I have some confusion about the commond of STFT

4 Ansichten (letzte 30 Tage)
neal paze
neal paze am 17 Mai 2021
Kommentiert: neal paze am 2 Jun. 2021
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.

Akzeptierte Antwort

Bhavik Patel
Bhavik Patel am 20 Mai 2021
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 Kommentare
neal paze
neal paze am 21 Mai 2021
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 am 2 Jun. 2021
Can you answer the added question?Thanks!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Time-Frequency Analysis finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by