Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Peak Detector for C# in Visual Studio 2008

Hi,

 

I have to detect the Peaks of a signal in a ScatterGraph. I have the signal created, in this case, the following signal:

 

 

double[] signal = new double[3200];
double[] x = new double[3200];
 
Random aleatorio = new Random();
 
for (int i=0; i< 3200; i++)
{
     signal[i] = 0.74 * aleatorio.Next(5);
     x[i] = i;
}
 
    
scatterPlot1.PlotXY(x,signal);
 

 

With this Example, I detect the Peaks with the following code:

 

PeakPolarity peakPolarity = PeakPolarity.Peaks;
PeakDetector pkd = new PeakDetector(0.5, 3, peakPolarity);           
pkd.Detect(this.signal, false, out this.amplitudesPeak, out this.locationsPeak, out secondDerivativesPeak);
 
scatterPlotPeaks.PlotXY(locationsPeak, amplitudesPeak);

 

 

Where this.signal is the previous signal which I have generated.

 

The problem is:  The Peaks which are plotting in the Graph don't coincide with the real peaks of this.signal.

 

¿Why??

 

Thanks,

0 Kudos
Message 1 of 3
(5,582 Views)

Hi,

 

Could you post the full project?

 

Thanks!

0 Kudos
Message 2 of 3
(5,524 Views)

Hi,

 

Just use "Reset" with the same parameters before any call to "Detect".

 

// loop
// {
pkd.Reset(
0.5, 3, peakPolarity);
pkd.Detect(this.signal, false, out this.amplitudesPeak, out this.locationsPeak, out secondDerivativesPeak);
scatterPlotPeaks.PlotXY(locationsPeak, amplitudesPeak);
// }

 

Regards

 

Iñaki Gauna

 

 

0 Kudos
Message 3 of 3
(4,467 Views)