Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MATLAB - Plot time-frequency graph of .wav file

I'm working on a project that involves looking at the changes in pitch/frequency over time with a wave file (I'm new to MATLAB, but not to programming). I'm able to see the time-amplitude graph and frequency-amplitude (after an FFT) graph, but how would I be able to isolate the frequency and show it at each point in time?

Code:

filename = '/Users/Username/Sample_1.wav'

[y, fs] = wavread(filename);
y = y(:,1);
dt = 1/fs;
t = 0:dt:(length(y)*dt)-dt;
plot(t,y); xlabel('Seconds'); ylabel('Amplitude');

transformed = fft(y);
mag = abs(transformed);
plot(mag);
like image 919
airplaneman19 Avatar asked Jan 15 '13 00:01

airplaneman19


1 Answers

If you have the Signal Processing Toolbox, then you may find the spectrogram function useful.

If you don't, then you can achieve the same effect manually by calculating FFTs of consecutive (possibly overlapped) windowed segments of your time-domain data, and then plotting the amplitudes.

This is essentially the short-time Fourier transform (STFT).

like image 170
Oliver Charlesworth Avatar answered Oct 19 '22 19:10

Oliver Charlesworth