Improve STFT Plot Clarity

조회 수: 5 (최근 30일)
Abo
Abo 2025년 4월 22일
댓글: Mathieu NOE 2025년 4월 22일
Hi,
I'm analyzing a time-domain signal using STFT and want to improve the clarity of the spectrogram. Here's my code:
load('D.mat')
nfft_custom = 1024*5;
wlen = nfft_custom;
win = hann(wlen, 'periodic');
[S, f, t_stft] = stft(AAA, 100000, ...
'Window', win, ...
'OverlapLength', round(0.5 * wlen), ...
'FFTLength', nfft_custom);
stft_dB = 20*log10(abs(S) + eps);
imagesc(t_stft, f, stft_dB); axis xy; ylim([0 800]); caxis([-70 0]);
xlabel('Time (s)'); ylabel('Frequency (Hz)');

채택된 답변

Mathieu NOE
Mathieu NOE 2025년 4월 22일
hello @Abo
and welcome back !
fist idea with STFT is to maximize the overlap , but anyway the STFT has not the best performance when you look for time AND frequency accuracy (cwt would be a better choice : look at the example in : CWT-Based Time-Frequency Analysis
to reduce the amount of fft computation I decided to downsample the data first with decimate (otherwise you are just doing a lot of computations and throw 90% at the garbage bin
to further improve the rendering with imagesc you can use the option : 'Interpolation', 'bilinear'
load('D.mat')
Fs = 100000;
% decimate the data
r = 8;
AAA =decimate(AAA,r);
size(AAA)
ans = 1×2
4096 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Fs = Fs/r
Fs = 12500
%% spectrogram
nfft_custom = 1024;
wlen = nfft_custom;
win = hann(wlen, 'periodic');
[S, f, t_stft] = stft(AAA, Fs,'Window', win,'OverlapLength', round(0.95 * wlen), ...
'FFTLength', nfft_custom,'FrequencyRange',"onesided");
stft_dB = 20*log10(abs(S) + eps);
imagesc(t_stft, f, stft_dB, 'Interpolation', 'bilinear');
axis xy;
colormap('jet');
ylim([0 800]);
caxis([-80 0]);
xlabel('Time (s)'); ylabel('Frequency (Hz)');
colorbar('vert');
  댓글 수: 2
Abo
Abo 2025년 4월 22일
Thanks, Mathieu. I’ll check out the CWT method. Your input already helped improve the STFT plot. Much appreciated.
Mathieu NOE
Mathieu NOE 2025년 4월 22일
as always, my pleasure !

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

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by