# 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. – keith 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. – Jason R Jul 12 '16 at 16:09
• @Jason R, I've updated my question to try and make it simpler. – keith 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? – Marcus Müller Jul 12 '16 at 18:52

$$\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.