10-01-2012 11:48 AM
I am using peakdetector function for finding peaks in a sawtooth wave. The peaks it detects is 2 units higher then the actual peak. But when i do the same thing for sine wave it detects the peaks properly.
Can anyone please tell me why am I having this problem and how to resolve it? Any help would be greatly appreciated. Thanks in advance
10-01-2012 12:14 PM
Me again
Could you provide the data set showing the issue and the respective code fragment?
10-01-2012 12:25 PM
My code is as follows:
SawtoothWave (1281, 10, 1/128, &phase, sig);
PlotWaveform (panelHandle, PANEL_GRAPH, sig, 1281, VAL_DOUBLE, 1.0, 0.0, 0.0, 1.0/128, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);
PeakDetector (sig, 1281, 0.0, 3, 0, 1, 1, &count, &peak_loc, &peak_amp, &peak_secon);
for(i=0;i<count;i++)
*(peak_loc+i)=*(peak_loc+i)/128;
PlotXY (panelHandle, PANEL_GRAPH, peak_loc, peak_amp, count, VAL_DOUBLE, VAL_DOUBLE, VAL_SCATTER, VAL_ASTERISK, VAL_SOLID,1, VAL_GREEN);
It works when i do the same thing for sine wave.....
10-01-2012 12:46 PM - edited 10-01-2012 12:52 PM
In order to reproduce it one would also need the initial value of phase...
Anyway, using your line
SawtoothWave (1281, 10, 1/128, &phase, sig);
yields constant values, i.e. no maximum, simply because 1/128 equals zero; so probably your code looks different... : How many peaks did you get, zero?
Using SawtoothWave (1281, 10, 1.0/128.0, &phase, sig); instead I obtain 10 peaks; the first location is 59.507812500000000 - rounded to an integer this yield the correct index 60...
10-01-2012 12:59 PM
With that line i got a sawtooth wave having 10 cycles. It dtects all the 10 peaks but at an amplitude 2 units higher the the actual peak. I have attached a picture of what I got...
10-02-2012 01:30 AM
I see - and also get those numbers. I would assume that this is due to the underlying algorithm which is based on fits of a quadratic polynomial; sharp edges as found in the sawtooth function result in large derivatives and seem to mislead the algorithm; you may take comfort from the fact that most of these built-in functions have limitations... As documented in this forum I am using my own PeakDetector, so you're not alone