Finite Impulse Response filter
2 views (last 30 days)
Show older comments
I set the order to 100. I need help to identify lower value of this filter that will satisfy the specifications
fpts = [0 0.2 0.3 0.5 0.52 1]; %frequency points
mval = [0.3 0.3 1.0 1.0 0.7 0.7]; %magnitudes of frequency components
b = fir2(100,fpts,mval); %design the FIR filter
[h,omega] = freqz(b,1,512); %get the response
plot(omega/pi,abs(h));grid; %plot the response
xlabel('\omega/\pi'); ylabel('Magnitude');
0 Comments
Answers (1)
Star Strider
on 22 Sep 2022
I thought about doing this with an optimisation funciton, however it minimises the distance between the estimated transfer function and the desired frequency response, resulting in an extremely high value for ‘n’ (in the hundreds of millions). Probably the best option is to simply do an iterative estimate and then decide what value of the residual norm (the square root of the sum of the squared differences between the actual and desired transfer function) will satisfy whatever requirements you have for them. I know of no function that will optimise specifically for the filter order for that reason.
This code does that —
fpts = [0 0.2 0.3 0.5 0.52 1]; %frequency points
mval = [0.3 0.3 1.0 1.0 0.7 0.7]; %magnitudes of frequency components
% absh = fir2fcn(5,fpts,mval);
% return
% n = fminsearch(@(n)norm(fir2fcn(n,fpts(:),mval(:))-mval(:)), 100)
nv = 2:2:500;
for k = 1:numel(nv)
n = nv(k);
normresid(n) = norm(fir2fcn(n,fpts(:),mval(:))-mval(:));
end
Comparison = [nv; normresid(2:2:end)]
fitval = 0.05; % Choose Value Of 'normresid'
n = interp1(Comparison(2,:), Comparison(1,:), fitval, 'nearest') % Value Of 'n' Nearest the 'fitval' Value
b = fir2(n,fpts,mval); %design the FIR filter
[h,omega] = freqz(b,1,512); %get the response
figure
plot(fpts, mval)
hold on
plot(omega/pi,abs(h));grid; %plot the response
hold off
xlabel('\omega/\pi'); ylabel('Magnitude');
function absh = fir2fcn(n,fpts,mval)
% n = max(fix(n),1)
b = fir2(n,fpts,mval); %design the FIR filter
[h,omega] = freqz(b,1,numel(fpts));
absh = abs(h);
end
.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!