I am trying to perform the STFT on a speech signal. I'd like to know when I should do the zero-padding, before windowing each frame, or after?
My attempt:
x = signal(:); % make sure signal is a column vector
sL = length(x); % signal length
wL = fix(window_Time*fs); % window length
HOP = floor(wL*(1 - overlap/100)); % windowing step
win = gausswin(wL); % window type
F = 1 + fix((sL-wL)/HOP); % calculate the number of signal frames
stft = zeros(nfft,F); % preallocate stft matrix, [nfftxF]
for f = 0:F-1
xw = x(1+f*HOP:wL+f*HOP).*win; % windowing
X = fftshift(fft([xw;zeros(wL,1)],nfft)); % FFT shifted (double-sided)
stft(:,1+f) = X; % update of the stft matrix
end
You must do it before the FFT.
P.S. I've read somewhere that the FFT algorithm already does the zero-padding automatically, i.e., When you to the FFT(x) it will already “padd” the signal x with zeros at the end, to reach the length of the FFT.