Effacer les filtres
Effacer les filtres

Spectrogram and Spectrum of an audio file

55 vues (au cours des 30 derniers jours)
Juan Carlos Pérez Novoa
Juan Carlos Pérez Novoa le 16 Fév 2022
Commenté : William Rose le 17 Fév 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.

Réponse acceptée

William Rose
William Rose le 17 Fév 2022
Modifié(e) : William Rose le 17 Fév 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 commentaires
Juan Carlos Pérez Novoa
Juan Carlos Pérez Novoa le 17 Fév 2022
Thanks! Both of these were exactly what I was hoping to get initially.
William Rose
William Rose le 17 Fév 2022
@Juan Carlos Pérez Novoa, you're welcome.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Time-Frequency Analysis dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by