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. Click here to view or download just this function.
Example: plot(FouFilter(tan(1:1000),15,2,2,0))
![]() ![]() Example 2
|
At the Matlab command prompt, type: ifilter(x,y) or ifilter(y) or ifilter(xymatrix) or ry=ifilter(x,y,center,width,shape,plotmode,filtermode) Version 2, October 2011. Additions include increased input argument flexibility, 'Y' key chages y-axis scale on OUTPUT plot; 'T' key prints current settings. Example 1: x=0:100;y=sin(x);ifilter(x,y); Example 2 uses optional input arguments to set intital values: x=0:(1/8000):.3; y=(1+12/100.*sin(2*47*pi.*x)).*sin(880*pi.*x)+(1+12/100.*si(2*20*pi.*x)).*sin(2000*pi.*x); ry=ifilter(x,y,132,31,18,3,'Band-pass'); KEYBOARD CONTROLS when figure window is topmost: Adjust center frequency.......Coarse: < and > Fine: left and right cursor arrows Adjust filter width...........Coarse: / and " Fine: up and down cursor arrows Filter shape..................A,Z (A more rectangular, Z more Gaussian) Filter mode...................B=bandpass; N or R=notch (band reject) H=High-pass; L=Low-pass Select plot mode..............1=linear; 2=semilog frequency 3=semilog amplitude; 4=log-log Print keyboard commands.......K Pints this list Print filter parameters.......Q Prints input arguments: center, width, shape, plotmode, filtermode Print current settings........T Prints list of current settings Switch SPECTRUM X-axis scale..X switch between frequency and period x scale on POWER SPECTRA Switch OUTPUT Y-axis scale....Y switch output plot between fixed or variable y scale Play output as sound..........P or Enter Save output as .mat file......S |
| 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: (If the range of the sliders is inappropriate for your signal, you can adjust the slider ranges in lines 43-45). |
| 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 |
|
|
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 1.5, May, 2007 |
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
Last updated: October, 2011. Number of unique visits to this site since May 17, 2008: