With the help of Python, calculate the effective (RMS) values of the following periodic signals.
The function quad from the scipy.integrate module may be useful for performing the necessary integrations. It takes as arguments a function, a lower bound, and an upper bound, and returns the value of the integral over that interval.
1/ . Compare your result with the known formula for a sinusoidal signal.
quad function to compute the integral.The period is .
from scipy.integrate import quad
import numpy as np
def s1_squared(t):
return ( 10*np.cos(20*np.pi*t + np.pi/2) )**2
T = 0.1 # period
integral, _ = quad(s1_squared, 0, T) # quad returns a tuple (value, error)
rms_value = np.sqrt(integral / T)
print("RMS value of s1:", rms_value)2/ . Compare your result with the known formula for a sinusoidal signal.
The period is .
from scipy.integrate import quad
import numpy as np
def s2_squared(t):
return np.cos(np.pi * t)**4
T = 2 # period
integral, _ = quad(s2_squared, 0, T) # quad returns a tuple (value, error)
rms_value = np.sqrt(integral / T)
print("RMS value of s2:", rms_value)3/ A triangular wave centered around zero with a peak value of 5 V and a period of .
The half-period is .
Between and , the signal rises linearly from to , with a slope of and a y-intercept1 of .
Between and , the signal falls linearly back to with a slope of and a y-intercept of .
from scipy.integrate import quad
import numpy as np
T = 2e-3
def s3_squared(t):
t = t % T # wrap around the period
if 0 <= t < 0.001:
return (10000 * t - 5)**2 # rising edge
else:
return (-10000 * t + 15)**2 # falling edge
integral, _ = quad(s3_squared, 0, T) # quad returns a tuple (value, error)
rms_value = np.sqrt(integral / T)
print("RMS value of s3:", rms_value)