I have some confusion about the commond of STFT

조회 수: 1 (최근 30일)
neal paze
neal paze 2021년 5월 17일
댓글: neal paze 2021년 6월 2일
I want to apply the commond of STFT to solve my problem,but I face two problems.Firstly,my date's frequencyRange is 100-2000,there is no commond to set it.In the help page of STFT in mathwork.com,frequencyRange only have three choices--'centered' |'twosided' | 'onesided'.Secondly,I need to use different date to make some figures by using STFT.Different date may cause every figure has different scale of colorbar,I want all my figures have same scale of colorbar.

채택된 답변

Bhavik Patel
Bhavik Patel 2021년 5월 20일
It is my understanding that you want to plot STFT for custom frequency range. You would also like to apply the same scale for colorbar to visualize plots for different data.
You can use the output arguments of stft function to visualize custom frequency range. To apply the same scale of colorbar, set colormap limits using caxis function.
The following example illustrates one way to achieve these objectives:
fs = 10e3; % Sampling frequency
LowerFreq = 100; % Lower frequency
UpperFreq = 2000; % Upper frequency
FFTLen = 512; % FFT length
% Generate a signal for two seconds
t = 0:1/fs:2;
x = vco(sin(2*pi*t),[500 1400],fs);
% Comute STFT
[S,F,T] = stft(x,fs,'FFTLength',FFTLen,'FrequencyRange','onesided');
% Compute FFT bins for lower and higher frequencies
LowerFreqIdx = ceil(LowerFreq*FFTLen/fs);
UpperFreqIdx = ceil(UpperFreq*FFTLen/fs)+1;
customFreqRange = LowerFreqIdx:UpperFreqIdx;
% Plot STFT
smag = mag2db(abs(S));
pcolor(T,F(customFreqRange),smag(customFreqRange,:))
xlabel('Time (s)')
ylabel('Frequency (Hz)')
shading flat
colorbar
caxis([-100 100]) % set colormap limits
Hope this helps!
  댓글 수: 2
neal paze
neal paze 2021년 5월 21일
THANK YOU VERY MUCH!
I still have some questions.I need to do deep learning.I only need the result without the axis and save it as the size of 224* 224 to suit the CNN.
neal paze
neal paze 2021년 6월 2일
Can you answer the added question?Thanks!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by