pouët.net

Synth Articles

category: code [glöplog]
Nah, I was waiting for the trolls to come out..
added on the 2011-02-08 23:12:08 by trc_wm trc_wm
kusma: FFT inaccuracies are typically very small (at least with a good implementation), and rarely the reason why you'd avoid using FFT for filters. Some other, more realistic reasons:

- You don't really want a perfect filter (assuming your filtering method is to zero/reduce the bins in the stopband); it causes massive ripple in the time domain (Gibbs effect).
- If you want a cutoff that isn't exactly on the edge between two FFT bins, things get hard(er).
- It's not obvious what to do with the phase. Actually nonlinear phase filters (e.g. IIR) sound better in many music applications.
- You get lots of delay, since FFT works block-by-block. Also, if you want to change parameters (ie. a cutoff sweep), you'll get discontinuities along the edges of the FFT blocks.
- And finally, since FFT is a circular transform, if you do anything interesting to the bins information will start leaking from the end to the start of the block and vice versa.

All of these can be worked around to some extent, but for a softsynth, why bother when you can implement a simple IIR filter much cheaper and with a fraction of the issues? :-)
added on the 2011-02-09 14:38:01 by Sesse Sesse
Quote:
And finally, since FFT is a circular transform, if you do anything interesting to the bins information will start leaking from the end to the start of the block and vice versa.


That's why KB invented window-overlap-and-add & window-overlap-and-save methods.
added on the 2011-02-13 00:01:18 by trc_wm trc_wm
neoneye: funny :)
added on the 2011-02-13 06:17:20 by Danguafer Danguafer
Don't worry, I invented these only to put other people on the wrong track. Actually I solved all of the FFT problems long ago, but I keep that stuff to myself to maintain that certain edge.
added on the 2011-02-13 06:18:45 by kb_ kb_
unbeknownst to many, kb also invented the universe, humility and sliced bread (but not the internet! that was al gore's job.)
added on the 2011-02-13 08:49:21 by ryg ryg
who invented sex?
added on the 2011-02-13 08:55:17 by ferris ferris
No scener know the answer to that, I'm affraid ;)
added on the 2011-02-13 10:24:27 by Punqtured Punqtured
kb's FFTs cure cancer; too bad he never does FFTs?
added on the 2011-02-13 15:47:28 by Sesse Sesse
That was a design decision... it was either sex AND cancer or none of them. I opted for the funnier choice.
added on the 2011-02-13 16:08:14 by kb_ kb_
and then aids came from the scientologists
added on the 2011-02-13 18:40:46 by CobaltHex CobaltHex
To avoid a mess, I usually stick my pole inside the circle, no matter what KB says.
added on the 2011-02-13 18:47:51 by trc_wm trc_wm
Is there any problem I should be aware of or are you just being an idiot?
added on the 2011-02-13 21:24:48 by kb_ kb_
I'm just being an idiot.
added on the 2011-02-13 23:53:24 by trc_wm trc_wm
After reading the Filter Chapter (3) in Digital Signal Processing Using MATLAB and Wavelets by Michael Weeks, I still cannot understand how a simple equation like the FIR and IIR can filter frequencies.
added on the 2011-03-12 05:54:29 by Danguafer Danguafer
i predict a riot :)
Regardless of the type of filter, FIR and IIR, both work on the principle that they use the current input and, most importantly, the past values of the input to produce and output.

You must convince yourself that using past values can lead to a reduction in reaction speed at the output. What I mean is that it will take longer for the output to settle to its final value when you change the input of the filter suddenly. The longer a filter takes to settle to its final value (if at all - but that is beside the point) the less high frequency energy it will let through.

As an experiment, lets take the fastest changing input signal: 1,-1,1,-1,1,-1, etc.

Now we make a filter that calculates:

y(n) = x(n) + x(n-1).

This is a FIR filter with two coefficients, namely [1 1]. Now, we calculate the output sequence y(n), assuming the input sequence is infinite in both past and future:

y(0) = 1 + (-1) = 0
y(1) = (-1) + 1 = 0
y(2) = 1 + (-1) = 0
etc.

As you can see, this FIR filter filters out the input sequence completely.

Now we try the lowest frequency input sequence: 1,1,1,1,1,1,1,1,1 etc.

y(0) = 1 + 1 = 2
y(1) = 1 + 1 = 2
etc.

So the filter has a gain of 2 at 0 Hz and a gain of 0 at the nyquist frequency (0.5*sampling frequency).

--------------------------------------------------------------

You can do the same experiment for other frequencies by taking x(n) = cos(2*pi*f/fs*n), where 'f' is the frequency you want, 'fs' is the sampling frequency. By the same method as above, you can calculate the output but now we do it analytically:

y(n) = cos(2*pi*f/fs*n) + cos(2*pi*f/fs*(n-1))

which can be changed, using trigonometric identities, to:

y(n) = 2*cos(2*pi*f/fs*(n-0.5)) * cos(pi*f/fs);
where 'cos(pi*f/fs)' is a constant (it doesn't depend on 'n'), thus we could write:

y(n) = 2*C*cos(2*pi*f/fs*(n-0.5));

Two things are important here, namely: the output frequency is the same as the input frequency, i.e. ,the filter doesn't change it! Secondly, the gain at the frequency 'f' is equal to 2*C !

gain(f) = 2*cos(pi*f/fs);

The gain is part of the frequency response.

--------------------------------------------------------------

We can check if gain(f) shows the same properties as we discovered earlier.

For the lowest frequency we get gain(0) = 2.
For the highest frequency, f = 0.5*fs, we get gain(0.5*fs) = 2*cos(pi*0.5*fs/fs) = 2*cos(0.5*pi) = 0.

This is what we expect.

--------------------------------------------------------------

The other part is the phase response, i.e. the difference between the input and output angle of the cosine.

The input is : cos(2*pi*f/fs*n)
The output is: 2*C*cos(2*pi*f/fs*(n-0.5))

The difference in angle is then: -pi*f/fs (in radians).

If you have MATLAB, you can easily plot the frequency response of this filter using the FIR coefficients [1 1] by doing:

freqz([1 1], 1);

This will show the gain in dB, which is 20*log10(gain(f)) and the phase in degrees, which is -180*f/fs.

--------------------------------------------------------------

The above method is rather involved. When you have more than two coefficients, the math becomes much more complex and we need to apply some other method to get the responses. This is why the z-transform is used; it is much less complicated.

Hope this helps.
added on the 2011-03-12 12:57:47 by trc_wm trc_wm
Thought I already posted it:

With some rude analysis, is it right to conclude that the closer indices treats high frequencies while far indices treats low frequencies (long term changes)?
added on the 2011-03-15 18:55:03 by Danguafer Danguafer
no, unfortunately, there is no such relationship.
added on the 2011-03-15 19:57:59 by trc_wm trc_wm
for instance:

y(n) = x(n-100)

is a delay; it does not filter.
added on the 2011-03-15 19:59:01 by trc_wm trc_wm
Hm... Wait, I think I got it. Thanks! :D
added on the 2011-03-20 03:59:52 by Danguafer Danguafer

login