# FIR filter design with matlab firls() function

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.

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];