correct way visualize short time fourier transform on each window

I am trying to visulize the short time fourier transform by windows
the code from below is what i have currently, but i am not sure if i am doing it or not.
any corrections and suggestions are welcome, thanks in advance.
%%
fs = 8000;
t = 0:1/fs:1;
signal = sin(2*pi*10*t) + 0.5*sin(2*pi*3*t);
signal_sigure = figure;
plot(t,signal)
%%
[s1, f1, t1] = stft(signal, 'Window', hamming(128,'periodic'),'OverlapLength',64,'FFTLength',128);
stft_figure = figure;
spectrogram(signal, hamming(128,'periodic'), 64, 128, fs)
%%
overlap_length = 64;
temp_t = 0:t1(4);
stft_window_fig = figure;
subplot(4,1,1)
stft_freq = zeros(size(temp_t));
stft_freq(1:t1(1)*2) = abs(s1(:, 1));
plot(temp_t, stft_freq)
xlabel("t(ms)")
ylabel("$|ST\hat{f}|$",'interpreter','latex')
title("ST$\hat{f}(\xi, \tau=64)$",'interpreter','latex')
subplot(4,1,2)
stft_freq = zeros(size(temp_t));
stft_freq(t1(1)+1:t1(2)+overlap_length) = abs(s1(:, 2));
plot(temp_t, stft_freq)
xlabel("t(ms)")
ylabel('$|ST\hat{f}|$','interpreter','latex')
title("ST$\hat{f}(\xi, \tau=128)$",'interpreter','latex')
subplot(4,1,3)
stft_freq = zeros(size(temp_t));
stft_freq(t1(2)+1:t1(3)+overlap_length) = abs(s1(:, 3));
plot(temp_t, stft_freq)
xlabel("t(ms)")
ylabel("$|ST\hat{f}|$",'interpreter','latex')
title("ST$\hat{f}(\xi, \tau=194)$",'interpreter','latex')
subplot(4, 1, 4)
plot(t, signal)
xlabel("t(s)")
ylabel("f(t)")
title("f(t) = sin(2\pi10t)+0.5sin(2\pi3t)", 'interpreter','latex')

답변 (1개)

NATHANIEL ASIAK
NATHANIEL ASIAK 2022년 3월 3일

1 개 추천

Yes, this looks right. You can however use a for loop to display the windows and then display the original signal in the last subplot. Hope this is helpful
This link gives an example on how to do this

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

제품

릴리스

R2020b

질문:

2022년 3월 3일

답변:

2022년 3월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by