Zero padding - before or after the windowing?
up vote
0
down vote
favorite
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
signal-processing fft speech
add a comment |
up vote
0
down vote
favorite
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
signal-processing fft speech
Not a programming question - try dsp.stackexchange.com ?
– Paul R
Nov 11 at 18:07
@PaulR I did not know about dsp.stackexchange.com. Thank you for the insight, I'll try there.
– user10516309
Nov 11 at 18:40
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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
signal-processing fft speech
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
signal-processing fft speech
signal-processing fft speech
edited Nov 11 at 18:48
asked Nov 11 at 16:24
user10516309
Not a programming question - try dsp.stackexchange.com ?
– Paul R
Nov 11 at 18:07
@PaulR I did not know about dsp.stackexchange.com. Thank you for the insight, I'll try there.
– user10516309
Nov 11 at 18:40
add a comment |
Not a programming question - try dsp.stackexchange.com ?
– Paul R
Nov 11 at 18:07
@PaulR I did not know about dsp.stackexchange.com. Thank you for the insight, I'll try there.
– user10516309
Nov 11 at 18:40
Not a programming question - try dsp.stackexchange.com ?
– Paul R
Nov 11 at 18:07
Not a programming question - try dsp.stackexchange.com ?
– Paul R
Nov 11 at 18:07
@PaulR I did not know about dsp.stackexchange.com. Thank you for the insight, I'll try there.
– user10516309
Nov 11 at 18:40
@PaulR I did not know about dsp.stackexchange.com. Thank you for the insight, I'll try there.
– user10516309
Nov 11 at 18:40
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
accepted
You must do it before the FFT.
- Divide the signal into frames, see butter function;
- Apply a window to each frames: frames x window;
- Zero-padd the signal;
- FFT each windowed frames.
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.
Ok. That makes sense. Thank you @Dirac.
– user10516309
Nov 12 at 2:10
add a comment |
up vote
-1
down vote
You zero pad frames inside window after windowing to make the window length the power of 2
1
Thank you. Something like xframed = [xframed; zeros(windowLength,1)]; And I apply the window to xframed and then the FFT, right? I'm using MATLAB.
– user10516309
Nov 11 at 18:37
Could you explain a little bit better the part of making the window length the power of 2? Why?
– user10516309
Nov 11 at 18:50
1
FFT algorithm requires input to be power of 2, you can check dsp.stackexchange.com/questions/8792/… for example. Matlab zero-pads automatically, you do not need to pad yourself. See "If X is a vector and the length of X is less than n, then X is padded with trailing zeros to length n" in ch.mathworks.com/help/matlab/ref/fft.html
– Nikolay Shmyrev
Nov 11 at 21:09
1
That makes sense, with or without the zero-padding (done by me), that is no different in the spectrogram. Thanks.
– user10516309
Nov 11 at 23:07
I did not know that MATLAB does zero-pads automatically, but it makes sense.
– user4061624
Nov 12 at 1:34
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You must do it before the FFT.
- Divide the signal into frames, see butter function;
- Apply a window to each frames: frames x window;
- Zero-padd the signal;
- FFT each windowed frames.
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.
Ok. That makes sense. Thank you @Dirac.
– user10516309
Nov 12 at 2:10
add a comment |
up vote
0
down vote
accepted
You must do it before the FFT.
- Divide the signal into frames, see butter function;
- Apply a window to each frames: frames x window;
- Zero-padd the signal;
- FFT each windowed frames.
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.
Ok. That makes sense. Thank you @Dirac.
– user10516309
Nov 12 at 2:10
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You must do it before the FFT.
- Divide the signal into frames, see butter function;
- Apply a window to each frames: frames x window;
- Zero-padd the signal;
- FFT each windowed frames.
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.
You must do it before the FFT.
- Divide the signal into frames, see butter function;
- Apply a window to each frames: frames x window;
- Zero-padd the signal;
- FFT each windowed frames.
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.
edited Nov 14 at 14:44
answered Nov 12 at 1:21
user4061624
Ok. That makes sense. Thank you @Dirac.
– user10516309
Nov 12 at 2:10
add a comment |
Ok. That makes sense. Thank you @Dirac.
– user10516309
Nov 12 at 2:10
Ok. That makes sense. Thank you @Dirac.
– user10516309
Nov 12 at 2:10
Ok. That makes sense. Thank you @Dirac.
– user10516309
Nov 12 at 2:10
add a comment |
up vote
-1
down vote
You zero pad frames inside window after windowing to make the window length the power of 2
1
Thank you. Something like xframed = [xframed; zeros(windowLength,1)]; And I apply the window to xframed and then the FFT, right? I'm using MATLAB.
– user10516309
Nov 11 at 18:37
Could you explain a little bit better the part of making the window length the power of 2? Why?
– user10516309
Nov 11 at 18:50
1
FFT algorithm requires input to be power of 2, you can check dsp.stackexchange.com/questions/8792/… for example. Matlab zero-pads automatically, you do not need to pad yourself. See "If X is a vector and the length of X is less than n, then X is padded with trailing zeros to length n" in ch.mathworks.com/help/matlab/ref/fft.html
– Nikolay Shmyrev
Nov 11 at 21:09
1
That makes sense, with or without the zero-padding (done by me), that is no different in the spectrogram. Thanks.
– user10516309
Nov 11 at 23:07
I did not know that MATLAB does zero-pads automatically, but it makes sense.
– user4061624
Nov 12 at 1:34
add a comment |
up vote
-1
down vote
You zero pad frames inside window after windowing to make the window length the power of 2
1
Thank you. Something like xframed = [xframed; zeros(windowLength,1)]; And I apply the window to xframed and then the FFT, right? I'm using MATLAB.
– user10516309
Nov 11 at 18:37
Could you explain a little bit better the part of making the window length the power of 2? Why?
– user10516309
Nov 11 at 18:50
1
FFT algorithm requires input to be power of 2, you can check dsp.stackexchange.com/questions/8792/… for example. Matlab zero-pads automatically, you do not need to pad yourself. See "If X is a vector and the length of X is less than n, then X is padded with trailing zeros to length n" in ch.mathworks.com/help/matlab/ref/fft.html
– Nikolay Shmyrev
Nov 11 at 21:09
1
That makes sense, with or without the zero-padding (done by me), that is no different in the spectrogram. Thanks.
– user10516309
Nov 11 at 23:07
I did not know that MATLAB does zero-pads automatically, but it makes sense.
– user4061624
Nov 12 at 1:34
add a comment |
up vote
-1
down vote
up vote
-1
down vote
You zero pad frames inside window after windowing to make the window length the power of 2
You zero pad frames inside window after windowing to make the window length the power of 2
answered Nov 11 at 18:08
Nikolay Shmyrev
19.9k43063
19.9k43063
1
Thank you. Something like xframed = [xframed; zeros(windowLength,1)]; And I apply the window to xframed and then the FFT, right? I'm using MATLAB.
– user10516309
Nov 11 at 18:37
Could you explain a little bit better the part of making the window length the power of 2? Why?
– user10516309
Nov 11 at 18:50
1
FFT algorithm requires input to be power of 2, you can check dsp.stackexchange.com/questions/8792/… for example. Matlab zero-pads automatically, you do not need to pad yourself. See "If X is a vector and the length of X is less than n, then X is padded with trailing zeros to length n" in ch.mathworks.com/help/matlab/ref/fft.html
– Nikolay Shmyrev
Nov 11 at 21:09
1
That makes sense, with or without the zero-padding (done by me), that is no different in the spectrogram. Thanks.
– user10516309
Nov 11 at 23:07
I did not know that MATLAB does zero-pads automatically, but it makes sense.
– user4061624
Nov 12 at 1:34
add a comment |
1
Thank you. Something like xframed = [xframed; zeros(windowLength,1)]; And I apply the window to xframed and then the FFT, right? I'm using MATLAB.
– user10516309
Nov 11 at 18:37
Could you explain a little bit better the part of making the window length the power of 2? Why?
– user10516309
Nov 11 at 18:50
1
FFT algorithm requires input to be power of 2, you can check dsp.stackexchange.com/questions/8792/… for example. Matlab zero-pads automatically, you do not need to pad yourself. See "If X is a vector and the length of X is less than n, then X is padded with trailing zeros to length n" in ch.mathworks.com/help/matlab/ref/fft.html
– Nikolay Shmyrev
Nov 11 at 21:09
1
That makes sense, with or without the zero-padding (done by me), that is no different in the spectrogram. Thanks.
– user10516309
Nov 11 at 23:07
I did not know that MATLAB does zero-pads automatically, but it makes sense.
– user4061624
Nov 12 at 1:34
1
1
Thank you. Something like xframed = [xframed; zeros(windowLength,1)]; And I apply the window to xframed and then the FFT, right? I'm using MATLAB.
– user10516309
Nov 11 at 18:37
Thank you. Something like xframed = [xframed; zeros(windowLength,1)]; And I apply the window to xframed and then the FFT, right? I'm using MATLAB.
– user10516309
Nov 11 at 18:37
Could you explain a little bit better the part of making the window length the power of 2? Why?
– user10516309
Nov 11 at 18:50
Could you explain a little bit better the part of making the window length the power of 2? Why?
– user10516309
Nov 11 at 18:50
1
1
FFT algorithm requires input to be power of 2, you can check dsp.stackexchange.com/questions/8792/… for example. Matlab zero-pads automatically, you do not need to pad yourself. See "If X is a vector and the length of X is less than n, then X is padded with trailing zeros to length n" in ch.mathworks.com/help/matlab/ref/fft.html
– Nikolay Shmyrev
Nov 11 at 21:09
FFT algorithm requires input to be power of 2, you can check dsp.stackexchange.com/questions/8792/… for example. Matlab zero-pads automatically, you do not need to pad yourself. See "If X is a vector and the length of X is less than n, then X is padded with trailing zeros to length n" in ch.mathworks.com/help/matlab/ref/fft.html
– Nikolay Shmyrev
Nov 11 at 21:09
1
1
That makes sense, with or without the zero-padding (done by me), that is no different in the spectrogram. Thanks.
– user10516309
Nov 11 at 23:07
That makes sense, with or without the zero-padding (done by me), that is no different in the spectrogram. Thanks.
– user10516309
Nov 11 at 23:07
I did not know that MATLAB does zero-pads automatically, but it makes sense.
– user4061624
Nov 12 at 1:34
I did not know that MATLAB does zero-pads automatically, but it makes sense.
– user4061624
Nov 12 at 1:34
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250745%2fzero-padding-before-or-after-the-windowing%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Not a programming question - try dsp.stackexchange.com ?
– Paul R
Nov 11 at 18:07
@PaulR I did not know about dsp.stackexchange.com. Thank you for the insight, I'll try there.
– user10516309
Nov 11 at 18:40