1
$\begingroup$

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)

enter image description here

$\endgroup$
9
  • 2
    $\begingroup$ 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? $\endgroup$
    – Peter K.
    Commented Jul 12, 2016 at 15:39
  • $\begingroup$ @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. $\endgroup$
    – keith
    Commented Jul 12, 2016 at 15:57
  • 1
    $\begingroup$ @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. $\endgroup$
    – Jason R
    Commented Jul 12, 2016 at 16:09
  • 1
    $\begingroup$ @Jason R, I've updated my question to try and make it simpler. $\endgroup$
    – keith
    Commented Jul 12, 2016 at 16:16
  • $\begingroup$ 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? $\endgroup$ Commented Jul 12, 2016 at 18:52

1 Answer 1

1
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ 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). $\endgroup$
    – Peter K.
    Commented Jul 13, 2016 at 21:23
  • $\begingroup$ 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. $\endgroup$ Commented Jul 13, 2016 at 22:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.