LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Peak detect, fitting and average

Solved!
Go to solution

I am using a while loop in LabVIEW 8.5 to capture the signals continuously from a card, peak detector.VI is used to detect the peaks of the signals, then nonlinear curve fit.VI is used to fit the peaks, now signal capturing, peaks detecting, peaks fitting and display are all works continuously very well, but there are still some problems annoying me.
1. The signals captured is not very stable, so fitting results should be averaged for 100 times, so how can I averaged the fitting results on condition that signal capturing is not interrupted, that is the while loop is no stop, when the average is done this time, the average is reset so the next 100 fitting results can be average again?
2. There is another way, that is 100 fitting results is stored automatically to excel, then the results is averaged manually in excel, so how to store results like this: the first 100 fitting results are stored in a excel and the next 100 fitting results for another excel or they are stored in one excell but in different columns? Of course thses are done on condition that signal capturing is not interrupted.
3. There is a threshold input for peak detector.VI, but the signals captured is not very stable, so the number of peaks detected is not the same every time, such as this time the number of peaks is 40, the next will be 39, this will affect the fitting results slightly, so how to detect the same number of peaks every time, such as the number is 40 every time?

Any advice will be appreciated!

0 Kudos
Message 1 of 7
(6,314 Views)

It would be helpful if you posted your VI with some typical data saved as default.

 

So, guessing a bit:

 

1.  Something like a producer/consumer loop might be appropriate here.  Put the continuous acquisition in the producer loop and the analysis (peak detection, fitting, averaging, saving to files, ...) in the consumer loop.

 

1.1. It sounds as though your fitting process is not very robust in the presence of the "instability" of your signal.  What is the nature of the instability?  Is it random noise, frequency changes, amplitude changes, baseline drift, ...?  Would you be better off averaging the signals first and then fitting to the average?

 

2.  You can easily save your data to a file.  The Write to Spreadsheet FIle.vi will save to a tab delimited text file which can be read by nearly any spreadsheet program.  I think you may get better performance doing your signal analysis in LV.

 

3.  See 1.1.  The answer to this is very dependent upon the nature of your signal and the instability.  The Peak Detector.vi is fairly simple and is not intended to analyze complex signal.

 

Lynn 

0 Kudos
Message 2 of 7
(6,299 Views)

Thanks Lynn very much for helping me and I am sorry for not posting the VI last time. Now the VI is posted below, please see the accessory named Peak detect and fitting.

 

I think it is necessary to told how I did and what I want more clearly.

 

The exponential decay curves (Please see the figure named Waveform which is processed by WaveStar supplied by Tektornix and fitting by Origin) are captured by a Tektronix oscilloscope TDS 220, the data are transferred to PC via COM by LabVIEW 8.5, then in LabVIEW the peaks are detected and fitted. Though the signals have been averaged for 64 times by the oscilloscope, there is still a slight instability and I think this is not the real average, so I need to average the fitting result b1(b1 is only one that I need, I don’t care about a1 and c1) for 100 times again.

 

1. LabVIEW is new for me, the VI that I post is just modified on the basis of examples. I don’t even know what producer/consumer loop is before you said, now I am working on it.

 

2. The instability of signals are just a slight change of amplitude, frequency changes and baseline drift and so on are unchanged. I don’t know which is correct between fitting single signal first then average b1 and average signals first then fitting to get b1. It takes about 7 seconds to get a signal form the oscilloscope via COM. GPIB is faster, but it still takes about 2 seconds besides it will affect the signals when it “talk” to oscilloscope, so I choose COM. I think you are right, I need to average before fitting, but I don’t know how to do, how to add a loop for “read (single waveform).VI”, and how to add the waveforms and average? I hope you can help me for both the two process ways said above.

 

3. The Write to Spreadsheet File.vi store the 1D or 2D array to spreasheet, but what I want is the first 100 fitting results (that is 100 b1) are stored in column A, when it is reset the next 100 fitting results are stored in column B, ...... Then I can average the 100 data manually in excel.

 

4. The signals are intrinsic instability and the vertical resolution is 8 bits of the oscilloscope (we have not a better one), so it is a little low and can’t distinguish the small voltages, I think they are the sources of the voltage instability. So I think Peak Detector.vi is not perfect for me, is there a better VI?

 

Thanks again to Lynn.
Download All
0 Kudos
Message 3 of 7
(6,281 Views)

One subVI for reading the waveform from the scope was missing, but since I do not have a compatible scope, it does not matter.

 

I have an idea I would like to try.  Can you post some data?  What I would like is one dataset similar to the Waveform.jpg you posted.

 

One way to do this would be to put an array indicator on the Y output from the WDT Scale Delta t DBL.vi.  Run the program.  Then Make the value in the indicator default. Save the VI and post it.

 

Lynn 

0 Kudos
Message 4 of 7
(6,259 Views)

Thanks very much again to Lynn for giving me help.

I don’t know how to “put an array indicator on the Y output from the WDT Scale Delta t DBL.vi.” as you said, I am sorry for that, but I captured a waveform using WaveStar supplied by Tektornix, and export the dataset into excel. (See what I post this time named Waveform dataset.xls ), I think this is just what you need.  By the way, I think a Sine waveform which have an offset of half of  its amplitude multiples an exponential decay waveform, it will get a wave similar to the Waveform that I post, but I don’t know how to do this. And there is another questions after I have think about your advices “off averaging the signals first and then fitting to the average”, how to average the waveform for 100 times before fitting?
0 Kudos
Message 5 of 7
(6,245 Views)
Solution
Accepted by topic author fliablerain

Maybe the attached "test peak detect.vi"  can help you. "average signal.vi" is a sub VI to average input signal in an online way.

There are three methods to average the input signal: 

1. No Average.

2. Exponential  Average.

3. Linear Average. 

 

Your problem is when the input signal is corrupted by some noise, and you want to average the input signal before peak detection. I use white noise to simulate the noisy environment. 

By default, average mode is "Linear", and the number of averages is 50. The larger the number of averages, the better of the result, but the longer the update time. 

Swith average mode between "Linear" and "No Average" to compare the difference before average and after average.

 

Exponential average is not suitable in your case. 

 

Let me know whether this works for you. 

Message 6 of 7
(6,200 Views)

Here is the modified peak detector I mentioned in an earlier post.  It autoindexes through the Y array looking for points where the current value is less than all of the 4 previous values and declares that the value preceding the current one was a peak.  It then extracts the X and Y values at the peaks and feed them to the standard Exponential Fit.vi.  The amplitude and damping values from the fitting routine are used to calculate a fitted curve.

 

I removed all of the DAQ stuff and read the file once.  The data from the file was displayed in an indicator called "all rows."  I made the current value of "all rows" default, changed it to a control and removed the file reading VI.  Then I proceeded to look at the data.

 

There are notes in the VI explaining some of the non-obvious features.  For example the little glitch at the beginning of the dataset is detected as two peaks.  So I inserted an Array Subset function starting with index 2 to remove those.  Similarly, the algorithm does not work well when the amplitude gets quite small.  With this data it finds spurious peaks beyond time = 150, so I manually excluded that data also.

 

Lynn 

Message 7 of 7
(6,176 Views)