
Interactive Fourier Filter (version 2, May, 2008)

A Matlab implementation of a fourier filter function for time-series signals, including an interactive version with sliders that allow you to adjust the filter parameters continuously while observing the effect on your signal dynamically. By adjusting the parameters, you can create lowpass, highpass, bandpass, and bandreject (notch) filters with variable cut-off rate. Version 2 is calibrated for time-based signals, where the independent variable is time in seconds. 

FouFilter.m: Basic Fourier Filter function
function ry=FouFilter(y,samplingtime,centerfrequency,frequencywidth,shape,mode)
   Fourier filter function for time-series signal vector y; 'samplingtime' is the total duration of sampled signal in sec, millisec, or microsec; 'centerfrequency' and 'frequencywidth' are the center frequency and width of the filter in Hz, KHz, or MHz, respectively. If shape = 1, the filter is Gaussian; as shape increases, the filter shape becomes more and more rectangular (faster cut-off rate). Set mode = 0 for band-pass filter, mode = 1 for band-reject (notch) filter.

Example: plot(FouFilter(tan(1:1000),15,2,2,0)

InteractiveFourierFilter.m

Interactive Fourier Filter script for data in global variables x,y. Requires Matlab 6.5. To use it, place the signal in the global variables x,y (x = independent variable, e.g. time, and y = dependent variable, e.g. signal amplitude) and then execute this m-file. The filtered signal is returned in the global vector ry. (There is also a version written as a function, iff(x,y), that works similarly and returns the filtered signal as the value of the function.)
   The bottom plot shows the power spectrum of the original signal (in blue) and the spectrum of the filter (in red). The x-axis of this plot is frequency, in the reciprocal units of the signal's independent variable x (e.g. Hz if the signal is in seconds, KHz if the signal is in milliseconds, etc). In this version, the original and filtered signals are displayed in separate windows. (To display the original signal and filtered signal superimposed in the same window, rename AlternativeRedrawFourierFilter.m to RedrawFourierFilter.m)
   There are 4 sliders for interactive control of the filter parameters:
The Center slider controls the center frequency (CenterFreq).
The Width slider controls the frequency width of the filter (FreqWidth).
The Shape slider determines the sharpness of the cut-off. (If shape = 1, the filter is Gaussian; as shape increases, the filter shape becomes more and more rectangular).
The Mode slider has only 4 settings: mode=0 for band-pass filter, linear plot; mode=1 for band-pass filter, semilogx plot; mode=2 for band-reject (notch) filter, linear plot; mode=3 for band-reject (notch) filter, semilogx plot. To make a low-pass filter, set Center to zero and the Mode to 0 and vary the Width; to To make a high-pass filter, set Center to zero and the Mode to 2 and vary the Width. x
(If the range of the sliders is inappropriate for your signal, you can adjust the slider ranges in lines 43-45).

iff.m function
Interactive Fourier filter written as a single self-contained Matlab function. Identical to the above, except it acts as a function, taking x and y as input paramaters and returning the filtered signal. Declares global variables "iffdata" and "iffparameters". 

DemoIFF.m
   Self-contained demonstration of Interactive Fourier Filter with sliders for interactive control. Requires Matlab 6.5. The Signal slider selects from five different signals (you can change these in the function iffsignal.m). The Center slider controls the center frequency of the filter, the Width slider controls the width, and the Shape slider controls the shape of the pass band. If shape = 1, the filter is Gaussian; as shape increases, the filter shape becomes more and more rectangular. The Mode slider has only 4 settings: mode=0 for band-pass filter, linear plot; mode=1 for band-pass filter, semilogx plot; mode=2 for band-reject (notch) filter, linear plot; mode=3 for band-reject (notch) filter, semilogx plot. In this version, the original and filtered signals are displayed in separate windows. To display the original signal and filtered signal superimposed in the same window, rename AlternativeRedrawFourierFilter.m to RedrawFourierFilter.m

FourierTest.m
   Simple self-contained fourier filter script, without interactive sliders, for simulated time-based signal, where x = time in sec, millisec, or microsec. Original signal (blue) and filtered signal (red) are displayed superimposed in the top window, power spectrum and filter spectrum in bottom window. 'samplingtime' is the total duration of sampled signal, in seconds (or millisec or microsec). 'samplerate' is the sample rate in Hz (or KHz or MHz). 'centerfrequency' is the center frequency of the filter, and 'frequencywidth' is the frequency width of filter, in Hz (or KHz or MHz). 'Center' and 'width' are the center harmonic and width of the filter band expressed in harmonic number. 'Shape' determines the sharpness of the cut-off. If shape = 1, the filter is Gaussian; as shape increases the filter shape becomes more and more rectangular. Set mode = 0 for band-pass filter, mode = 1 for band-reject (notch) filter.

T. C. O'Haver (toh@umd.edu), version 2, May, 2008
Tom O'Haver
Professor Emeritus
Department of Chemistry and Biochemistry
The University of Maryland at College Park
toh@umd.edu
http://www.wam.umd.edu/~toh 