# Calculating phase response of filter with latency

I have an LTI filter that I want to treat like a black box. It has a latency of 24 samples.

This is what I'm doing (which works for a filter with no latency):

1. Send unit impulse through my filter
2. Capture first 16,384 samples output
3. Perform FFT
4. For each of first 8192 complex values, take phase

Doing the above gives the red line shown below.

If I replace step 2 with:

1. Skip first 24 samples and then capture first 16,384 samples output

Then I get the blue line shown below.

The green line represents the actual phase of the signal.

Bode plot of phase vs log frequency (10Hz to 20kHz)

• If all you are doing is shifting the output left by 24 samples, how can that change the magnitude response? A delay of 24 samples should only change the phase of the frequency response, not the magnitude of it. Can you include a plot of the bad vs good phase?
– Peter K.
Jul 12 '16 at 15:39
• @Peter K. I've uploaded a picture. Note I am wanting the phase of a filter after sending through an impulse response - don't know if that makes a difference or not. Jul 12 '16 at 15:57
• @keith: Note that a delay is equivalent to a linear phase trajectory. Shifting the signal by a specified amount should just apply an additive linear phase to your measurement. If it doesn't, then something is going wrong (or your system isn't LTI!). I'm not clear on what the red trace is supposed to be in the plot as it relates to the other two. Jul 12 '16 at 16:09
• @Jason R, I've updated my question to try and make it simpler. Jul 12 '16 at 16:16
• How did you measure your green line? I really have my doubts – maybe you're doing a monstrous DFT and your window effectively kills your first N samples of output? Jul 12 '16 at 18:52

Thanks to everyone who provided helpful comments. As some suggested shifting the signal might be the way to go, but this results in the blue line where the green line is the phase I would expect.

It turns out to correct the phase after taking the DFT of the impulse response of the filter when the filter has a delay each bin needs the following angle adding to it:

$$\frac{ 2\pi i L} {N}$$

Where $L$ is the latency in samples, $N$ is the FFT size and $i$ is the $i$th FFT bin. So I was missing this as step 5.

For anyone else who stumbles upon this, the phase will end up being neither wrapped or unwrapped. So you will need to take the remainder of the final phase modulus $\pi$. This will give you the normal wrapped phase (as a correctly quadranted arctan would produce by just taking the phase of the complex valued FFT bin) and then you can unwrap as normal.

• Thanks for taking the time to write up your own solution. Make sure you give yourself the check mark once the system lets you (I think there's a delay between when you answer your own question and when you're allowed to accept it).
– Peter K.
Jul 13 '16 at 21:23
• later tonight, i will try to write an answer. you need to remove the linear-phase component and there is a nice DSP way to estimate that linear-phase component and then subtract. otherwise, what you are doing is estimating from what you otherwise know about the system (that it has a 24 sample delay) and you are manually compensating. Jul 13 '16 at 22:42