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.

  1. 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:
  2. 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.

  3. To view a quick plot of this data set, shown in the following diagram, enter:
    gssig01.gif
  4. IPLOT, data

  5. Add some uniformly-distributed random noise to this data set and store it in a new variable:
  6. 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.

  7. Now plot the array:
    gssig02.gif
  8. IPLOT, noisy

  9. Display the original data set and the noisy version simultaneously by entering the following commands:
  10. IPLOT, data, XTITLE="Time",$
       YTITLE="Amplitude", THICK=3

  11. Then overplot the previous data:
  12. IPLOT, noisy, /OVERPLOT

     
     
     


    gssig03.gif
    The XTITLE and YTITLE keywords are used to create the X and Y axis titles. The OVERPLOT keyword plots the NOISY data set over the existing plot of DATA. 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.