Create a spectrogram from .wav file
71 次查看(过去 30 天)
显示 更早的评论
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')
0 个评论
回答(1 个)
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Time-Frequency Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!