# How do I find the phase response of a filter from the filter equation?

I am new to this forum. I have been teaching myself DSP for the last two years, so my experience and knowledge has a long way to go.

I am trying to find the phase response of a specific filter that I am using on Csound for any given fundamental frequency of the input (and I guess I'll need to be able to do that for any cuttoff frequency and ideally any sampling rate as well).

The filter is a 1st order lowpass IIR, and the filter's equation is as follows:

$$y[n] = c_1 x[n] + c_2 y[n-1]$$

• $h_p$ - half power point

• $b = 2 - \cos(2 \pi h_p/s_r)$

• $c_2 = b - \sqrt{b^2 - 1}$

• $c_1 = 1 - c_2$

Three questions:

1. Can I find the phase response for any frequency based on this equation alone?

2. Can I derive a phase response equation from this equation alone?

3. Is there a standardised way of finding the phase response for any lowpass filter, or does it depend on what kind of filter it is?

I have found some info about finding phase response both in these forums and elsewhere online, but without knowing the answer to question 3, it's hard to know if they are relevant or not.

I have also read most of the scientists and engineers guide to DSP (which I notice is also the boards DSP guide, awesome!), and I have been going back over it the last few days to try and get some clues. The best solution I can find is to fft the impulse response, and I know how to find the impulse response for a cuttoff frequency, but it'll take a long time to calculate the impulse response for all possible cuttoff frequencies.

EDIT:

I have been reexamining ths online resouce from analog.com:

http://www.analog.com/library/analogDialogue/archives/43-09/active_filters.html

The website tells me this about the phase response of a 1 pole lowpass filter:

Is this true of any 1st order low pass filter, or are they refering to a specific filter type? If this is true of my filter, I think I might be able to do this (though I won't say for sure yet!)

• thanks for the edit jojek! I will try and post my equations more like this in the future – Iron Attorney Jan 25 '16 at 12:36
• The phase response formula you found is the phase response of a first order analog (i.e., continuous-time) low pass filter. What you got is a discrete-time low pass filter. – Matt L. Jan 25 '16 at 12:49
• Ah right of course! I knew it looked too easy ;) their definition of w doesn't even account for sampling rate – Iron Attorney Jan 25 '16 at 12:52

You need to determine the frequency response of the filter. The phase of this complex function is the filter's phase response. If you have the filter's difference equation, you need to transform it to the $\mathcal{Z}$-transform domain, where a delay of $k$ (with integer $k$) corresponds to a multiplication by $z^{-k}$:

$$Y(z)=c_1X(z)+c_2Y(z)z^{-1}\tag{1}$$

From $(1)$ you can determine the transfer function

$$H(z)=\frac{Y(z)}{X(z)}=\frac{c_1}{1-c_2z^{-1}}\tag{2}$$

The frequency response is the transfer function evaluated at $z=e^{j\omega}$, where $\omega$ is the normalized frequency in radians:

$$\omega=\frac{2\pi f}{f_s}\tag{3}$$

with $f_s$ the sampling frequency, and $f$ the actual frequency in Hz.

From $(2)$, the filter's frequency response is

$$H(e^{j\omega})=\frac{c_1}{1-c_2e^{-j\omega}}=|H(e^{j\omega})|e^{j\phi(\omega)}\tag{3}$$

where the phase response $\phi(\omega)$ is given by

$$\phi(\omega)=\text{atan2}\left(\frac{-c_2\sin(\omega)}{1-c_2\cos(\omega)}\right)\tag{4}$$

For more complicated filters it's usually easier to determine the frequency response (and the phase response) numerically by using an FFT. The (sampled) frequency response is obtained by element-wise division of the FFT of the numerator coefficients of the transfer function by the FFT of the denominator coefficients. The (sampled) phase is then obtained as the argument of this complex-valued vector. In Matlab/Octave, the frequency response can be obtained directly from the filter coefficients using the command freqz.

• Thanks for your answer! I'm gonna have to read through this a few times, and do some hectic thinking to fully understand this (which is fine, it's what I anticipated would happen :D ) so give me a while and I'll be back to upvote or tick the answer – Iron Attorney Jan 25 '16 at 12:50
• Ok, I think I'm starting to understand this. Could I generalise the last part 4, so that any filter differential that looked a bit like this: y[n] = A * x[n] + B * y[n -1] could be used to work out the phase in a similar way to part (4), swapping the -c2 for any value of -A, and the 1 - c2 for any value of B? – Iron Attorney Jan 25 '16 at 13:01
• @IronAttorney: Well, the way you defined it you would simply have $c_1=A$ and $c_2=B$. – Matt L. Jan 25 '16 at 13:06
• Hmmm, is that a yes? Lol :D – Iron Attorney Jan 25 '16 at 13:08
• Ah man, I forgot I can't up vote yet! Thanks for your help man, I'm gonna crunch the numbers now and see what happens – Iron Attorney Jan 25 '16 at 13:09

If you can factor your LTI filter's equation into the ratio of zeros over poles, then you can calculate phase very simply (even graphically) by adding up the angles from every pole and subtracting the angles from every zero to points on the unit circle in the complex plane representing frequency. The atan2() in equation (4) in Matt L's answer gives just such a phase angle.

• See: dsp.stackexchange.com/questions/2241/… for a more extended graphical description. – hotpaw2 Jan 25 '16 at 22:01
• I've got a way to go before I entirely understand everything you just said :D but what I believe you're getting at with the second part is that I could use equation (4) to make a graph of the phase responses? This might be an idea in the future, and it's definately a good thing to be able to do, although for my current usage, I just need the computer to be able to calculate the phase response (i think anyway, I'm about to embark on the next step which is an allpass filter to account for fractional delay caused by the very filter I mention above) – Iron Attorney Jan 26 '16 at 10:32