0
votes

In the documentation on lowpass I found this:

y = lowpass(x,wpass) filters the input signal x using a lowpass filter with normalized passband frequency wpass in units of π rad/sample. lowpass uses a minimum-order filter with a stopband attenuation of 60 dB and compensates for the delay introduced by the filter. If x is a matrix, the function filters each column independently.

y = lowpass(x,fpass,fs) specifies that x has been sampled at a rate of fs hertz. fpass is the passband frequency of the filter in hertz.

But it seems like the second one, y = lowpass(x,fpass,fs), does not really use Hz since it does not filter the frequencies above that goven by fpass.

How I can use the first one? How can I calculate the wpass if I want a lowpass filter with cutoff frequency x? Do I need to do wpass = x/samplerate? I'm a little bit confused with those radians.

1

1 Answers

2
votes

The normalized cut-off frequency is

Wn = fc/(fs/2)

where fc is the cut-off frequency you want and fs is the sampling rate. The 2 has something to do with the Nyquist-Shannon-theorem but I don't want any confusion. Note that the filter never is sharp. So it won't actually cut off at fc but it will damp higher frequencies.

To actually control how sharp the filter is, I recommend design the filter directly: e.g. butter gives you a Butterworth filter (or the Bessel filter -- less sharp than Butterworth but also better gain at < fc, or Chebyshev filter, which is much sharper but introduces oscillation in the gain at < fc). From my experience, usually a 4th order Butterworth filter is applied.

[b,a] = butter(4,Wn);
sig_flt = filter(b,a,sig);

EDIT: In fact, it is recommended to use (as @LuisMendo pointed out)

[z,p,k] = butter(4,Wn);
sos = zp2sos(z,p,k); % convert to zero-pole-gain filter parameter
sig_flt = sosfilt(sos,sig);

to avoid numerical errors:

In general, use the [z,p,k] syntax to design IIR filters.

(Chebyshev is also an IIR filter)