Can I create the same FIR filter using two different commands?

If I use the same values to create a bandpass FIR filter but two different commands (fir1 through the window method and firpm) do I get the same filter? If not, is there a way to get the same filter using those two commands?

1 Comment

The R2022a doc page states:
  • f is a vector of pairs of frequency points, specified in the range between 0 and 1, where 1 corresponds to the Nyquist frequency. The frequencies must be in increasing order. Duplicate frequency points are allowed and, in fact, can be used to design a filter exactly the same as those returned by the fir1 and fir2 functions with a rectangular (rectwin) window.
which explicitly says that what you want to do is feasible, though offhand I'm not sure how that would work with fir1. However, that statement does not appear in the 2023B doc. Not sure what to make of that.

Sign in to comment.

 Accepted Answer

Getting the same filter using ttwo differnt methods is probably possible. Comparing a windowed design (using kaiserord here with fir1) with your other filter produces FIR filters of different lengths, so they will have different characteristics.
Fs = 500; % Use Correct Sampling Frequency (Must Be Greater Than 370 Hz)
f = [0.8 1 8 8.2];
mags = [0 1 0];
dev = [0.5 0.1 0.5];
[n,Wn,beta,ftype] = kaiserord(f,mags,dev,Fs);
hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale');
n
n = 2099
figure
freqz(hh, 1, 2^20, Fs)
set(subplot(2,1,1), 'XLim', [0 20]) % Zoom X-Axis
set(subplot(2,1,2), 'XLim', [0 20]) % Zoom X-Axis
fFIR= [0 1 4 6 8 9]; % frequenza di taglio in Hz
a=[0 1 1 0]; %ampiezza desiderata
rp= 0.5; %ripple banda passante in dB
rs= 30; %ripple banda di stop in dB
fs=500; % frequenza di campionamento in Hz
% La deviazione (dev) rappresenta il massimo ripple possibile tra la risposta del filtro e la risposta desiderata,
% quindi dovrebbe essere calcolata come il valore massimo tra rp e rs linearizzati (prima erano in dB)
dev = [ 10^(-rs/20) (10^(rp/20)-1)/(10^(rp/20)+1) (10^(rp/20)-1)/(10^(rp/20)+1) 10^(-rs/20)];
%ricavo l'ordine minimo del filtro
[n,fo, ao, w]=firpmord(fFIR,a,dev,fs);
b = firpm(n,fo,ao,w);
n
n = 671
figure
freqz(b,1,2^20,fs )
set(subplot(2,1,1), 'XLim', [0 20]) % Zoom X-Axis
set(subplot(2,1,2), 'XLim', [0 20]) % Zoom X-Axis
title('Filtro FIR passabanda con frequenze di taglio [1,8] Hz')
It should be possible to compare them using the freqz function with outputs (then comparing the outputs), however you would necessarily need to make the filters the same lengths to do that. Here, the windowed filter has a length of 2099 and the firpm filter a length of 671, with appropriate differences in passbands. (The fft lengths used with freqz would also have to be the same in order to compare the results.)
.

More Answers (0)

Products

Release

R2023b

Community Treasure Hunt

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

Start Hunting!