I am trying to calculate manually the phase of the frequency response of an LTI system as a function of frequency and plot the results. The original system is described as $y[n]=0.1(x[n]-x[n-1]+x[n-2]$, which I was able to write the frequency response $H(e^{j\hat{\omega}})=0.1(1-e^{-j\hat{\omega}}+e^{-j\hat{\omega}2})$.
I used MATLAB to plot the phase using the code below:
tt = -pi : 1/200 : pi;
H = 0.1*(1-exp(-j*tt)+exp(-j*tt*2));
plot(tt, angle(H))
And the output was as shown below:
This does not match the result I got by calculating as shown below:
$0.1(1-e^{-j\hat{\omega}}+e^{-j\hat{\omega}2})$
$0.1e^{-j\hat{\omega}}(e^{j\hat{\omega}}-1+e^{-j\hat{\omega}})$
$0.1e^{-j\hat{\omega}}(2\cos(\hat{\omega})-1)$
$0.1(\cos(\hat{\omega})-j\sin(\hat{\omega}))(2\cos(\hat{\omega})-1)$
$0.1(2\cos^2(\hat{\omega})-\cos(\hat{\omega}) - 2j\sin(\hat{\omega})\cos(\hat{\omega})+j\sin(\hat{\omega}))$
$0.1\left(\left(2\cos^2(\hat{\omega})-\cos(\hat{\omega})\right)+j\left(- 2\sin(\hat{\omega})\cos(\hat{\omega})+\sin(\hat{\omega})\right)\right)$
$\theta = \tan^{-1}\left(\dfrac{-2\sin(\hat{\omega})\cos(\hat{\omega})+\sin(\hat{\omega})}{2\cos^2(\hat{\omega})-\cos(\hat{\omega})}\right)$
$\theta = \tan^{-1}\left(\dfrac{-\sin(\hat{\omega})\left(2\cos(\hat{\omega})-1\right)}{\cos(\hat{\omega})\left(2\cos(\hat{\omega})-1\right)}\right)$
$\theta = \tan^{-1}\left(-\tan(\hat{\omega})\right)$
I am not sure if I am misunderstanding how to calculate the phase function, or if there is an error in my work somewhere. Is this the correct way to calculate the phase? If so, is there an error somewhere that I am missing?