spectrograme using STFT(DSP)

1 回表示 (過去 30 日間)
rohollah hosseyni
rohollah hosseyni 2021 年 2 月 23 日
コメント済み: Mathieu NOE 2021 年 2 月 23 日
I wan to build an image same left image with STFT , but I don't understand why my output image(left) is not like right image(desired).
any one can write desired code?
thanks a lot
N=512; n=1:1:N;
y=4*cos(8*pi*n/N)+N/5;
x=cos(2*pi*y.*(n/N));
>> s = spectrogram(x);
stft(x,1000,'Window',gausswin(128),'OverlapLength',110,'FFTLength',256); colormap jet

採用された回答

Mathieu NOE
Mathieu NOE 2021 年 2 月 23 日
hello
I was not comfortable with how you defined the basics constants in your code , so I rewrote it my way - I believe more readable (even if longer)
I used pcolor with interp shading to get the same smooth visual aspect as your target image
hope it helps
% demo
f1_mean = 100; % mean freq (start value)
f1_amplitude = 50; % beating amplitude of freq
f_mod = 5; % max frequency of modulation
Fs = 512; % sampling frequency
duration = 1; % s
%%%%%%%%%%%
dt = 1/Fs;
samples = floor(duration*Fs)+1;
t = (0:dt:(samples-1)*dt);
mod_amplitude = linspace(0,1,samples); % linear increase of frequency modulation with time
omega = 2*pi*(f1_mean+f1_amplitude.*mod_amplitude.*sin(2*pi*f_mod.*t));
angle_increment = omega.*dt;
angle = cumtrapz(angle_increment); % angle is the time integral of omega.
signal = sin(angle);
figure(1);
plot(t,signal)
% spectrogram demo
NFFT = 32; % to have highest frequency resolution , NFFT should be greater than typical max length of files ( 1 second duration at Fs = 16 kHz = 1600 samples);
Noverlap = round(0.975*NFFT);
w = hanning(NFFT);
[sg,fsg,tsg] = specgram(signal,NFFT,Fs,hamming(NFFT),Noverlap);
% plots sg
figure(2);
pcolor(tsg,fsg,20*log10(abs(sg)));axis('xy');colorbar('vert');colormap jet
shading interp
title(['Spectrogram / Fs = ' num2str(Fs) ' Hz / Delta f = ' num2str(fsg(2)-fsg(1)) ' Hz ']);
xlabel('Time (s)');ylabel('Frequency (Hz)');
  2 件のコメント
rohollah hosseyni
rohollah hosseyni 2021 年 2 月 23 日
編集済み: rohollah hosseyni 2021 年 2 月 23 日
thanks a lot. it's great. I do't know how to thank you :)
Mathieu NOE
Mathieu NOE 2021 年 2 月 23 日
you're welcome

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultirate Signal Processing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by