Creating a Data Set
In this example, we create a data set and then introduce noise to make it appear more like real-world data. Then we plot the original data and the "noisy" data together in the same window to see the difference.
First, we need to create a data set to display.
- Enter the following command to create a sine wave function with a frequency that increases over time and store it in a variable called
DATA: - To view a quick plot of this data set, shown in the following diagram, enter:

- Add some uniformly-distributed random noise to this data set and store it in a new variable:
- Now plot the array:

- Display the original data set and the noisy version simultaneously by entering the following commands:
- Then overplot the previous data:
data = SIN((FINDGEN(200)/35)^2.5)
The FINDGEN function returns a floating-point array in which each element holds the value of its subscript, giving us the increasing "time" values upon which the sine wave is based. The sine function of each "time" value divided by 35 and raised to the 2.5 power is stored in an element of the variable DATA.
noisy = data + ((RANDOMU $
(SEED,200)-.5)/ 2)
The RANDOMU function creates an array of uniformly distributed random values. The original data set plus the noise is stored in a new variable called NOISY. When you plot this data set, it looks more like real-world test data.
IPLOT, data, XTITLE="Time",$
YTITLE="Amplitude", THICK=3
The XTITLE and YTITLE keywords are used to create the X and Y axis titles. The OVERPLOT keyword plots theNOISYdata set over the existing plot ofDATA. Setting the THICK keyword causes the default line thickness to be multiplied by the value assigned to THICK, so you can differentiate between the data. This result can be seen in the figure to the right.
