Yes this part will not work all the time.
Thanks for pointing out.
Can you throw some light how can I avoid some for loop when I want to do calculations online? I am using this method to detect start and stop of my waveform.
1) What is your definitition of "calculation online"? Where exactly is that?
Calculation online means this is performed on live data not on the past data. Where I don't know at what sample my cycle will start. Position of peak will very anywhere between samples I captured.
2)Your loops differ very little. I am sure you could combine the bulk of the code to avoid all that repetition.
This is just example code actual code contains subVis for code repetition.
3) It is a really bad idea to place user files into the root folder (C:\data.csv).
This is just example for Rani_jcha's question. Path can be anything.
4)Your code does not work right if the first peak is negative..
In my case I am capturing sine wave signal and I do soft firing of TRIAC, so I always get positive peak first.