How to calculate integral of a square waveform

38 次查看(过去 30 天)
Hi,
Could you please let us know how to calculate integral of a square waveform using Matlab

采纳的回答

Ameer Hamza
Ameer Hamza 2018-8-10
You can use the square() function to create a square wave with the time period of 2*pi and amplitude between -1 and 1. And then use trapz() to evaluate the integral numerically. For example
t = 0:0.1:10; %%choose the range you want
y = square(t);
trapz(t,y)
  2 个评论
Ashwini Amin
Ashwini Amin 2018-8-24
Hi,
Thank you for your response. I am trying below but i am unable to use this function as it is displaying me a error. Please help
t=0:1e-3:4; S1t=heaviside(t)-heaviside(t-2); S2t=heaviside(t)-2*heaviside(t-1)+heaviside(t-2); S3t=heaviside(t)-2*heaviside(t-2)+heaviside(t-3); S4t=-1*heaviside(t)+heaviside(t-3);
subplot(411);
plot(t,S1t);
title(' S1 ');
subplot(412);
plot(t,S2t);
title(' S2 ');
subplot(413);
plot(t,S3t);
title(' S3 ');
subplot(414);
plot(t,S4t);
title(' S4 ');
%Energy of the signal1
e1Energy= sum(abs(S1t).^2)*1e-3 e2Energy= sum(abs(S2t).^2)*1e-3 e3Energy= sum(abs(S3t).^2)*1e-3 e4Energy= sum(abs(S4t).^2)*1e-3 figure(2); squareRoote1 = sqrt(e1Energy); %F1(t) solution f1t = S1t/squareRoote1; figure(2); subplot(411); plot(t,f1t);
%Calculate C12
%c12input = S2t*f1t;
c12 = trapz(t,S2t,f1t)
Error : Error using trapz Dimension argument must be a positive integer scalar within indexing range.
Ashwini Amin
Ashwini Amin 2018-8-24
I am trying to calculate the integration of 2 signals. Please suggest a better option to calculate this from -inf to +inf limits

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differentiation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by