You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
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
    5 views (last 30 days)
  
       Show older comments
    
clc;
clear all;
open('tranmissionfault.slx');
sim('tranmissionfault.slx');
syms t
P=int(Phasecurrent,t,0,0.008)

Accepted Answer
  madhan ravi
      
      
 on 6 Jan 2024
        
      Edited: madhan ravi
      
      
 on 6 Jan 2024
  
      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
  madhan ravi
      
      
 on 6 Jan 2024
				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.
  madhan ravi
      
      
 on 6 Jan 2024
				cumtrapz(phasecurrent.Data((phasecurrent.Time >= lower_limit) & (phasecurrent.Time <= upper_limit)))
  A Lumbini
 on 6 Jan 2024
				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
  A Lumbini
 on 6 Jan 2024
				I have to implement DFT algorithm under fault conditions with selective intervals and i have to write a code for it 
  A Lumbini
 on 6 Jan 2024
				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
  Paul
      
      
 on 6 Jan 2024
				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.
  madhan ravi
      
      
 on 6 Jan 2024
				
      Edited: madhan ravi
      
      
 on 6 Jan 2024
  
			
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
  Paul
      
      
 on 6 Jan 2024
				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))
  madhan ravi
      
      
 on 6 Jan 2024
				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

  Paul
      
      
 on 6 Jan 2024
				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.
  madhan ravi
      
      
 on 6 Jan 2024
				
      Edited: madhan ravi
      
      
 on 6 Jan 2024
  
			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.
  A Lumbini
 on 6 Jan 2024
				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
  A Lumbini
 on 7 Jan 2024
				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
More Answers (0)
Communities
More Answers in the Power Electronics Control
See Also
Categories
				Find more on Discontinuities in Help Center and File Exchange
			
	Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)


