spectrograme using STFT(DSP)

7 visualizaciones (últimos 30 días)
rohollah hosseyni
rohollah hosseyni el 23 de Feb. de 2021
Comentada: Mathieu NOE el 23 de Feb. de 2021
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

Respuesta aceptada

Mathieu NOE
Mathieu NOE el 23 de Feb. de 2021
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 comentarios
rohollah hosseyni
rohollah hosseyni el 23 de Feb. de 2021
Editada: rohollah hosseyni el 23 de Feb. de 2021
thanks a lot. it's great. I do't know how to thank you :)
Mathieu NOE
Mathieu NOE el 23 de Feb. de 2021
you're welcome

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by