Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Frequency dependent FIR filters? (Read 14220 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Frequency dependent FIR filters?

Hello.
I'll try to make my question understandable though it's a bit complicated.
Suppose I'm working with digital FIR filters and I'm doing everything in the time domain so that I don't use FFT. When the FIR filter consists of, for example, a single value of +1 delayed by 100 ms, then all the frequency bands in the output are delayed by 100 ms as well. But I would like to find such a FIR filter which delays each frequency by the time of one actual period -- i.e. so that 1000hz is delayed by 1 ms, 100Hz is delayed by 10 ms and so on. I don't want to make the filter very long because I really don't need to have frequencies lower than about 16Hz in the output signal. My question is: Is there a way to find such a filter without FFT? And if there is, what would it look like if I used, for example, a SR of 48kHz?
Thank you a lot in advance.
Petr

Frequency dependent FIR filters?

Reply #1
But I would like to find such a FIR filter which delays each frequency by the time of one actual period -- i.e. so that 1000hz is delayed by 1 ms, 100Hz is delayed by 10 ms and so on.

Don't you realize that this filter actually does nothing at all?

Proof:
  • All sine waves regardless of amplitude, frequency and phase remain unchanged (altering phase by 360° doesn't do anything)
  • The kind of filter we're talking about is a linear mapping of signals.
  • Any finite-length signal can be represented as a linear combination of different sine waves.
From 1,2,3 it follows that the filter you'd like to use doesn't do anything to any kind of signal and is therefore the identity mapping.

Cheers,
SG

Frequency dependent FIR filters?

Reply #2
Heh. Would delaying by a quarter-period be ok for your application?

Frequency dependent FIR filters?

Reply #3
Don't you realize that this filter actually does nothing at all?

It does nothing to the signal as long as the input is static. But pops and clicks can't come out unchanged because each frequency band is excited at a different time. The reason I wanted to find such a filter was that I had an idea of varying its size while processing, which could make something like an "allpass phaser" when mixed with the original. Another idea I had was gradually changing its size from 0% to 100% within a certain time and looping it, which could eventually result in a frequency shift downwards --- or it may go from 100% of the original size to 0%, which could make a frequency shift upwards. At least I think this is what the Sound Blaster Live 1024 was doing when I switched on its "Frequency shifter". When I set the amount of shifting fairly small and mixed the processed sound with the original, I heard something like a phaser. On the other hand, when I set the shifting frequency fairly large and removed the original, I could clearly hear that the frequencies were all shifted by the desired amount.
BTW: I was pretty surprised when I first heard this effect because the "usual" algorithm for frequency shifting that I knew (i.e. phase shifting both of the two signals by 90 degrees, multypling each other of each pair and mixing/subtracting the two results) can never make a phaser-like effect.


Heh. Would delaying by a quarter-period be ok for your application?

Well, it's one of more possibilities. If you can suggest how I could do that, it will certainly help me understand the matter a lot better.

Frequency dependent FIR filters?

Reply #4
It does nothing to the signal as long as the input is static. But pops and clicks can't come out unchanged because each frequency band is excited at a different time.

This is where you're wrong. It contradicts point #2 and #3 of the proof.

Cheers,
SG


Frequency dependent FIR filters?

Reply #6
This is where you're wrong. It contradicts point #2 and #3 of the proof.

In that case I probably wasn't exact enough in describing what filter I'm looking for. The effect I want to get is that if the input signal contains a short pure sine "click" at 500Hz starting at the position of 2 seconds, the output should contain the same click starting at 2.002 seconds (i.e. delayed by 1/500 of a second). And this amount of delay would be different depending on what frequencies would occur in the input.
Petr


Look up Hilbert transforms.

Hilbert transforms shift the phase by 90 degrees but the delay is the same for the entire frequency range -- i.e. if the impulse itself were 2 seconds long, then everything would be delayed by 1 second. What I'm trying to find is a filter which makes different frequencies delayed by different amounts of time.

 

Frequency dependent FIR filters?

Reply #7
In that case I probably wasn't exact enough in describing what filter I'm looking for. The effect I want to get is that if the input signal contains a short pure sine "click" at 500Hz starting at the position of 2 seconds, the output should contain the same click starting at 2.002 seconds (i.e. delayed by 1/500 of a second). And this amount of delay would be different depending on what frequencies would occur in the input.
There's no such thing as a "pure sine wave" "click". It doesn't exist. A rectangular-windowed single period of a sine wave is a strongly broadband signal.

There's an intrinsic tradeoff between frequency resolution and time resolution here. If you evaluated this over wider bands, say 1/4 octave, your idea would totally make sense, and would be relatively easy to implement - just put together a filter bank and delay each band by a different amount on reconstruction. But of course you lose a certain degree of smoothness in the delays that way.

Quote

Look up Hilbert transforms.

Hilbert transforms shift the phase by 90 degrees but the delay is the same for the entire frequency range -- i.e. if the impulse itself were 2 seconds long, then everything would be delayed by 1 second. What I'm trying to find is a filter which makes different frequencies delayed by different amounts of time.
Ah. In that case, nevermind.

Frequency dependent FIR filters?

Reply #8
Petr, I got you the first time. I'm simply trying to explain to you that this specific frequency-dependant delay thingy you're talking about and the identity mapping are the same.. If you're not convinced try approximating your filter by
  • creating many zero-delay band pass filters (try ten 1/4-octave-bands covering a spectrum from 750 to 24000 Hz for example)
  • shifting their impulse responses according to the desired frequency-dependant delays (ie based on the band's center frequency)
  • summing the results and checking the resulting impulse response
Compare the impulse response to the zero-delay band pass filter for 750-24000 Hz. If I'm right they should be similar.

edit: I just realized that this is close to what Axon wrote

Cheers,
SG

Frequency dependent FIR filters?

Reply #9
There's an intrinsic tradeoff between frequency resolution and time resolution here. If you evaluated this over wider bands, say 1/4 octave, your idea would totally make sense, and would be relatively easy to implement - just put together a filter bank and delay each band by a different amount on reconstruction. But of course you lose a certain degree of smoothness in the delays that way.

I think you've lost me.
If I understand your words well, that means that this method may make audible artefacts if I stretch the filter to, for example, 10 time the original size (i.e. delaying 20Hz by 500 ms).

Frequency dependent FIR filters?

Reply #10
Petr, I got you the first time. I'm simply trying to explain to you that this specific frequency-dependant delay thingy you're talking about and the identity mapping are the same.. If you're not convinced try approximating your filter by
  • creating many zero-delay band pass filters (try ten 1/4-octave-bands covering a spectrum from 750 to 24000 Hz for example)
  • shifting their impulse responses according to the desired frequency-dependant delays (ie based on the band's center frequency)
  • summing the results and checking the resulting impulse response
Compare the impulse response to the zero-delay band pass filter for 750-24000 Hz. If I'm right they should be similar.

edit: I just realized that this is close to what Axon wrote

Cheers,
SG

If I understand you well, do you want to tell me it's actually impossible to make such a filter with the FIR method?
I thought that if I stretched the filter to, for example, 100 times of its original size, that a 400Hz sine beep would be delayed by 250 ms and so mixing the processed signal with the original signal would actually result in two audible beeps one after the other.
Petr

Frequency dependent FIR filters?

Reply #11
I think you've lost me.
If I understand your words well, that means that this method may make audible artefacts if I stretch the filter to, for example, 10 time the original size (i.e. delaying 20Hz by 500 ms).
Well, don't do that then.

More specifically, the artifacts are only going to crop up in relation to changes in delay across transition bands. If you make delay change between bands small enough - say in the low milliseconds range - there shouldn't be a problem. Of course, if you shrink the bands sufficiently small, you're back to where you started...

If I understand you well, do you want to tell me it's actually impossible to make such a filter with the FIR method?
No. What we're saying is that it is mathematically impossible, with any implementation.

Frequency dependent FIR filters?

Reply #12
If I understand you well, do you want to tell me it's actually impossible to make such a filter with the FIR method?

It's perfectly possible and pretty easy to do as well because the filter you try to implement doesn't do anything. I'm afraid I'm running out of options w.r.t. how to bring this point across. I admit it may seem strage but it really boils down to a 360° phase shift. Please check the proof again. We seem to agree on point #1. Point #2 implies that when the sines don't change, any weighted (additive) combination of sines also don't change and vice versa. Point #3: It's well-known that any finite-length signal can be described as linear combination of sines. This is simple linear algebra. The vector space of all possible finite-length signals (including "transients") is spanned by a certain set of sine functions of different frequencies and phases. So, in combination with point #2 it should be clear that your filter doesn't do anything to any signal.

Cheers,
SG

Frequency dependent FIR filters?

Reply #13
If the effect is added back to the original signal, then it appears to me what Petr wants is a special-purpose multi-gated reverb with only one reflection.  I've been in some marble bathrooms that have a fast reflection on the high-end but resonate on the low-end, which would probably sound similar to what he's going for (if I understand it correctly).

Frequency dependent FIR filters?

Reply #14
It's perfectly possible and pretty easy to do as well because the filter you try to implement doesn't do anything.
Obviously, the filter WOULD shift the (non-periodic) signal along the time axis, if not anything else. Your proof no. 1 holds true just for infinitely periodic stationary signals.

Frequency dependent FIR filters?

Reply #15
Quote
Obviously, the filter WOULD shift the (non-periodic) signal along the time axis

No it doesn't because this would be a contradiction to #1,#2,#3 of the proof.

How about doing the exercise I mentioned? The result is admittedly counter-intuitive. Go ahead and try.

Edit: You know what? I'm saving you the trouble: Install GNU Octave and try this:

Save this to the file "fddelay.m":
Code: [Select]
function [y,x] = fddelay(radius)
   x = -floor(radius):radius;
   f2 = 1;
   y = x.*0;
   while (f2>0.01) %% cutoff frequency
      f1 = f2 * 0.95; %% narrow bands
      fcenter = (f1+f2)/2;
      delayinsamples = 2/fcenter;
      y = y + bandpass(x-delayinsamples,f1,f2);
      f2 = f1;
   end;
return;

function y = bandpass(x,f1,f2)
   y = lowpass(x,f2)-lowpass(x,f1);
return;

function y = lowpass(x,freq)
   y = sinc(x.*freq).*freq;
return


In the Octave console do this:
Code: [Select]
[y,x] = fddelay(999);
plot(x,y);

It'll show you the impulse response of the filter's approximation.

This thing converges to the unit impulse when you further reduce the band pass filters' bandwidths and lower the cut off frequency...

I'm done here.

Cheers,
SG

Frequency dependent FIR filters?

Reply #16
I think the naive idea behind his filter is something like this

I don't say it's realistic to achieve this, though...

Frequency dependent FIR filters?

Reply #17
[quote name='Axon' date='Jul 13 2008, 00:09' post='576713']
[quote name='Petr P.' post='576698' date='Jul 12 2008, 16:24']I think you've lost me.
[quote name='Petr P.' post='576704' date='Jul 12 2008, 16:42']If I understand you well, do you want to tell me it's actually impossible to make such a filter with the FIR method?[/quote]No. What we're saying is that it is mathematically impossible, with any implementation.
[/quote]
I've tried to make an impulse demonstrating the effect and although I didn't succeed in preserving the phases, I did succeed in delaying the frequencies. As an example, I chose a delay factor of 100 (i.e. 300hz is delayed by 1/3 of a second, 200Hz is delayed by 1/2 of a second and so on). If you are interested, I've made a temporary link to a Rar archive containing three wave files -- "beeps" (the original signal), "beeps2" (the convolved signal using 25% of its volume to prevent clipping), and "sweep" (the filter used). You can find it here: https://www.yousendit.com/download/TTdHRGx6Q0NrUmxFQlE9PQ
What I'd like to get is something very similar only with the exception that the phases should stay preserved.
Petr

Frequency dependent FIR filters?

Reply #18

Look up Hilbert transforms.

Hilbert transforms shift the phase by 90 degrees but the delay is the same for the entire frequency range -- i.e. if the impulse itself were 2 seconds long, then everything would be delayed by 1 second. What I'm trying to find is a filter which makes different frequencies delayed by different amounts of time.

No, a hilbert transformer shifts every frequency by 90 degrees. So it would turn y=sin(x)+sin(4*x) into y=cos(x)+cos(4*x). It's not just a simple quarter period delay.

This seems to be exactly what you want - a filter with a frequency dependent group delay which delays different frequencies by different amounts of time. There are several methods for designing such allpass filters, many of them fairly conceptually simple.

Frequency dependent FIR filters?

Reply #19
What I'd like to get is something very similar only with the exception that the phases should stay preserved.

Here's a simple analogy of what you're requesting:
"I'd like to have a red car. But it should be completely blue. Please help."

This seems to be exactly what you want - a filter with a frequency dependent group delay which delays different frequencies by different amounts of time. There are several methods for designing such allpass filters, many of them fairly conceptually simple.

Yeah, he wants varying group delay. He also wants H(z)=1 for |z|=1. Since the group delay is the derivative of the phase response "Theta" and "Theta" is constant zero for H(z)=1 these two requirements contradict each other.

Cheers,
SG

Frequency dependent FIR filters?

Reply #20
No, a hilbert transformer shifts every frequency by 90 degrees. So it would turn y=sin(x)+sin(4*x) into y=cos(x)+cos(4*x). It's not just a simple quarter period delay.

Aha, so how do I get a simple quarter period delay then?


Yeah, he wants varying group delay. He also wants H(z)=1 for |z|=1. Since the group delay is the derivative of the phase response "Theta" and "Theta" is constant zero for H(z)=1 these two requirements contradict each other.

Okay, I'll let it go and think about it, for the time being. But anyway, I'd like to say yet something else and I'd be glad to know what you (anyone) think about it.
A few months ago, right here, on this very forum, in topic #31226, I found a post explaining what a FIR Hilbert transform should look like. As I was just looking for a solution how to shift the phase by 90 degrees at that time, I found it useful and used a pair of hilbert transforms to get linear frequency shifts (or SSB). When I used small shifts like 1Hz or so and mixed the result with the original, it did just what I expected -- i.e. audible amplitude modulation. This confirmed that I got exactly what I was looking for. But ... Now comes the unexplained matter. At the times I had a Sound Blaster Live 1024 which had a built-in effect unit, there was an effect called "Frequency shifter" which also could make these linear shifts. But the interesting difference from my software version was that when I set the frequency shift to -1Hz and mixed it with the original, instead of hearing amplitude modulation, I heard something like a phaser whose delay was modulated by a sawtooth instead of a triangle (i.e., getting larger and larger, then suddenly jumping to 0, and getting larger again). When I set the frequency shift to +1Hz and mixed it with the original, the phaser-like effect sounded to me as if the delay was getting smaller and smaller.
Having experienced this thing, I believe that there must be yet another method for frequency shifting than the one using a pair of hilbert transforms and that there must be an explanation for a phaser-like effect which is not based on simple notch filtering.
Petr

Frequency dependent FIR filters?

Reply #21
Hilbert transforms shift the phase by 90 degrees but the delay is the same for the entire frequency range [...]

If by "delay" you mean "group delay" then yes. The group delay of this filter is zero for all frequencies. The filter's group delay of frequency 'f' tells you how "the envelope" of a narrow band around 'f' shifts in time.

No, a hilbert transformer shifts every frequency by 90 degrees. So it would turn y=sin(x)+sin(4*x) into y=cos(x)+cos(4*x). It's not just a simple quarter period delay. [...]

Depends on what kind of delay you are referring to. The filter's phase delay tells you how a specific frequency is "delayed" w.r.t. phase. So, the Hilbert filter has a frequency-varying phase delay of 1/(4f).

I basically kept saying that an all-pass filter with a 1/f phase delay isn't doing anything.

Cheers,
SG

Frequency dependent FIR filters?

Reply #22
I love this counter intuitive example.

One thing I don't understand: your Octave/MATLAB script uses log spacing. If you switch to linear spacing, then you get a clean 4 sample delay. It doesn't matter how fine the spacing, that's what you get. What's happening?

Cheers,
David.

Frequency dependent FIR filters?

Reply #23
I love this counter intuitive example.

One thing I don't understand: your Octave/MATLAB script uses log spacing.

The reason for this is that I expect it to do a better approximation because the phase delay varies more quickly for lower frequencies -- hence the lower bandwidths for lower frequencies.

If you switch to linear spacing, then you get a clean 4 sample delay. It doesn't matter how fine the spacing, that's what you get. What's happening?

I can't confirm this. Using
Code: [Select]
   while (f2>0.01) %% cutoff frequency
      f1 = f2 - 0.001;

it still looks close to a unit impulse, peaking at zero.

Cheers,
SG

Frequency dependent FIR filters?

Reply #24
Yes, you're right - I did "exactly" the same, but added a typo   

Cheers,
David.