%
% file:      	wave_example.m, (c) Matthew Roughan, Wed Apr 28 2004
% directory:   /home/mroughan/Classes/Transformations/2004/Matlab/
% created: 	Wed Apr 28 2004 
% author:  	Matthew Roughan 
% email:   	matthew.roughan@adelaide.edu.au
% 
% an example of wav data
%
%
file = 'play_by_numbers_06.wav';
[y, Fs, bits] = wavread(file);
dt = 1/Fs;

fprintf('file = %s\n', file);
fprintf(' sampled at %d bits at %d Hz\n', bits, Fs);

sample_times = (1:length(y(:,1)))/Fs;

%%%% plot a segment of the input data
%%%%   the starting few tones
M = 45500;
N = 15;
temp = y(M:M+2^N,1);

figure(1) 
plot(sample_times(M:M+2^N), temp);
xlabel('seconds');

%%%% now do the FFT of the chunk of interest
y = fft(temp);
K = length(temp);
freq = (1:K/2) / (K*dt);

figure(2)
hold off
semilogy(freq/1000, abs(y(1:K/2)).^2);
hold on

xlabel('frequency (kHz)');
axis tight
