Finite Impulse Response filter

2 ビュー (過去 30 日間)
Kervin Aranzado
Kervin Aranzado 2022 年 9 月 22 日
回答済み: Star Strider 2022 年 9 月 22 日
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');

回答 (1 件)

Star Strider
Star Strider 2022 年 9 月 22 日
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)]
Comparison = 2×250
2.0000 4.0000 6.0000 8.0000 10.0000 12.0000 14.0000 16.0000 18.0000 20.0000 22.0000 24.0000 26.0000 28.0000 30.0000 32.0000 34.0000 36.0000 38.0000 40.0000 42.0000 44.0000 46.0000 48.0000 50.0000 52.0000 54.0000 56.0000 58.0000 60.0000 0.6953 0.6304 0.5279 0.4305 0.3547 0.3038 0.2655 0.2355 0.2123 0.1917 0.1775 0.1659 0.1567 0.1496 0.1433 0.1380 0.1338 0.1303 0.1278 0.1251 0.1231 0.1208 0.1191 0.1173 0.1159 0.1145 0.1132 0.1115 0.1103 0.1086
fitval = 0.05; % Choose Value Of 'normresid'
n = interp1(Comparison(2,:), Comparison(1,:), fitval, 'nearest') % Value Of 'n' Nearest the 'fitval' Value
n = 190
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
I left the fminsearch call in (commented-out) in case you want to experiment with it.
.

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by