Sign in

username:

password:



Not a member?

Search Online Books



Search tips

Free Online Books



Chapters

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?

  

Matlab listing: invspectrogram.m

function a = invspectrogram(b,hop,dbg)
%INVSPECTROGRAM Resynthesize a signal from its spectrogram.
%   A = INVSPECTROGRAM(B,NHOP)
%   B is a complex array of STFT values as generated by SPECTROGRAM.
%   The number of rows of B is taken to be the FFT size, NFFT.
%   INVSPECTROGRAM resynthesizes A by inverting each frame of the 
%   FFT in B, and overlap-adding them to the output array A.  
%   NHOP is the overlap-add offset between successive IFFT frames.
%
%   See also: SPECTROGRAM

if nargin<3, dbg=0; end

[nfft,nframes] = size(b);

No2 = nfft/2;

a = zeros(1, nfft+(nframes-1)*hop);

for col = 1:nframes
  fftframe = b(:,col);
  xzp = real(ifft(fftframe)); % zero phase
  x = [xzp(nfft-No2+1:nfft); xzp(1:No2)];
  ix = (col-1)*hop + [1:nfft];
  if dbg>=8, doplots(x,x,ix,a); end
  a(ix) = a(ix) + x';  % Overlap-add
end

function []=doplots(x,xw,ix,a);
figure(8);
subplot(4,1,1);
plot(ix,x);grid; ylabel('x');
set(gca,'YLim',[-1,1]);
subplot(4,1,2);
plot(ix,xw);grid; ylabel('xw');
set(gca,'YLim',[-1,1]);
subplot(4,1,3);
nx=length(x);
ix1=ix(1);
ia1 = ix1-nx;
% if ia1>=1, ia=[ia1:ix1-1,ix]; else ia=ix; end
% plot(ia,a(ia));grid;
plot(ix,a(ix));grid; ylabel('a(ix)');
set(gca,'YLim',[-1,1]);
subplot(4,1,4);
plot(a);grid; ylabel('a');
hold on; plot([ix1 ix1],YLim); hold off;
set(gca,'YLim',[-1,1]);
disp('*** PAUSING --- RETURN to continue'); pause;


Order a Hardcopy of Spectral Audio Signal Processing

Previous: Matlab listing: spectrogram.m
Next: Matlab listing: testspectrogram.m

written by 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


No comments yet for this page


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