0
$\begingroup$

Say you have a bandpass filter and you place it on 40 discretely sampled points from a sinusoid with a period of 40.

Why is the bandpass filter (green curve on the image) only "in phase" with the sinusoid if you use a window length (impulse response length) for the filter of 1/4th the period of the sinusoid (here 40/4=10)? So the green filter has the same turning and bending points only if you use the 10 past observations, multiply with the impulse response (of length 10) and add that up..

Sinusoid with 3 Bandpass filters

Am I correct that this is related to how the length of the impulse response affects the phase delay?

$\endgroup$
  • $\begingroup$ A linear phase FIR filter has a delay of $(N-1)/2$ samples, where $N$ is the filter length. Does your filter have a linear phase? It would be helpful if you showed us the filter's impulse response. $\endgroup$ – Matt L. Mar 17 '14 at 17:34
  • $\begingroup$ The phase transfer response of a band pass filter is something like a tangent function, asymptotically approaching +/- 90 degrees per pole pair. $\endgroup$ – MisterH Mar 17 '14 at 20:21
  • $\begingroup$ This makes your question even less clear. You are talking about pole pairs, i.e. a recursive filter (IIR). In your question you talk about the (finite) length of your impulse response (FIR). Please edit and clarify your question, otherwise it is impossible to know what you're doing. Specify the filter you're using (difference equation, impulse response, etc.). Add some code if you like. $\endgroup$ – Matt L. Mar 17 '14 at 20:33
  • $\begingroup$ My filter is a band-pass filter, it's the difference of a FIR and an IIR filter. I approximated the IIR filter with an impulse response that is of finite length, so it is not recursive, but I get a kind of hybrid. The approximation is not exact, but good enough up to a certain number of decimals for my problem. $\endgroup$ – MisterH Mar 18 '14 at 22:41
1
$\begingroup$

I find what you are saying really hard to understand. Let me try to decode it. Let me know if my decoding is correct.

Say you have a bandpass filter and you place it on 40 discretely sampled points from a sinusoid with a period of 40.

This makes little sense. What I think you mean is: I have a filter with impulse response $h(n)$ that I am going to apply to a sinusoidal signal of length 40 samples.

Why is the bandpass filter (green curve on the image) only "in phase" with the sinusoid if you use a window length (impulse response length) for the filter of 1/4th the period of the sinusoid (here 40/4=10)?

Again, I'm finding it hard to fathom what you mean, but I interpret this as: If my impulse response $h(t)$ is of length 10 samples, then the output of my filter is a sinusoid that is in phase with the input. When I use an impulse response of a different length (9 or 11) then the phase is incorrect.

For a start, your filter output will not generally have precisely the same phase as the filter input. If your filter is a linear phase FIR filter, then as @MattL says, the filter will hvae a group delay of $(N-1)/2$ samples --- 4.5 samples in the case of a length 10 filter.

Trying to reproduce your diagram (scilab code below) shows this effect: the green plot is the original, the red plot is the output of a length 9 filter (which has a delay of 4 samples), the black plot is the output of a length 10 filter (delay 4.5), and the blue is the output for a length 11 filter (delay of 5).

enter image description here


CODE BELOW

P = 40;
x = sin(2*%pi*[0:79]/P)

h10 = ones(1,10)/10;
h09 = ones(1,9)/9;
h11 = ones(1,11)/11;

y09 = filter(h09,1,x);
y10 = filter(h10,1,x);
y11 = filter(h11,1,x);

clf;
plot(x,'g');
plot(y10,'k');
plot(y09,'r');
plot(y11,'b');
$\endgroup$
  • $\begingroup$ Thank you for your comment. Your decoding of my gibberish is correct. Only, it is not a FIR filter. My filter a difference: FIR filter - IIR filter. The delay is not (n-1)/2, it is 0 if the window is set at 10 (p/4) (I know, IIR is recursive, but as I said, I approximated it with a finite length window). $\endgroup$ – MisterH Mar 21 '14 at 17:18
  • $\begingroup$ Ok! Thanks. No causal filter can have zero phase (for all frequencies) --- unless it is just a constant gain. Can you give a bit more detail about how you are doing the filtering? I suspect you are effectively making the filter non-causal (using "future" inputs for the output now). That's ok for offline processing... I'm just trying to get to the bottom of the shift you are seeing. :-? $\endgroup$ – Peter K. Mar 21 '14 at 18:15
  • $\begingroup$ It is a causal filter. I was playing around with different types of filters and combinations, and I suddenly saw a very attractive shape. I calculate the filters on a stationary signal, and for quite a lot of time, the difference of the FIR & IIR filters had the same turning points as a spline (the Hodrick-Prescott filter, it's used a lot in economics). So I want to learn the reason why it has no lag at this window length so I can use this and make an adaptive digital filter that always has the same turning points as a non-causal filter. Ambitious, but it might possible to get close to that. $\endgroup$ – MisterH Mar 21 '14 at 21:31
  • $\begingroup$ So any ideas on fitness functions for adaptive bandpas filters? $\endgroup$ – MisterH Mar 25 '14 at 23:03
  • $\begingroup$ Seems like quite a different question! And the "fitness" will depend on what you're trying to do. $\endgroup$ – Peter K. Mar 26 '14 at 19:16
0
$\begingroup$

Obviously, it is not exactly in phase. What kind of a filter is it? IIR filters can easily have large delays. The result will be in phase with the original when the phase of the filter (including any technical delay) is a multiple of 2pi.

$\endgroup$
  • $\begingroup$ The green line and the black line are in phase. The question is why is it only true if the filter window is set at 1/4th the period of the sinusoid. $\endgroup$ – MisterH Mar 18 '14 at 22:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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