0
$\begingroup$

I have defined the following linear phase filter of order 4 (real and symmetric) in matlab: h_d = [0.8367 -1.537 1 -1.537 0.8367] I calculate the frequency response (for many points) and then I use firls function (which is supposed to give the least-squares solution) to find a linear phase FIR filter (5 taps) that matches the desired response. However the filter is nowhere close to h_d. What am I doing wrong? Here is the code:

f = [0:1/(2^14-1):1];
[a,~] = freqz([0.8367 -1.537 1 -1.537 0.8367],1,f*pi);
a=abs(a);
n = 4; % Filter order
b_lp = firls(n,f,a);
[h,w] = freqz(b_lp,1,512);
figure(1)
plot(f,20*log10(abs(a)),'-s')
hold on
plot(w/pi,20*log10(abs(h)))

I appreciate any insights.

$\endgroup$

1 Answer 1

2
$\begingroup$

The function firls() is meant to design filters with piecewise constant magnitude responses. So in practice you use only a few frequency points and the corresponding desired magnitude values, and the function computes a linear interpolation between the given frequency points. Of course, in theory your call to firls is correct, but I guess that the resulting system of linear equations becomes ill-conditioned.

I wrote a function lslevin.m, which can be used in the way you intended to use firls:

h = [0.8367 -1.537 1 -1.537 0.8367];
[H,w] = freqz(h,1,2048);    % that's more than enough frequency points
h2 = lslevin(5,w,H,ones(size(H)));
[H2,w] = freqz(h2,1,2048);
plot(w/pi,abs(H),w/pi,abs(H2),'r--')
$\endgroup$
1
  • $\begingroup$ Awesome, thanks a lot for your help. $\endgroup$ Dec 2, 2020 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.