How to calculate integral of a square waveform

36 visualizaciones (últimos 30 días)
Ashwini Amin
Ashwini Amin el 10 de Ag. de 2018
Comentada: Ashwini Amin el 24 de Ag. de 2018
Hi,
Could you please let us know how to calculate integral of a square waveform using Matlab

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 10 de Ag. de 2018
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 comentarios
Ashwini Amin
Ashwini Amin el 24 de Ag. de 2018
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 el 24 de Ag. de 2018
I am trying to calculate the integration of 2 signals. Please suggest a better option to calculate this from -inf to +inf limits

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by