How can I make a simple low-pass FIR filter using Matlab (without using the built-in function) ?
Problem example:
Implement a FIR LPF with cut-off frequency 250Hz
it may also be necessary that, sampling freq is given...
Solution attempt or what I already know:
x = [...] -> input signal
A = 1; -> Since this is FIR
B = [?????]
y = filter(B, A, x) -> Output signal
Afaik, B should contain the coefficients for the FIR filter. But; how do I calculate these coefficients given that I only have the cut-off frequency?
The simplest thing is a "windowed sinc" filter:
fs = 44100;
cutoff = 250;
t = -256:256; % This will be a 513-tap filter
r = 2*cutoff/fs;
B = sinc(r*t).*r .* blackman(length(t))';
freqz(B);
The length of the filter (see t=...
) controls the width of the transition band. cutoff
is in this case the -6 dB point. blackman
is the name of a popular window. You can check out this Wikipedia page for more infos on window functions. They basically have different trade-offs between transition band width and stopband rejection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With