03-19-2012 07:38 AM
I made a very a simple peak detector program that detects and stores peaks/valleys of a noisy sinusoid.
Although not noticeable when the incoming data is clean, the peaks and valleys detected are not exactly at the position of the actual peaks/valleys. i.e. there is an "accuracy" problem. See the attached screenshot, where the peaks/valleys are highlighted, and are obviously not aligned with the incoming data (in red).
How does the native Peak Detector actually find these peaks/valleys, and how can I avoid the error?
Thanks!
03-20-2012 07:34 AM
Based on what you have posted, the peak/valley detector is working correctly. You have a noisy signal, so the "peak" location will not necessarily be at the highest or lowest point of your data. The algorithm essentially does a least squares fit to a parabola around each peak/valley, then returns the peak/valley of the parabola.
If you want better location values, increase the width input to the peak/valley finder. This may cause minor height issues, since a sine wave is not a parabola. Alternately, since you know your input is a sine wave, you can do your own least squares fit to a sine using more points at each peak/valley, or, better yet, fit the entire signal.
Ultimately, though, if you want better analysis, you need to reduce the noise on the input signal. You can do this by prefiltering it (watch out for phase shifts), but it would be better to reduce the noise in your measurement system.
03-20-2012 08:39 AM
Thanks for the reply.
Trouble is the noise in my signal may be mechanical noise, and I want to detect the peaks of my noisy data.
Is there a peak detector that fits the incoming data with, say, a spline -- such that the "noisy peaks" are accounted for and hence detected?
03-21-2012 07:46 AM
Your current implementation is already working well. The major discrepancy between your data and the peak locations appears to be noise, not signal. If you want to determine the peak/valley values of signal + noise, you have a plethora of options (although I must admit I think this is probably a bad idea - you should probably be looking for peaks in the signal, not signal+noise).
All of these basically do the same thing. They filter the data to help eliminate noise issues, find nominal values for the peaks, then search the original data for the actual peak/valley.