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);
n = 4; % Filter order
b_lp = firls(n,f,a);
[h,w] = freqz(b_lp,1,512);
hold on

I appreciate any insights.


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);
  • $\begingroup$ Awesome, thanks a lot for your help. $\endgroup$ – dsp_guy2020 Dec 2 '20 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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