Digital Filters with GNU Octave
The following scripts use Octave's Signal Processing Toolbox; If you don't have the toolbox installed, get it from Octave-Forge.
It is easy to design a low pass filter:
% The sampling frequency in Hz.
Fsam = 1500;
% Nyquist frequency, in Hz.
% The Nyquist frequency is half your sampling frequency.
Fnyq = Fsam/2;
% The cut-off frequency of your Low pass filter in Hz.
% This frequency must be greater than 0 and less than Fnyq.
% Create a first-order Butterworth low pass.
% The returned vectors are of legth n.
% Thus a first order filter is created with n = 2.
% clear unused variables
Now let's test the filter. First, let's generate a input signal containing components at 1 Hz, 200 Hz and Gaussian white noise.
% Create a 5 seconds signal with 3 components:
% a 1 Hz and a 200 Hz sinusoidal component and some gaussian noise.
input=sin(2*pi*t) + sin(2*pi*200*t) + randn(size(t));
% Apply the filter to the input signal and plot input and output.
plot(t, [input; output])
You can also compare the input and output signals in the frequency domain:
find(abs(fft(input)) > 3000)
find(abs(fft(output)) > 3000)
Thanks to Greg Locock for pointing out that rand() does not yield Gaussian noise.