Tejas,
Note that what you are integrating is an ADC value that is never negative ( range = 0.00 ... 1.00). Therefore, your integration (summation) into temp just keeps increasing until you run into floating point limits or the DAC input range limit.
You probably need to start your for() loop with "i = 0;" (it's a 'C' language thing, arrays start at subscript zero). More importantly, since you set Aout in every step of the loop you are not performing trapazoidal integration. Perhaps your intent would be to set "temp = 0;" just before the for() loop and only set Aout after the for() loop? With your 100us delay and 200 samples, that would create a filter with a notch (zero response) at 50 Hz (updated 50 times per second).
To perform a running trapazoidal integration with samples and outputs 10,000 times per second, you need to remove the inner for() loop, and run your input array (Ia[]) as a 'ring buffer' with the index wrapped to modulus 200. Then the trapazoidal integration (over a fixed 200 sample history) reduces to subtracting half of (the oldest sample (which you are about to replace) plus the next-to-oldest sample) from your running sum (temp), and adding half of (the new sample plus the previous sample). That works best with integer ADC values. With floating-point representations of the ADC samples you may need to figure out how to prevent the accumulation of floating-point round-off errors into your running sum.
After your code is doing what you want, you might consider stablizing the sample rate by using a 'ticker' interrupt function to update a (volatile global) sample-value and a 'sample-ready' flag. Replace your (sample and wait) lines with a (wait on the flag) followed by setting the DAC (from the previously updated sum), copying the global sample value, and re-setting the flag. That will bury any timing delays and variations (from the subsequent calculation of the next sum) within the ticker's background delay. You could also put the new running sum into another global variable and let the ticker function update the DAC from that global instead.
thank you fred for your valueable replied
first thing is that it is my mistake to start array from 1 in stead of 0. i accept it.
second if i use the wait_us(100) then adc take the sample every 100 us then it would be taken 200 sample in one cycle,if signal of 50hz that way i stabilized the sampling rate.
third thing is that if i put the aout out of for loop then how can i show the result because it is an array variable then i need the for loop.
forth point if we want to show instantaneously (running) value of integration what would we do?
if we want show the integration of the one cycle at the end of integration then what would we do?beause ending of one cycle , we have 200 value of the integration because we run loop for 200 times the how to show this value on time axes?
i really don't understand the how to use ring buffer in my program?
here i show the result of the same code which i run in matab yes, i have polt this graph out of the scope of for loop it mean after completion of the integration of one cycle. i really do not understand how can i do this thing in lpc 1768.
i want to integrate signal, suppose it is sine signal. i give the sine signal through function generator to the Adc of the Mbed board. then i used the trapezoidal method to integration.it formula is given below
f(x)=(h/2)*{(y1+yn)+2*(y1+y2+y3+y4.......+yn)};; y is sample here ;h is the sampling time;;
problem is that when i try to show the integrated signal through the DAC(pin18)then it is not able to show me any signal. it shows me random noise signal rather than cos signal. i have tryed it in simulation software (matlab) then this code is perfectly run but in mbed it is not working.