I have some confusion about the commond of STFT
조회 수: 1 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
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!
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File 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!