% Audio processing demo in Matlab. Barnett 4/23/13
% run system cmd:    arecord -f S16_LE -r 44100 test.wav
% or get WAV exported from recording in audacity

[f fs nbits] = wavread('test.wav');  % f=data, fs=sampling freq, nbits=16
[f fs nbits] = wavread('test2.wav');

plot(f);

f = f(50000:90000); % take chunk that want, discards rest

plot(f);     % but want correct time units
N = numel(f);
plot((0:N-1)/fs, f); xlabel('time (s)');

ft = fft(f);
figure; plot(abs(ft), '-');          % what are correct freq axis units?

T = N/fsam;  % total time interval length
df = 1/T;    % frequency spacing

plot((0:N-1)*df, abs(ft), '-'); xlabel('freq (Hz)');
% now zoom in to near origin. Peaks are at around 130 Hz and multiples
% Strengths of peaks tells you about timbre of sound, etc...

semilogy((0:N-1)*df, abs(ft), '-'); xlabel('freq (Hz)');  % log vertical
% plot shows more dynamic range


