Spectrogram and Spectrum of an audio file

157 views (last 30 days)
I'm trying to get the spectrogram and the spectrum of an audio file that has 2 columns, and for that, I've tried using the following for the spectrogram:
spectrogram(signal, 'window', overlap, NFFT , fs, 'yaxis')
But this function doesn't seem to work with an audio file that has 2 columns, so I've also tried the Signal Analyzer app, but the spectrogram button was greyed out, so my first question is, how should I get the spectrogram of an audio file with more than 1 columns.
As for the spectrum, I can get it through the Signal Analyzer app, but I would like to have the frequency in Hz in the x axis so that I can get the fundamental frequency from there, so I was wondering if it was possible to do that through the signal analyzer app, and if it isn't, how should I resolve this issue? I've also tried using pspectrum, and it seems like it is showing Hz on the x axis, but I'm not quite sure.

Accepted Answer

William Rose
William Rose on 17 Feb 2022
Edited: William Rose on 17 Feb 2022
[Edited because I submitted the answer before I was finished answering.]
It would help if you would attach an example file.
Compute the spectrogram of column 1 and a separate specrtrogram of column 2.
For the spectrum, I recommend pwelch().
N=20480; Fs=1000;
t=(0:N-1)/Fs;
x=randn(N,2)+[20*cos(2*pi*(250+10*sin(2*pi*t'/10)).*t'),sin(2*pi*200*t')*5.*(1+cos(2*pi*t'/20))];
figure; spectrogram(x(:,1),1000,500,1000,Fs); %channel 1 spectrogram
figure; spectrogram(x(:,2),1000,500,1000,Fs); %channel 2 spectrogram
[pxx1,f]=pwelch(x(:,1),1000,500,1000,Fs);
[pxx2,f]=pwelch(x(:,2),1000,500,1000,Fs);
plot(f,pxx1,'-r',f,pxx2,'-b');
xlabel ('Frequency (Hz)'); ylabel('Power');
legend('x(:,1)','x(:,2)')
Try it.

More Answers (0)

Categories

Find more on Time-Frequency Analysis in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!