Supercomputing Institute Technical User Support

 

IDL: Signal Processing

  1. Creating a Data Set
  2. Signal Processing with SMOOTH
  3. Frequency Domain Filtering
  4. Displaying Results

Creating a Data Set

First, we need to create a dataset to display.
1. Enter the following command to create a sinewave function with a frequency that increases over time and store it in a variable called original:
original=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 sinewave 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 original.
2. To view a quick plot of this dataset, shown in the following, enter:
plot,original
3. Now add some uniformly-distributed random noise to this dataset and store it in a new variable:
noisy=original+((randomu(seed,200)-.5)/2)
4. Now plot the array:
plot,noisy
The RANDOMU function creates an array of uniformly distributed random values. The original dataset plus the noise is stored in a new variable called noisy. This dataset looks more like real-world test data.
5. Display the original dataset and the noisy version simultaneously by entering the following commands:
plot, original, xtitle="Time",ytitle="Amplitude",thick=3
6. Then overplot the previous data:
oplot,noisy
The XTITLE and YTITLE keywords are used to create the X and Y axis titles.  The OPLOT command plots the noisy dataset over the existing plot of original without erasing.  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 following figure.

Signal Processing with SMOOTH

A simple way to smooth out the NOISY dataset is to use IDLs SMOOTH function. It returns an array smoothed with a boxcar average of a specified width.
1. Create a new variable to hold the smoothed dataset by entering the following command:
smoothed=smooth(noisy,5)
2. Now plot your new data set:
plot,smoothed,title='Smoothed Data'
The TITLE keyword draws the title text centered over the plot. Notice that while SMOOTH did a fairly good job of removing noise spikes, the resulting amplitudes taper off as the frequency increases.

Frequency Domain Filtering

Perhaps a better way to eliminate noise in the NOISY dataset is to use Fourier transform filtering techniques. Noise is basically unwanted high-frequency content in sampled data. Applying a lowpass filter to the noisy data allows low-frequency components to remain unchanged while high-frequencies are smoothed or attenuated. Construct a filter function by entering the following step-by-step commands:
1. Create a floating point array using FINDGEN which sets each element to the value of its subscript and stores it in the variable y by entering:
y=[findgen(100),findgen(100)-100]
2. Next, make the last 99 elements of y a mirror image of the first 99 elements:
y[101:199]=reverse(y[0:98])
3. Now, create a variable filter to hold the filter function based on y:
filter=1.0/(1+(y/40)^10)
4. Finally, plot:
plot,filter
To filter data in the frequency domain, we multiply the Fourier transform of the data by the frequency response of a filter and then apply an inverse Fourier transform to return the data to the spatial domain.
5. Now we can use a lowpass filter on the noisy dataset and store the filtered data in the variable lowpass by entering:
lowpass=fft(fft(noisy,1)*filter,-1)
6. Then plot:
plot,lowpass
7. The same filter function can be used as a high-pass filter (allowing only the high frequency or noise components through) by entering:
highpass=fft(fft(noisy,1)*(1.0-filter),-1)
8. Then plot:
plot,highpass

Displaying Results

Now look at all of the results at the same time. The plotting window can be split into six sections, making each section display a different plot. The system variable !P.MULTI tells IDL how many plots to put on a single page.  Enter the following lines to display a plotting window which shows all of the plots simultaneously.
1. To display all plots at the same time with two columns and three rows, enter:
!p.multi=[0,2,3]
2. Now, display original dataset, upper-left:
plot,original,title='Original (Ideal) Data'
3. Next, display noisy dataset in the upper-right:
plot,noisy,title='Noisy Data'
4. Display filter function, middle-left. The SHIFT function was used to show the
filters peak as centered.
plot,shift(filter,100),title='Filter Function'
5. Now, display low-pass filtered dataset in the middle-right:
plot,lowpass,title='Lowpass Filtered'
6. Display high-frequency noise, lower-left:
plot,highpass,title='Highpass Filtered'
7. Finally, display the SMOOTH function dataset for comparison with the low-pass filtered data in the lower right.
plot, smoothed, title = 'Smoothed with Boxcar average'
8. Before continuing with the rest of the chapters, reset the plotting window to display a single image by entering the command:
!p.multi = 0


 
This information is available in alternative formats upon request by individuals with disabilities. Please send email to alt-format@msi.umn.edu or call 612-624-0528.

HOME | QUESTIONS | FEEDBACK
Employment | Events | Links | People | Publications | Support | Welcome
 


URL: http://www.msi.umn.edu/software/fast/tutorial/fast-starting.html
This page last modified on Friday, 03 November, 2000,  09:10:02 CDT  
Please direct questions or problems to help@msi.umn.edu  
Website related questions or problems should be dirrected to webmaster@msi.umn.edu