Welcome, Guest. Please login or register.

Author Topic: Is this feasable?  (Read 3961 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Is this feasable?
« on: July 13, 2003, 09:25:05 PM »
Hi all,

Whilst working on something today, I had an idea I thought I'd bounce off people here.

I was recording some sound and cleaning it up. Then I had an idea.

Many moons ago I wrote a simple FIR bandpass filter for samples based on example source in a Zilog DSP evaluation kit. It simply cuts frequencies above and below the range you specify.

I started thinking. If you split a sample into windows and analyse each window with a fourier transform to identify the regions containing the most frequencies, could that not be used to program the FIR filter automatically?

Basically an adaptive filter of sorts that cuts the top (and bottom) frequencies based on an intensity threshold.

Overlap the windows and gradually modify the FIR response curve and you might get a very nice adaptive noise filter for samples...

Has anybody here done anything like this already?
int p; // A
 

Offline Wittgenstein

  • Newbie
  • *
  • Join Date: May 2002
  • Posts: 39
    • Show only replies by Wittgenstein
Re: Is this feasable?
« Reply #1 on: July 13, 2003, 10:16:42 PM »
Quote
I started thinking. If you split a sample into windows and analyse each window with a fourier transform to identify the regions containing the most frequencies, could that not be used to program the FIR filter automatically?


Well, the problems with the discrete Fourier transform of a discrete signal is that it is in fact a Fourier series of the periodic expansion of the signal. This means that if you just take a window and chop of the signal on both sides of that window you will get lots of ripples and smearing. The chopping can be seen as a multiplication with a box in the time domain and hence a convolution with a sinc  in the frequency domain (the ripples and smearing comes from this convolution).

The easiest way to get a better resolution is to multiply with some other kind of waveform (instead of the box). Examples of such waveforms are a raised cosine (a "bump")  or a Blackman window (available in MATLAB).

Quote
Overlap the windows and gradually modify the FIR response curve and you might get a very nice adaptive noise filter for samples...


I am not 100% sure what you mean by "gradually modify" the FIR-filter. Can you elaborate?

Quote
Has anybody here done anything like this already?


Im not sure about the filtering stuff, but this kind of approach is central in spectral analysis so the theory is probably available somewhere....

/W
Backworld /  Current 93 / Death in June / Fire + Ice /  Sol Invictus / TMLHBAC
 

Offline JoannaK

  • Hero Member
  • *****
  • Join Date: Dec 2002
  • Posts: 757
    • Show only replies by JoannaK
Re: Is this feasable?
« Reply #2 on: July 13, 2003, 10:22:39 PM »
Can't comment on Amiga programs but CoolEdit2000 on windowse has automatic function for bacground noise elimination... It requires user to give part of recording that has nothing important and then automatically eliminates (some... confiurable) of that noise of full sample.

Anyhow.. I have not been reserching it any more detail so
I've no idea how it'll exactly does the trick but it'll seem to work quite good..  Most likely it analyses known noise and creates filter (fir?) for eliminatig it.

So.. yuor method could indeed work.. at least with some cases..
 

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: Is this feasable?
« Reply #3 on: July 14, 2003, 12:47:59 AM »
What I meant by modifying the FIR filter was calculating the coefficeints based on each unique window - ie each window is filtered seperately based on the low and high frequency limits determined by the FT analysis of that window.

I also imagined that to avoid sharp changes in the filtering across windows, the windows could be overlapped say 50 % with a crossfading function of some sort.

Ie window 0 is from sample 0 - 1000, window 1 is from 500 to 1500, window 2 is from 1000-2000 and so on.

Each window would be seperately analysed and filtered and the output mixed together with a crossfade.

At least that was the thought :-) DSP isn't my strongest area...
int p; // A
 

Offline Wittgenstein

  • Newbie
  • *
  • Join Date: May 2002
  • Posts: 39
    • Show only replies by Wittgenstein
Re: Is this feasable?
« Reply #4 on: July 14, 2003, 01:21:04 AM »
Quote
What I meant by modifying the FIR filter was calculating the coefficeints based on each unique window - ie each window is filtered seperately based on the low and high frequency limits determined by the FT analysis of that window.


Ok, but how do you calculate the limits? If I understand you correctly, you have some kind of bandpass filter and the cut off frequencies depends on the signal. In what way? Do you want the band to be as narrow as possible to remove as much noise as possible or is there another reason?

Quote

I also imagined that to avoid sharp changes in the filtering across windows, the windows could be overlapped say 50 % with a crossfading function of some sort.

Ie window 0 is from sample 0 - 1000, window 1 is from 500 to 1500, window 2 is from 1000-2000 and so on.


It doesnt matter that they overlapp. You will still lose resolution because of fewer samples but you will gain "better" parameters.

This sounds like an interesting problem, but before I can do some calculations I need more information. I need the assumptions you have made, that is, what kind of signal and noise you have and how you calculate your parameters.

One interesting question is how the optimal number and size of window will look (1 window, 10 windows, 100 windows with or without overlapp). Using several windows will probably be better if the signal has a limited bandwidth which is not fixed (it is moving around in the frequency domain).

/W
Backworld /  Current 93 / Death in June / Fire + Ice /  Sol Invictus / TMLHBAC
 

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: Is this feasable?
« Reply #5 on: July 15, 2003, 01:22:33 PM »
Right, lets see

My basic assumptions were as follows

1) We analyse a window of sound to get the frequency spectrum for that window.

2) We identify the lowest and highest frequencies for which the intensity (contribution to the overall signal strength) is greater than a threshold set by the user.

3) We use those frequencies as the limits to build an FIR filter and process the original window samples to eliminate as much of those frequencies above and below as possible.

By doing this for each window in the sample we get an adaptive filtering for the sound as it changes over time.
int p; // A
 

Offline bloodline

  • Master Sock Abuser
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 12113
    • Show only replies by bloodline
    • http://www.troubled-mind.com
Re: Is this feasable?
« Reply #6 on: July 15, 2003, 01:40:18 PM »
Quote

Karlos wrote:
Right, lets see

My basic assumptions were as follows

1) We analyse a window of sound to get the frequency spectrum for that window.

2) We identify the lowest and highest frequencies for which the intensity (contribution to the overall signal strength) is greater than a threshold set by the user.

3) We use those frequencies as the limits to build an FIR filter and process the original window samples to eliminate as much of those frequencies above and below as possible.

By doing this for each window in the sample we get an adaptive filtering for the sound as it changes over time.


Still not sure what effect you're tring to achive!!!

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: Is this feasable?
« Reply #7 on: July 15, 2003, 11:43:03 PM »
Hi Matt,

Quote

Still not sure what effect you're tring to achive!!!


Oops!
 
Ok, its an adaptive noise filter that depends on the signal itself.

-edit-

It's pretty much what Wittgenstiend described in that latter post

-end edit-

Instead of uniformly removing set frequencies from a whole sample (as JoannaK mentioned) it does analysis of the sound as it changes over time (by using Fourier Analysis on windows of a certian size).

The analysis determines the frequency region (using an intensity threshold) where the signal is located and uses these parameters to build a FIR filter pair (high and low pass) to eliminate the frequencies above and below the signal region.

By splitting the sample into windows, the filtering adapts over time (each window is seperately analysed and filtered).

I was thinking to make a realtime double buffered setup for this (using very small windows of a few milliseconds) to clean up live inputs such as guitars and mics and the like...
int p; // A
 

Offline Wittgenstein

  • Newbie
  • *
  • Join Date: May 2002
  • Posts: 39
    • Show only replies by Wittgenstein
Re: Is this feasable?
« Reply #8 on: July 16, 2003, 12:24:23 AM »
Quote
My basic assumptions were as follows
1) We analyse a window of sound to get the frequency spectrum for that window.

2) We identify the lowest and highest frequencies for which the intensity (contribution to the overall signal strength) is greater than a threshold set by the user.

3) We use those frequencies as the limits to build an FIR filter and process the original window samples to eliminate as much of those frequencies above and below as possible.


Ok, all those points are more or less straight forward, so I add two other points that must be considred.

2a) Decide (in some way) the number and size of the windows.

4) Develop some kind of method to change the parameters of the filter as a function of time (position). This is probably the hardest part and it depends on the windowing technique we want to use. It is important that the filter parameters doesnt change too much (highly nonlinear filters can give rise to unwanted results).

To test the method we could skip point (2a) and fix the number and size of the windows but to get a good and robust method we probably need to find some kind of (local) maximum of the number and size of the windows (we need at least know that the specific size and number works for the data).

I would love to do some calculations on this, but Im leaving for vacation tomorrow and I will be back in about 2 weeks. If you are still interested we can continue our discussion then and I can do some basic analysis (if someone else hasnt already done it by then).

Good luck and if you get any results, please post them here (or pmail them to me).

/W
Backworld /  Current 93 / Death in June / Fire + Ice /  Sol Invictus / TMLHBAC
 

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: Is this feasable?
« Reply #9 on: July 16, 2003, 12:31:54 AM »
Quote

Wittgenstein wrote:

4) Develop some kind of method to change the parameters of the filter as a function of time (position). This is probably the hardest part and it depends on the windowing technique we want to use. It is important that the filter parameters doesnt change too much (highly nonlinear filters can give rise to unwanted results).



I was planing to cheat on this part by using overlapping windows and a crossfade :-)

So each window is discretely analysed and filtered as a finite sample. The output has a fade in (beginning to centre) and fade out (centre to end) volume envelope applied and is mixed from the middle point of the previous output.

The fade out of the previous output window will thus overlap with the fade in of the current one (the 50% overlap I mentioned earlier).

This way we remove the complexity of a true time dependent filter and approximate the desired effect.

-edit-

I should point out that that this is just an idea I have bouncing around at the moment but cant afford to work on it just yet...
int p; // A
 

Offline Wittgenstein

  • Newbie
  • *
  • Join Date: May 2002
  • Posts: 39
    • Show only replies by Wittgenstein
Re: Is this feasable?
« Reply #10 on: July 16, 2003, 12:47:23 AM »
Quote
I was planing to cheat on this part by using overlapping windows and a crossfade

So each window is discretely analysed and filtered as a finite sample. The output has a fade in (beginning to centre) and fade out (centre to end) volume envelope applied and is mixed from the middle point of the previous output.

The fade out of the previous output window will thus overlap with the fade in of the current one (the 50% overlap I mentioned earlier).

This way we remove the complexity of a true time dependent filter and approximate the desired effect.


Think about this case: If you have a signal with frequency f_1 in the first window and in the directly following window a signal with frequence f_2, with f_1>f_2 (that is, two simple sine waves).

If you use the old method you will get a filter that have a turn on frequency less than f_1 and turn off frequency greater than f_2 (you will hear both signals after the filtering).

If you instead use the new method, you will get two filters, the first one will only allow frequencies around f_1 to pass and the second one will only allow frequencies around f_2 to pass. If you now do a cross fade you will hear both tones equally bright around the moment you switch window. Hence, the result will not be the same as in the first case.

If I understand you correctly, you want the result to be as close to the first case as possible so we must deal with this in some way. This problem will probably arise as soon as the filter completely changes between the windows. If the filter only changes a "little" you will probably not hear the change. This also shows that point 4 (the problem with changing the parameters) and point 2a (the problem with choosing the windows) are in fact closely related...


/W
Backworld /  Current 93 / Death in June / Fire + Ice /  Sol Invictus / TMLHBAC
 

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: Is this feasable?
« Reply #11 on: July 16, 2003, 01:14:51 AM »
The idea as I imagined it was that the filter would behave as if it were smoothly gated. Sudden changes in filter response would be smoothed away via the crossfade.

So considering your example again:

lets say our window size is 1000 samples and we have a 50% crossfade.

We have 1000 samples of f1 followed by 1000 samples of f2

A) We analyse input samples 0-999, get a filter that passes only f1 and apply (to a copy of the samples). The result 1000 output samples are faded out from 500-999...

B) We analyse input samples 500-1499, get a filter that passes both f1 and f2 and apply (to a copy). The resultant output samples are faded in from 0-499 and faded out from 500-999. The result is then mixed onto A (starting at output offset 500)...

C) We analyse input samples 1000 - 1999, get a filter that passes f2 only and apply (to a copy). The resultant output samples are faded in from 0-499 and faded out from 500-999. The result is then mixed onto B (starting at output offset 1000)...

The effect is that the output just begins to pass f2 at 500 and just begins to reject f1 at 1000. The transition is gradual. In reality the degree of 'gating' would be user selectable.

For the example you set, a non overlapping filter would be perfect since we are dealing with a very specific case of 2 frequencies that change exactly on a window border.

In reality I want to process natural sounds such as instruments and speech for which sudden changes in the filter would probably produce unwanted effects.
int p; // A
 

Offline Wittgenstein

  • Newbie
  • *
  • Join Date: May 2002
  • Posts: 39
    • Show only replies by Wittgenstein
Re: Is this feasable?
« Reply #12 on: July 16, 2003, 01:34:15 AM »
Quote
The effect is that the output just begins to pass f2 at 500 and just begins to reject f1 at 1000. The transition is gradual. In reality the degree of 'gating' would be user selectable.


Ok, it might work but I am still not 100% sure. The best way is probably to test it :)

Quote
For the example you set, a non overlapping filter would be perfect since we are dealing with a very specific case of 2 frequencies that change exactly on a window border.


Well, it is the simplies case. If we have two spectras that are overlapping and still have completely different filter you will get another result than the ordinary method. For example, at sample 749, you will get 50% of the signal filtered with a filter using the info of the first window, and 50% of the signal filtered with a filter using the info of the second window (that is the window from smaple 500 to 1499).

But I dont have any alternative method so it can be a good starting point to try it out.

/W
Backworld /  Current 93 / Death in June / Fire + Ice /  Sol Invictus / TMLHBAC
 

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: Is this feasable?
« Reply #13 on: July 16, 2003, 01:48:53 AM »
Quote

Wittgenstein wrote:

For example, at sample 749, you will get 50% of the signal filtered with a filter using the info of the first window, and 50% of the signal filtered with a filter using the info of the second window (that is the window from smaple 500 to 1499).


Well yes, but sample 749 (f1) will a mix of 50% from a filter that passes f1 and a 50% from filter that passes both  f1 and f2 (however there is no f2 present at this position yet)

So hopefully you'll still get 100% of f1 through at this point :-)

Quote

But I dont have any alternative method so it can be a good starting point to try it out.


Yeah. If I do get around to it I'll let you know how it turned out :-)
int p; // A
 

Offline Wittgenstein

  • Newbie
  • *
  • Join Date: May 2002
  • Posts: 39
    • Show only replies by Wittgenstein
Re: Is this feasable?
« Reply #14 on: July 16, 2003, 12:05:21 PM »
Quote

Well yes, but sample 749 (f1) will a mix of 50% from a filter that passes f1 and a 50% from filter that passes both f1 and f2 (however there is no f2 present at this position yet)

So hopefully you'll still get 100% of f1 through at this point
 


Yeah, but I was thinking more generaly now... If the spectras overlap and have different filters you will get something strange (50% from the output of filter 1 and 50% from the output of filter 2).

/W
Backworld /  Current 93 / Death in June / Fire + Ice /  Sol Invictus / TMLHBAC