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;
}
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!!