Sign in

username:

password:



Not a member?

Search Online Books



Search tips

Free Online Books



Chapters

See Also

Embedded SystemsFPGAElectronics

Chapter Contents:

Search Spectral Audio Signal Processing

  

Book Index | Global Index


Would you like to be notified by email when Julius Orion Smith III publishes a new entry into his blog?

  

STFT in Matlab

The following matlab segment, adapted from §G.3, illustrates the above processing steps:

Xtwz = zeros(N,nframes); % pre-allocate STFT output array
M = length(w);           % M = window length, N = FFT length
zp = zeros(N-M,1);       % zero padding (to be inserted)
xoff = 0;                % current offset in input signal x
Mo2 = (M-1)/2;           % Assume M odd for simplicity here
for m=1:nframes
  xt = x(xoff+1:xoff+M); % extract frame of input data
  xtw = w .* xt;         % apply window to current frame
  xtwz = [xtw(Mo2+1:M); zp; xtw(1:Mo2)]; % windowed, zero padded
  Xtwz(:,m) = fft(xtwz); % STFT for frame m
  xoff = xoff + R;       % advance in-pointer by hop-size R
end

Notes:

  • The window w is implemented in zero-centered (``zero-phase'') form (see, e.g., §2.5.4 for discussion).

  • The signal x should have at least Mo2 leading zeros for this (simplified) implementation.

  • See §G.3.1 for a more detailed implementation.


Previous: Two Dual Interpretations of the STFT
Next: Classic Spectrograms

Order a Hardcopy of Spectral Audio Signal Processing


About the Author: Julius Orion Smith III
Julius Smith's background is in electrical engineering (BS Rice 1975, PhD Stanford 1983). He is presently Professor of Music and Associate Professor (by courtesy) of Electrical Engineering at Stanford's Center for Computer Research in Music and Acoustics (CCRMA), teaching courses and pursuing research related to signal processing applied to music and audio systems. See http://ccrma.stanford.edu/~jos/ for details.


Comments


 

celmoucary wrote:

6/4/2008
 
I have one question please. I would like to know how to compute the Inverse STFT after having done some computations and modifications on the array given by the STFT.
Thank you
 

JOS wrote:

6/4/2008
 
For that, you do what is called "overlap-add" reconstruction. That is, after performing the inverse FFT on each column of the Xtwz matrix, they are shifted by (m-1)*R samples (where m is the column number) and summed. See http://www.dsprelated.com/dspbooks/sasp/Overlap_Add_OLA_STFT_Processing.html
for more details.
 

mardsp wrote:

7/7/2009
 
I have one question, What does Mo2 stand for?
 

JOS wrote:

7/7/2009
 
"M over 2" - see the code referenced for details - jos
 

bluebear5225 wrote:

5/7/2010
 
Hi I have a question about line 8 of this code. Why does xtwz go from the last half of xtw to the first half of xtw?
As in, why is xtw extracted first from Mo2 to M, and then after that, from 1 to Mo2, and not the other way around?

Thanks!
 

JOS wrote:

5/7/2010
 
This is to implement the window w in zero-centered ("zero-phase") form. Note that the signal x should have at least Mo2 leading zeros for this implementation. Search for "zero-phase zero-padding" for more discussion.
 

bluebear5225 wrote:

5/7/2010
 
I read through your Blackman zero-phase-zero-padding example. In that example, window length M was shorter than the signal length N. Right now, I have an audio signal that does not have leading zeros. I am trying to carry out a series of transforms, where I take N-points, window it with an N-length window, and then FFT the result, and continue doing that for a series of N points. The process looks like the code on this page. Without leading zeros on my signal, should I still use line 8, or should I omit it, and replace xtwz with xtw in line 9? Because with window length being the same as signal length, zp would not exist.

Thanks a lot! =]
 

JOS wrote:

5/7/2010
 
Yes, you can do that with no drawbacks if you are only going to look at the FFT magnitude. Otherwise you will be adding a linear phase term to your phase spectrum. Also note that the first N/2-1 samples of your signal will be attenuated (by the window) because you don't have N/2-1 leading zeros, unless of course you use the rectangular window. :-)
 

juangc70 wrote:

5/11/2010
 
Hi all,
I am working on a project audio signal enhancement and I am using a spectrogram in order to analize the data. The signal is corrupted with noise and there is no filter that could help me get rid of this noise. I can modify the STFT matrix but matlab does not do inverse for this. I read that the ISTFT is the sum of all IDFT's of each column? If there is anyone that worked with this before I will appreciate suggestions,
Thanks!!
 

akshay231289 wrote:

2/5/2011
 
i have calculated stft using spectrogram func in matlab and have done some computaional work. now i need to do inverse stft how to do it???
 

shailendrat wrote:

9/21/2011
 
Let x[n] = cos (2  5  10􀀀2  n) and n = 0; 1; : : : ; 399. With x[101] = 3,
1. Compute spectrogram of x[n] with Hamming window of length 16 and 32, with no
overlap and 50% overlap.
2. State your observations.


please help me . i m new in MATLAB .solve this
 

shailendrat wrote:

9/21/2011
 
x[n]= cos(2pi*5*10^-2*n) and n= 0,1,.................399

Add a Comment
You need to login before you can post a comment (best way to prevent spam). ( Not a member? )