Filter löschen
Filter löschen

Spectrogram and Spectrum of an audio file

55 Ansichten (letzte 30 Tage)
Juan Carlos Pérez Novoa
Juan Carlos Pérez Novoa am 16 Feb. 2022
Kommentiert: William Rose am 17 Feb. 2022
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.

Akzeptierte Antwort

William Rose
William Rose am 17 Feb. 2022
Bearbeitet: William Rose am 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.
  2 Kommentare
Juan Carlos Pérez Novoa
Juan Carlos Pérez Novoa am 17 Feb. 2022
Thanks! Both of these were exactly what I was hoping to get initially.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Time-Frequency Analysis finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by