

sr = 16000;
d = generate_sin(2,[1 2500 -pi/4],sr);
%[d,sr] = wavread('clar.wav');
S = specgram(d,256);          % SP Toolbox routine (or use ifgram.m below)
[R,M]=extractrax(abs(S));     % find peaks in STFT *magnitude*
disp(['size of R is ',num2str(size(R,1)),' rows x ',num2str(size(R,2)),' cols']);

tt = [1:(size(R,2))]*128/sr;           % default specgram step is NFFT/2 i.e. 128
F = R*sr/256;                  % Convert R from bins to Hz
specgram(d,256,sr)
colormap(1-gray)              % black is intense, white is quiet
hold on
plot(tt,F','r');              % the tracks follow the specgram peaks