Borrar filtros
Borrar filtros

Spectrogram and Spectrum of an audio file

55 visualizaciones (últimos 30 días)
Juan Carlos Pérez Novoa
Juan Carlos Pérez Novoa el 16 de Feb. de 2022
Comentada: William Rose el 17 de Feb. de 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.

Respuesta aceptada

William Rose
William Rose el 17 de Feb. de 2022
Editada: William Rose el 17 de Feb. de 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 comentarios
Juan Carlos Pérez Novoa
Juan Carlos Pérez Novoa el 17 de Feb. de 2022
Thanks! Both of these were exactly what I was hoping to get initially.
William Rose
William Rose el 17 de Feb. de 2022
@Juan Carlos Pérez Novoa, you're welcome.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Time-Frequency Analysis en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by