필터 지우기
필터 지우기

How to calculate integral of a square waveform

조회 수: 14 (최근 30일)
Ashwini Amin
Ashwini Amin 2018년 8월 10일
댓글: Ashwini Amin 2018년 8월 24일
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