calculate average values of a sinusoidal signal

I want to calculate average values of a sinusoidal signal with the period 0.02s in the interval of 0.0001s. The signal I measure by a sensor. I make some codes but the results are wrong, I do not know where are the problems. Please help me check the code. if there are something wrong, please give me a hint to fix it. thank you so much.

1
2
3
4
5
6
7
8
9
10
11
12
13
f=10000;
T=1/f=0.0001;
Tsp=T/10=0.00001;
kmax=T/Tsp;

areaAB=areaAB+v_AB_o*Tsp; //v_AB is the sinusoidal signal measured by the sensor

if (k==kmax)
{
averageAB=areaAB/T;
areaAB=0;
k=0;
}
Hi,

1
2
T=1/f=0.0001;
Tsp=T/10=0.00001;


replace this with

1
2
T=1/f;
Tsp=T/10;


let the computer do your work :)

I don't much about sinusoidal signal so could you tell us more about the formula and special conditions?

PS: welcome to cplusplus.com


About the code, I just add the values 0.0001 and 0.00001 for you can understand easier. They do not appear in my code.

Example for the sinusoidal signal is v=100sine(2*pi*50*t-pi/2) and there are not special conditions.

As you can see the period of the signal is 0.02s by calculate 1/f (f=50Hz). The average value of this signal in 0.02s is zero obviously. But I only want to calculate average value in interval of 0.0001s. That means I will have 200 different average values of sine signal.

Addition, with sinusoidal signal, we will have sine waveform.
with the averages values, we will have staircase waveform. I think!!

PS: thanks for help.
Last edited on
closed account (48T7M4Gy)
There are two possibilities depending on what sort of information the sensor provides:

1) If the sensor provides voltage reading at equally spaced intervals of time then the average voltage is sum_of_voltages/number_of_readings

2) If the sensor provides the amplitude and interval of a sin wave then just calculate the average using calculus ( area_under_Sin = - Cos )

PS http://www.electronics-tutorials.ws/accircuits/average-voltage.html gives a non calculus rendition
Last edited on
Topic archived. No new replies allowed.