LPF with notches at 50hz and all other harmonics

8 views (last 30 days)
Hi Matlab,
I like to design a LPF with notches at 50hz, 100hz, 150hz. etc... as shown on the attached picture. Borrow the example code, but got no clue.
Fs = 1000;
fc = 1;
Wn = (2/Fs)*fc;
b1 = fir1(40, Wn,'low');
fvtool(b1,1,'Fs',Fs)
Please advise, thanks in advance
JD

Accepted Answer

Star Strider
Star Strider on 10 Apr 2021
I am assuming that the sampling frequency is 2 kHz, and the magnitude spectrum in the image goes to the Nyquist frequency of 1 kHz.
The filter amplitude spectrum shown in the Question may not be a true ’comb’ filter, and may represent varaitions in the stopband of a lowpass filter.
However, if the desired result is a true ‘comb’ filter, those are straightforward to design:
Fs = 2000;
cfv = 0:50:900; % Centre Frequency Vector
fcomb = reshape(cfv + [45 48 52 55].', 1, []); % Passband-Stopband Vector
mags = [[1 0 1] repmat([0 1], 1, numel(cfv)-1)]; % Magnitude (Amplitude) Vector
dev = [[0.5 0.1 0.5] repmat([0.1 0.5], 1, numel(cfv)-1)]; % Maximum Alloweable Deviations Vector
[n,Wn,beta,ftype] = kaiserord(fcomb,mags,dev,Fs);
hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale');
figure
freqz(hh, 1, 2^20, Fs)
Use the filtfilt function to do the actual filtering.
The Bode plot for this filter:
This approach can easily be applied to any repetitive passband or stopband filter. Other options to FIR filter design allowing straightforward passband and stopband specification are implemented using firls and other approaches linked to in that documentation page.
  2 Comments
Star Strider
Star Strider on 11 Apr 2021
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!