MATLAB: Plotting amplitude of individual frequencies over time.

amplitudefftfrequencyMATLAB

Hi,
I'm coming back to MATLAB after a long time away.
I need to plot the amplitude of an individual frequency over the length of an audio file. I'm currently reading in the audio file, and then using an FFT on it for another part of my analysis. However, I don't know how to specific a frequency to plot the amplitude of, rather than see the spectral characteristics of all frequencies at once.
Any help & code examples would be very appreciated.

Best Answer

The pspectrum function can likely do what you want. Use the 'spectrogram' type and choose the x-axis column that corresponds to your frequency-of-interest to see it evolve over time.
Using and adapting one of the examples in the documentation:
fs = 3000;
t = 0:1/fs:1-1/fs;
x1 = chirp(t,300,t(end),1300,'quadratic',0,'convex') + ...
randn(size(t))/100;
x2 = exp(2j*pi*100*cos(2*pi*2*t)) + randn(size(t))/100;
[p,f,t] = pspectrum(x2,fs,'spectrogram');
figure
waterfall(f,t,p');
xlabel('Frequency (Hz)')
ylabel('Time (seconds)')
wtf = gca;
wtf.XDir = 'reverse';
view([30 45])
Freq = 500;
figure
plot(t, p(500,:)')
xlabel('Time')
ylabel('Amplitude')
title(sprintf('Frequency = %5d',Freq))
.
Related Question