Create a spectrogram from .wav file

조회 수: 71 (최근 30일)
Rachael Courts
Rachael Courts 2019년 5월 20일
댓글: Azadeh 2025년 3월 19일
Hi,
I'm currently working with one .wav file (hoping to achieve for multiple .wav files at once), and would like to create a black and white spectrogram. With my current code I can produce the .wav file image, but then struggle to create the actual spectrogram. I also noticed the frequency levels were very zoomed out. Code as follows;
%% reads file into matlab This reads an array of audio samples into y,
%%%assuming the file is in the current folder
[y,Fs] = audioread('T0005_01_0.03.wav');
window=hamming(512); %%window with size of 512 points
noverlap=256; %%the number of points for repeating the window
nfft=1024; %%size of the fit
[S,F,T,P] = spectrogram(y,window,noverlap,nfft,Fs,'yaxis');
surf(T,F,10*log10(P),'edgecolor','none'); axis tight;view(0,90);
colormap(hot); %%for the indexed colors, check this in help for blck/white
set(gca,'clim',[-80 -30]); %%clim is the limits of the axis colours
xlabel('Time s');
ylabel('Frequency kHz')

답변 (1개)

Matthew
Matthew 2024년 10월 10일
Hi,
The spectrogram function will display a convenience plot if you do not specify any output arguments. Your code could look like the following:
%% reads file into matlab This reads an array of audio samples into y,
%%%assuming the file is in the current folder
[y,Fs] = audioread('T0005_01_0.03.wav');
window=hamming(512); %%window with size of 512 points
noverlap=256; %%the number of points for repeating the window
nfft=1024; %%size of the fit
spectrogram(y,window,noverlap,1024,Fs,'yaxis'); % no outputs specified will create a convenience plot
colormap(gray) % for black and white
  댓글 수: 1
Azadeh
Azadeh 2025년 3월 19일
Thank you for the Code! It works great.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by