How to make the resolution for a spectrogram higher

40 ビュー (過去 30 日間)
Freya Guo
Freya Guo 2022 年 9 月 16 日
コメント済み: Freya Guo 2022 年 9 月 27 日
I'm trying to plot the spectrogram of an auditory stimulus but the resolution looked really low. I tried to change the parameters for the plot but none helped significantly. Is there some specific parameters I can change to make a higher-quality plot? Thank you!
The code I used is as follows:
Fs=44100;
win_size = 0.01;
fft_overlap = 0.3;
hop_size = Fs*win_size;
nfft = round(hop_size/fft_overlap);
noverlap = round(nfft-hop_size);
w = sqrt(hann(nfft)); %use some window
figure
spectrogram(tWaveform, w ,noverlap, nfft, Fs, 'yaxis' );
colormap jet;
set(gca,'YLim', [0,3]);
set(gca,'XLim', [0.4,1.2]);
  3 件のコメント
Mathieu NOE
Mathieu NOE 2022 年 9 月 19 日
following my comment above , and using @Chunru demo code, you can assign a min threshold to your spectrogram plot
IMHO this makes the plot less aggressive :
load handel.mat
tWaveform = y;
Fs=44100;
nfft =1024;
noverlap = round(.75*nfft);
w = sqrt(hann(nfft)); %use some window
figure
spectrogram(tWaveform, w ,noverlap, nfft, Fs, 'yaxis' ,'MinThreshold',-100); % remove estimates less than -100 dB
% [S,F,T,P] = SPECTROGRAM(...,'MinThreshold',THRESH) sets the elements of
% P to zero when the corresponding elements of 10*log10(P) are less than
% THRESH. Specify THRESH in decibels. The default value of THRESH is
% -Inf.
colormap jet;
set(gca,'YLim', [0,3]);
set(gca,'XLim', [0.4,1.2]);
Freya Guo
Freya Guo 2022 年 9 月 27 日
Thank you this has helped!

サインインしてコメントする。

採用された回答

Chunru
Chunru 2022 年 9 月 19 日
load handel.mat
tWaveform = y;
Fs=44100;
win_size = 0.02; % 20ms
ws = round(win_size*Fs);
noverlap = round(.75*ws);
w = sqrt(hann(ws)); %use some window
nfft =1024;
figure
spectrogram(tWaveform, w ,noverlap, nfft, Fs, 'yaxis' );
colormap jet;
set(gca,'YLim', [0,3]);
set(gca,'XLim', [0.4,1.2]);

その他の回答 (1 件)

Apeksha Bagrecha
Apeksha Bagrecha 2022 年 9 月 20 日
Possible workarounds to this issue are provided below:
1) Open your script as a Live Script and export it as an HTML or other format.
You can do this by right-clicking on the script file in the Current Folder browser and selecting "Open as Live Script". Then run the script and save it to an HTML. In the save dialog box, change the ‘Save as type’ to ‘HTML (*.html)’.
2) Manually increase the resolution of the figure in your script, save the figure to an image file, and embed the image using publishing markup. e.g.
>>print('test_non_pub','-dpng','-r300')

カテゴリ

Help Center および File ExchangeTime-Frequency Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by