Units of kHz in frequency plots

28 Ansichten (letzte 30 Tage)
Thomas Guggenbuhl
Thomas Guggenbuhl am 3 Sep. 2020
Beantwortet: Giggs B. am 3 Aug. 2021
When calling functions like pwelch, spectrogram or poctave with no function outputs, MATLAB conveniently provides a plot. That saves me from a lot of code (and potential bugs).
However, the following code (from poctave, I presume something similar occurs elsewhere) makes the plots less intuitive to my eyes, and often cause me to just define the plot from ground up.
% Determine engineering units
[~, scaleFactor, unitsStr] = signal.internal.utilities.getFrequencyEngUnits(CF(end));
...
elseif (value < 1000)
scaleFactor = 1;
unitsStr = 'Hz';
elseif (value < 1000 * 1000)
scaleFactor = 1 / 1000;
unitsStr = 'kHz';
I prefer the x-axis to read:
[3, 8, 20, 50, 126, 316, 794, 1995, 5012, 12589] [Hz]
Rather than:
[0.003, 0.008, 0.020, 0.050, 0.126, 0.316, 0.794, 1.995, 5.012, 12.589] [kHz]
I see that a similar question was asked here, where it is suggested to modify xticks after the fact, which is somewhat more complicated with the use of cathegorical for xticks:
My request would be for a string option ala:
spectrogram(x, N, N/2, N, 48e3, 'Yaxis', 'UseSIBaseUnits')

Antworten (1)

Giggs B.
Giggs B. am 3 Aug. 2021
I know its late to answer, but for someone who faces the similar problem, try this:
set(gca,'XTick',[0.003, 0.008, 0.020, 0.050, 0.126, 0.316, 0.794, 1.995, 5.012, 12.589])
set(gca,'XTickLabel',[3, 8, 20, 50, 126, 316, 794, 1995, 5012, 12589])

Kategorien

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

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by