# STFT overlap add method - What am i doing wrong?

i am trying to implement a short time fourier transform of an audio signal to do some filtering (subtract another stft signal using spectral subtraction). I am using a hamming window function with 50% overlap. Additional the size of my FFT is twice the window size, zeros at the end of the signal in time domain.

mic is the input and output signal for in-place filtering

here is my code for so far:

    stftWindowSize = 256;
stftWindowSizeOver2 = stftWindowSize/2;
stftN = 512;
stftLog2n = log2(stftN);
stftNOver2 = stftN/2;

//length is the complete signal to be processed
for(i = 0;i<(length/stftWindowSizeOver2)-1;i++){

//apply hamming window and copy to complex arrays
vDSP_vmul(&mic[i*stftWindowSizeOver2],1,stftHamming,1,stftTmpStorage,1,stftWindowSize);
vDSP_ctoz((DSPComplex *)stftTmpStorage, 2, &stftMic, 1, stftWindowSize);

//fft
vDSP_fft_zrip(stftSetup, &stftMic, 1, stftLog2n, FFT_FORWARD);

//here shold the filtering happen right?

//inverse fft
vDSP_fft_zrip(stftSetup, &stftMic, 1, stftLog2n, FFT_INVERSE);

//scale back
float scale = 2*stftN;
vDSP_vsdiv(stftMic.realp, 1, &scale, stftMic.realp, 1, stftNOver2);
vDSP_vsdiv(stftMic.imagp, 1, &scale, stftMic.imagp, 1, stftNOver2);

//mic data back to real, clear original signal and add overlapping data back in
vDSP_ztoc(&stftMic, 1, (COMPLEX *)stftTmpStorage, 2, stftWindowSizeOver2);

//set old signal to zero in non overlapping area and add
if(i==0)
vDSP_vclr(mic, 1, stftWindowSize);
else
vDSP_vclr(&mic[(i+1)*stftWindowSizeOver2], 1, stftWindowSizeOver2);

}


basically what im trying to do here is:

1. get chunk of float data of length: stftWindowSize (only half the data is "new" due to 50% overlap with previous chunk) from input/output signal mic
2. apply hamming window
3. compute FFT of the chunk + zeros at the end of signal with overall length: stftN
4. compute inverse FFT
5. scale back as a result of the FFT
6. clear non overlapping area in innput/output signal mic.
7. add my processed iFFT data back into mic with a 50% overlap with previous chunk data.

My Problem:
as i'm not doing anything with my FFT-data the sound should be the same as before, but unfortunately it isn't. It sounds somewhat modified and especially low frequencies look significantly changed when i look at the spectrum of the signal before and after my STFT.

What am i doing wrong? have i misunderstood the zero padding? is this method suited for filtering (especially spectral subtraction)?
i hope you can help me!

## migrated from stackoverflow.comMar 25 '14 at 23:19

This question came from our site for professional and enthusiast programmers.

• "especially low frequencies look significantly changed when i look at the spectrum of the signal before and after my STFT" can you plot this? – endolith Sep 12 '14 at 19:31