LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Peak detection function for sawtooth waveform not working properly

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 :smileyhappy:

0 Kudos
Message 1 of 6
(3,546 Views)

Me again Smiley Wink

 

Could you provide the data set showing the issue and the respective code fragment?

0 Kudos
Message 2 of 6
(3,545 Views)

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.....

0 Kudos
Message 3 of 6
(3,541 Views)

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...

0 Kudos
Message 4 of 6
(3,538 Views)

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... 

0 Kudos
Message 5 of 6
(3,533 Views)

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 Smiley Wink

0 Kudos
Message 6 of 6
(3,512 Views)