Search code examples
matlabfilteringlowpass-filter

Matlab 3 dB 12 hertz lowpass filter


I am looking for a 3dB low-pass filter with a cut-off frequency of 12Hz. I know Matlab has this function fdesign.lowpass and it should be possible to be 3dB with F3db (source / additional) but I'm not really sure yet how to implement them, that is: what features I should include and what features not. I get confused by all the other variables I think I don't need -- I just need Fc and 3dB. I also found fdatool but also don't really know how to set such a filter.

The data contains regular x and y values while it will be a speed versus time plot of a recorded movement.


Solution

  • For your application I would strongly recommend trying a plain butterworth filter, the Matlab syntax is:

    [b,a]=butter(n,Wn)
    

    Where Wn is the digital frequency, so here's how I would pose it:

    % assume x is time and y is speed
    Ts = mean(diff(x));
    Fs = 1/Ts;
    % for butter, we need Wn, which is the cutoff frequency
    % where 0.0 < Wn < 1.0, where 1.0 is half the sample rate
    % The cutoff is the -3 dB point of the filter
    % Wn = fCutOff/(Fs/2)
    % for a cutoff of 12 Hz
    fCutOff = 12/(Fs/2);
    % we'll start with an order of 1 which should give us about 20 db/decade attenuation
    [b,a] = butter(1,fCutoff);
    % plot the filter frequency response to see what it looks like
    % use 512 points to plot it
    freqz(b,a,512,Fs)
    

    However, if, I understand correctly, you're sampling the data at about 66 Hz, which is about 5 times faster than your desired cutoff. Rule of thumb is often 10 times, so you may not be real happy with what you get as output. Here's my output: results