Customize the x-axis of hht plot

2 views (last 30 days)
For the following hht plot, I want to customize datetime values for 501 data points in x-axis instead of default time values. The datetime values should start from 01-01-1995.
t = 0:0.01:5;
signal = sin(2*pi*2*t) + sin(2*pi*5*t) + randn(size(t));
imf = emd(signal);
% Plot HHT spectrum
hht(imf, 1/mean(diff(t)), 'FrequencyLimits', [0 5]);
% Customize plot labels and title
xlabel('Time');
ylabel('Frequency (Hz)');
title('Hilbert-Huang Transform (HHT) Spectrum');

Accepted Answer

Star Strider
Star Strider on 26 Jan 2024
Putting 501 datetime x-ticks would be impossible to read, at least with this example. This creates all of them, nowever only uses 24 for obvious reasons.
Make appropriate changes to use the ones you want —
t = 0:0.01:5;
signal = sin(2*pi*2*t) + sin(2*pi*5*t) + randn(size(t));
imf = emd(signal);
% Plot HHT spectrum
hht(imf, 1/mean(diff(t)), 'FrequencyLimits', [0 5]);
Ax = gca;
xt = Ax.XTick;
N = 501;
xtime = linspace(min(xt), max(xt), N);
DT = datetime(1995,1,1) + years(xtime);
DT.Format = 'dd-MMM-yyyy';
xtnew = linspace(min(xt), max(xt), numel(xt)*4);
xtlnew = linspace(min(DT), max(DT), numel(xt)*4);
Ax.XTick = xtnew;
Ax.XTickLabel = compose('%s',xtlnew);
% Customize plot labels and title
xlabel('Time');
ylabel('Frequency (Hz)');
title('Hilbert-Huang Transform (HHT) Spectrum');
.

More Answers (0)

Categories

Find more on Polynomials in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!