How to add a horizontal line in a plot that corresponds to a maximum?
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
movRMS = dsp.MovingRMS
% The Signal Codes (assume no noise)
t = (0:0.0001:1); % signal duration : 1s
a = 0.60; % the decrease of rms voltage range from 0.1 pu to 0.9 pu (10% to 90% decreased)
w = 100; % the phase angle jump ( ex. 50, 100, 170)
t = (0:0.0001:1); % signal duration : 1s
a = 0.60; % the decrease of rms voltage range from 0.1 pu to 0.9 pu (10% to 90% decreased)
f = 50; % frequency
ti = 0.10; % initiation
tr = 0.50; % recovery (duration: 0.4s)
y = (1 - a*(heaviside(t-ti) - heaviside (t-tr))).*(sin(2*pi*f*t+w)); % heaviside is the unit step
rmsval = 2*movRMS(y) % RMS detection code
% Plot Disturbance waveform
figure (1)
subplot(2,1,1)
plot (t,y)
xlabel('Time (s)')
ylabel('Amplitude (pu)')
title('Voltage Sag')
% Plot RMS waveform
subplot(2,1,2)
plot (t,rmsval)
xlabel('Time (s)')
ylabel('Magnitude (pu)')
title('RMS Detection')
Edit: I would like to add a horizontal line (blue horizontal line in figure 2) corresponding to the maximum value of the waveform which only change when the peak amplitude also changes as you can see in figure 2. I also attached my simulation result in figure 1. Thank you for your attention.

Figure 1 : My simulation

Figure 2 : Sag voltage with RMS Detection
4 Commenti
Jeffrey Clark
il 11 Giu 2022
@Irfanudin Nor Anwar, use Find local maxima - MATLAB islocalmax (mathworks.com) and create the blue line plot from spline of the local maxima and ppval the spline to get the y values of the blue line.
Risposte (2)
Sam Chak
il 11 Giu 2022
No worries, I take your samples. Generally, you need to guess the function of a curve that might fit into the peaks:
% find peaks
[pks, locs] = findpeaks(y, t);
pks = [pks(1:25) pks(27:31)];
locs = [locs(1:25) locs(27:31)];
% curve fitting
fo = fitoptions('Method', 'NonlinearLeastSquares', ...
'Lower', [1e44, 0.2], ...
'Upper', [1e46, 0.4], ...
'StartPoint', [1.5e44 0.3]);
ft = fittype('1 - 0.6*exp(-b*(x - c)^64)', 'options', fo);
[curve, gof] = fit(locs', pks', ft)
% plotting
plot(t, y)
axis([0 0.6 -1.5 1.5])
hold on
plot(curve)
hold off

Star Strider
il 11 Giu 2022
movRMS = dsp.MovingRMS;
% The Signal Codes (assume no noise)
t = (0:0.0001:1); % signal duration : 1s
a = 0.60; % the decrease of rms voltage range from 0.1 pu to 0.9 pu (10% to 90% decreased)
w = 100; % the phase angle jump ( ex. 50, 100, 170)
t = (0:0.0001:1); % signal duration : 1s
a = 0.60; % the decrease of rms voltage range from 0.1 pu to 0.9 pu (10% to 90% decreased)
f = 50; % frequency
ti = 0.10; % initiation
tr = 0.50; % recovery (duration: 0.4s)
y = (1 - a*(heaviside(t-ti) - heaviside (t-tr))).*(sin(2*pi*f*t+w)); % heaviside is the unit step
rmsval = 2*movRMS(y); % RMS detection code
yenv = envelope(y, 500, 'analytic');
rmsenv = envelope(rmsval, 85, 'peak');
% Plot Disturbance waveform
figure (1)
subplot(2,1,1)
plot (t,y)
hold on
plot(t, yenv, '-r', 'LineWidth',2)
hold off
xlabel('Time (s)')
ylabel('Amplitude (pu)')
title('Voltage Sag')
% Plot RMS waveform
subplot(2,1,2)
plot (t,rmsval)
hold on
plot(t, rmsenv, '-r', 'LineWidth',2)
hold off
xlabel('Time (s)')
ylabel('Magnitude (pu)')
title('RMS Detection')
.
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
