Is there a way to swap axes on spectrogram?
40 views (last 30 days)
Show older comments
Matic Markovic
on 25 Jan 2021
Answered: Matic Markovic
on 26 Jan 2021
Hi!
Is there a way to swap x and y axis in lower subplot - spectrogram? Script for spectrogram is generated from Signal Analyzer app.
I need frequency on horizontal axis and time on vertical axis.
timeLimits = [0 3.981311]; %[s]
frequencyLimits = [0 120000]; %[Hz]
overlapPercent = 50;
svetlobni_tok_ROI = svetlobni_tok(:);
sampleRate = 1000000; %[Hz]
startTime = 0; %[s]
figure(2)
%FFT
minIdx = ceil(max((timeLimits(1)-startTime)*sampleRate,0))+1;
maxIdx = floor(min((timeLimits(2)-startTime)*sampleRate,length(svetlobni_tok_ROI)-1))+1;
svetlobni_tok_ROI = svetlobni_tok_ROI(minIdx:maxIdx);
subplot(2,1,1)
pspectrum(svetlobni_tok_ROI,sampleRate,'FrequencyLimits',frequencyLimits);
%Spectrogram
timeValues = startTime + (0:length(svetlobni_tok_ROI)-1).'/sampleRate;
minIdx = timeValues >= timeLimits(1);
maxIdx = timeValues <= timeLimits(2);
svetlobni_tok_ROI = svetlobni_tok_ROI(minIdx&maxIdx);
timeValues = timeValues(minIdx&maxIdx);
subplot(2,1,2)
pspectrum(svetlobni_tok_ROI,timeValues,'spectrogram','FrequencyLimits',...
frequencyLimits,'OverlapPercent',overlapPercent);
3 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!