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: testspectrogram.m

% testspectrogram.m
fs=22050;	% sampling frequency
D=1;		% test signal duration in seconds
L = ceil(fs*D)+1; % signal duration in samples
n = 0:L-1;      % discrete-time axis (samples)
t = n/fs;       % discrete-time axis (sec)
%c = ones(1,L); % dc test (good first OLA check)
c = chirp(t,0,D,fs/2); % sine sweep from 0 Hz to fs/2 Hz
windur = 0.01;  % window length in sec
Modd = 1;       % Set window parity (class can just use odd)

if Modd
  % Test odd window length:
  M = 2*round((windur*fs-1)/2)+1;
%  hop = (M-1)/2;
  hop = M;
  nfft = 2^(3+nextpow2(M));
%  w = hamming(M); w(1)=0; % Necessary for COLA property
  w = boxcar(M);
  sw = ola(w,hop,nfft); % find COLA gain 
  olaGain = max(sw);    % expect 1.08 for Hamming window
  w = w / olaGain;      % normalize system for unity gain
  x = [zeros(1,M),c(:)',zeros(1,M)]; % add room for 0-phase processing
  figure(1);
  X=spectrogram(x,nfft,fs,w,-hop,1); % or spectrogram(x,nfft,fs,w,M-hop);
else
  % Test even window length (COLA not exact)
  M = 2*round((windur*fs)/2);
  hop = M/2;
  nfft = 2^(3+nextpow2(M));
  w = hamming(M);
  sw = ola(w,hop,nfft); % find COLA gain 
  olaGain = max(sw);    % expect 1.08 for Hamming window
  w = w / olaGain;      % normalize system for unity gain
  x = [zeros(1,M),c(:)',zeros(1,M)]; % zero-phase processing
  figure(1);
  X = spectrogram(x,nfft,fs,w,-hop,1); % or spectrogram(x,nfft,fs,w,M-hop);
end
title('Spectrogram of original test signal');
print -depsc 'testspectrogram.eps';  % write plot to disk in PS format


Order a Hardcopy of Spectral Audio Signal Processing

Previous: Matlab listing: invspectrogram.m
Next: Matlab listing: unwrap.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? )