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 CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by