필터 지우기
필터 지우기

Spectrogram and Spectrum of an audio file

조회 수: 55 (최근 30일)
Juan Carlos Pérez Novoa
Juan Carlos Pérez Novoa 2022년 2월 16일
댓글: William Rose 2022년 2월 17일
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.

채택된 답변

William Rose
William Rose 2022년 2월 17일
편집: William Rose 2022년 2월 17일
[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
Juan Carlos Pérez Novoa
Juan Carlos Pérez Novoa 2022년 2월 17일
Thanks! Both of these were exactly what I was hoping to get initially.
William Rose
William Rose 2022년 2월 17일
@Juan Carlos Pérez Novoa, you're welcome.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Time-Frequency Analysis에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by