Next  |  Prev  |  Up  |  Top  |  JOS Index  |  JOS Pubs  |  JOS Home  |  Search

STFT in Matlab

M = length(w);          % Window length
Mh = (M-1)/2;           % Assume M is odd
N = 2^nextpow2(M);      % FFT length
Xtwz = zeros(N,nframes);% pre-allocate STFT output array
zp = zeros(N-M,1);      % zero padding (to be inserted)
xoff = 0;               % current offset in input signal 
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(Mh+1:M); zp; xtw(1:Mh)]; % insert 0-padding
  Xtwz(:,m) = fft(xtwz); % STFT for frame m
  xoff = xoff + R;       % advance in-ptr by hop-size R
end


Next  |  Prev  |  Up  |  Top  |  JOS Index  |  JOS Pubs  |  JOS Home  |  Search

[Comment on this page via email]

``Lecture 6: Time-Frequency Display'', by Julius O. Smith III, (From Lecture Overheads, Music 421).
Copyright © 2020-06-27 by Julius O. Smith III
Center for Computer Research in Music and Acoustics (CCRMA),   Stanford University
CCRMA  [Automatic-links disclaimer]