Question

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);
Was it helpful?

Solution

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).

OTHER TIPS

If you have the Signal Processing Toolbox, spectrogram is the way to go (as Oli Charlesworth mentioned).

If you don't have it, the MATLAB Central File exchange is always a good place to look for something that general.

http://www.mathworks.com/matlabcentral/fileexchange/1553-spectrogram-short-time-ft-log-magnitude

This seems to be a sensible and well working implementation of the spectrogram functionality.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top