Question

I'm trying to implement a DFT-based 8-band equalizer for the sole purpose of learning. To prove that my DFT implementation works I fed an audio signal, analyzed it and then resynthesized it again with no modifications made to the frequency spectrum. So far so good.

I'm using the so-called 'standard way of calculating the DFT' which is by correlation. This method calculates the real and imaginary parts both N/2 + 1 samples in length. To attenuate a frequency I'm just doing:

float atnFactor = 0.6;
Re[k] *= atnFactor;
Im[k] *= atnFactor;

where 'k' is an index in the range 0 to N/2, but what I get after resynthesis is a slighty distorted signal, especially at low frequencies.

The input signal sample rate is 44.1 khz and since I just want a 8-band equalizer I'm feeding the DFT 16 samples at a time so I have 8 frequency bins to play with.

Can someone show me what I'm doing wrong? I tried to find info on this subject on the internet but couldn't find any.

Thanks in advance.

Was it helpful?

Solution

DFT and FFT are essentially the same for the purposes of this question.

To attenuate a frequency bin (or "band") in an FFT-transformed array, you need to multiply both the real and imaginary components by the same factor, and also multiply the real and imaginary components of the corresponding negative frequency bin. FFT produces a transformed pair of arrays where the first half of the values represent positive frequency components and the second half represents negative frequency components.

Here is a simplified code sample for a low-pass filter that explains what I mean:

// fftsize = size of fft window
int halfFFTsize = fftsize / 2;
float lowpassFreq1 = 1000.0;
float lowpassFreq2 = 2000.0;
for (int i = 0; i < halfFFTsize; i++)
{
    int ineg = fftsize - 1 - i; // index of neg. freq.
    float freq = (float)i * (44100.0F / (float)halfFFTsize);
    if (freq >= lowpassFreq2)
    {
        real[i] = 0;
        imag[i] = 0;
        real[ineg] = 0;
        imag[ineg] = 0;
    }
    else if (freq >= lowpassFreq1)
    {
        float mult = 1.0 - ((freq - lowpassFreq1) / 
            (lowpassFreq2 - lowpassFreq1));
        real[i] *= mult;
        imag[i] *= mult;
        real[ineg] *= mult;
        imag[ineg] *= mult;
    }

}

Update: after reading your edit, I'd have to say your code is working as expected. I assumed you were getting a massively distorted re-synthesized signal, not a "slighty distorted signal, especially at low frequencies".

I think the distortion you're seeing is the result of the very small window size you're using - this would especially be the case if you're not using a Hanning window approach to reconstruct the original signal.

Try running your code with a more typical window size (like 1024). An 8-band equalizer doesn't usually use an 8-bin FFT window. Typically, the settings of 8 sliders would be used to calculate a curvy function connecting the 8 points in the frequency domain, and this function would then be used to set the bin amplitudes for a much larger, more finely-grained set of frequencies.

One more point, too: the frequency bins divide up the available range evenly, so no matter how big your window size is, more than half of the bins cover frequencies that aren't audible to the human ear. This is why the bands covered by an equalizer are typically scaled logarithmically (e.g. 100Hz, 1Khz and 10Khz for a typical 3-band equalizer) and thus do not apply to equal numbers of frequency bins.

In the case of an evenly-spaced 8 bin window, attenuation of 5 of the 8 is certain to have no audible effect other than distortion of the audible frequencies.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top