[R] average waveform over many cycles

Jim Lemon jim at bitwrit.com.au
Wed Oct 10 14:01:57 CEST 2007

Bill Simpson wrote:
> I have 400 cycles of a noisy waveform. I would like to find the average
> (over the 400 cycles) of one cycle. Please tell me to do it in R. Any
> suggestions welcome!
Hi Bill,
I recently had to do something like this for an "approach to target" 
curve. The steps were:

1) Create a matrix or data frame to hold all your data (400 rows, say, 
with enough columns to hold the data for one cycle) filled with NAs

2) Identify a common start or end point. In my case it was the target hit.

3) Because it was an end point, I had to fill each row of the matrix 
from the end until I reached the beginning of that approach (they were 
different lengths) leaving the NAs at the beginning. They won't plot.

4) Once the matrix is full, use "apply" to get whatever measure of 
central tendency you want for each column.

5) I then plotted all of the approaches in a light color, say #ffaaaa,
then overplotted the average in a darker color, e.g. #ff0000.

You can also plot confidence intervals for the curve, etc.


More information about the R-help mailing list