function fftwav(filename)
% plots time and frequency data for wav file filename
% Sean Hardesty (1 Feb 2006)

[y,fs]=wavread(filename);
N=2^floor(log(length(y))/log(2));
if (N < 0.75*length(y))
     N=length(y);
end

%use the next line if you have an old version of Matlab
%w=fft(y(1:N,:).*[sin((0:(N-1))*pi/N)' sin((0:(N-1))*pi/N)']);
w=fft(y(1:N,:).*[window(@hamming,N) window(@hamming,N)]);

range=(1:(N/2-1))';
f=range*fs/N;

figure(1)
subplot(2,1,1)
plot((1:N)/fs,y(1:N,1))
title('channel 1')
xlabel('t (sec)')
subplot(2,1,2)
semilogy(f,abs(w(range,1)))
xlabel('f (Hz)')

if size(y,2)==2
    figure(2)
    subplot(2,1,1)
    plot((1:N)/fs,y(1:N,2))
    title('channel 2')
    xlabel('t (sec)')
    subplot(2,1,2)
    semilogy(f,abs(w(range,2)))
    xlabel('f (Hz)')
end
