I have plotted a signal in Simulink and now i want to write a code to integrate that signal over the limits? can anyone help me with this please

clc;
clear all;
open('tranmissionfault.slx');
sim('tranmissionfault.slx');
syms t
P=int(Phasecurrent,t,0,0.008)

 Accepted Answer

Use Integrated Limited block specifying the upper limit as 0.008 and lower as 0.
edit: Thanks @Paul, i overlooked it, yes the same goal can be achieved in Simulink using a switch block, but not going in detail into it, since the OP's intention is to use MATLAB code

17 Comments

But i want to do integration by coding it in matlab not using Simulink
cumtrapz(phasecurrent.Data(phasecurrent.Time < 0.008))
Assuming phasecurrent is logged as timeseries through To workspace block. Use trapz() if you want the answer to be a scalar.
cumtrapz(phasecurrent.Data((phasecurrent.Time >= lower_limit) & (phasecurrent.Time <= upper_limit)))
Thank you so much for your time sir, i have been working on it for a long time as part of my semester project and i don't know much about matlab.
Your inputs were very helpful
I have to implement DFT algorithm under fault conditions with selective intervals and i have to write a code for it
I used your code which lead to another question
if we integrate sine wave by taking its timeperiod as an inteval we need to get 0.But, i am getting a value
Based on the code in the question, it appears that the OP wants to integrate the signal over the interval 0 < t < 0.008. The "Integrator Limited" doesn't do that. Rather it integrates the input signal over the whole simulation, but limits the integral itself to the specified limits.
I haven't tried it .... does cumtrapz really accept a timeseries as an input?
ix = (out.sinewave.Time >= 0) & (out.sinewave.Time <= 4); % lower limit 0 and upper limit 4
Int = cumtrapz(out.sinewave.Data(ix))
vpa(Int(end)) % very close to zero
Int =
0
0.1545
0.6029
1.3013
2.1813
3.1569
4.1324
5.0124
5.7108
6.1592
6.3138
6.1592
5.7108
5.0124
4.1324
3.1569
2.1813
1.3013
0.6029
0.1545
-0.0000
ans =
-0.0000000000000016375
My mistake. For some reason I didn't see you were dot indexing into PhaseCurrent, i.e., PhaseCurrent.Data.
However, shouldn't the cumtrapz use the two argument form?
ix = (out.sinewave.Time >= 0) & (out.sinewave.Time <= 4); % lower limit 0 and upper limit 4
Int = cumtrapz(out.sinewave.Time(ix),out.sinewave.Data(ix))
the form you have used is also correct, as we do the indexing directly into the data itself, i just use the first snytax mentioned in the docu
Except the first syntax assumes that the independent variable has unit spacing, which is not likely to be the case for the time vector of logged signal from a simulink model. The time spacing of the logged signal might not even be uniform if the solver is variable step.
Yes, i just noticed that specialzed power system's powergui uses Continuos method. I always work with Discrete models hence didn't notice it. Thanks for noticing it.
Thank you sir, got the answer
clc;
clear all;
open('tranmissionfault.slx');
sim('tranmissionfault.slx');
ix = (Phasecurrent.Time >= 0.012) & (Phasecurrent.Time <= 0.032016);
Int = cumtrapz(Phasecurrent.Data(ix))
vpa(Int(end))
Int =
1.0e+04 *
0
-0.0146
-0.0599
-0.1199
-0.1939
-0.2938
-0.4152
-0.5528
-0.7004
-0.8513
-1.0025
-1.1506
-1.2893
-1.4123
-1.5146
-1.6055
-1.6826
-1.7309
-1.7481
-1.7335
-1.6882
-1.6282
-1.5542
-1.4543
-1.3328
-1.1953
-1.0477
-0.8968
-0.7456
-0.5974
-0.4588
-0.3358
-0.2335
-0.1426
-0.0654
-0.0172
0.0000
ans =
0.15362797623171786653983872383833
Sir, i got 0.15 approximately when i integrate the sine wave
But,then i tried the same after the fault and i am getting huge value
F=0.05
ix = (Phasecurrent.Time >= F) & (Phasecurrent.Time <=F+0.020047);
Int = cumtrapz(Phasecurrent.Data(ix))
vpa(Int(end))
ans =
137031976.93982961773872375488281

Sign in to comment.

More Answers (0)

Communities

More Answers in the  Power Electronics Control

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Products

Release

R2023a

Community Treasure Hunt

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

Start Hunting!