# Linear phase impulse response causes non linear phase frequency response in GNU Octave/ Matlab

Assume linear phase FIR symteric impulse response like [1 2 3 4 5 5 4 3 2 1],shoud resault in a frequency response with linear phase negative sloped phase. but it doesn't:

>>stem(angle(fftshift(fft([1 2 3 4 5 5 4 3 2 1]))))


causes: But this is wrong the plot must follow the red line. Whats wrong with it?

Another example:

stem(angle(fftshift(fft([1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1]))))


Resault:

It seems it's because phase changes too fast and what we see is something like aliazing! but how to decrease phase change rate and how it effects the filter?

## update

Can you see the inconsistency between two freqz and fft:

The phase of fft must be samples of freqz phase but it isn't!

Don’t use the unpadded FFT to review the frequency response (which is given by the DTFT not the DFT). The FFT is circular so the result is corrupted by time domain aliasing. To do this properly zero pad the time domain waveform first (by simply using the optional length parameter in the ‘fft()’ function with the length much longer than the duration of the impulse response), and the result will approach the continuous DTFT frequency response waveform (as more zeros are added more samples will be interpolated in frequency in between the samples the FFT will have otherwise provided).

Even easier: use the ‘freqz’ command available in Matlab, Octave and Python scipy.signal as this will do this all properly under the hood and return the properly scaled frequency axis in units of radians/sample. Matlab will returns plot of the frequency response (both magnitude and phase) by typing

freqz([1 2 3 4 5 5 4 3 2 1])


The OP is also asking why the FFT results shown do not appear to be samples of the frequency response returned by freqz as we would otherwise expect. The FFT as shown is extending from $$0$$ to $$2\pi$$ (in normalized radian frequency), or DC to fs in Hz, but freqz as plotted is only extending $$0$$ to $$\pi$$ (DC to fs/2). There is a parameter you can use in freqz to plot the whole spectrum from $$0$$ to $$2\pi$$ instead (look at the help on the function for that). Also be sure to unwrap the phase when comparing since you could see differences in the phase when rolling over past $$\pm \pi$$.