Create a spectrogram from .wav file

52 Ansichten (letzte 30 Tage)
Rachael Courts
Rachael Courts am 20 Mai 2019
Kommentiert: Azadeh am 19 Mär. 2025
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')

Antworten (1)

Matthew
Matthew am 10 Okt. 2024
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 Kommentar
Azadeh
Azadeh am 19 Mär. 2025
Thank you for the Code! It works great.

Melden Sie sich an, um zu kommentieren.

Kategorien

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

Community Treasure Hunt

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

Start Hunting!

Translated by