From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Performing A Derivitave On Waveform Using Savitzky-Golay Filter To Aquire Velocity Data From Laser Displacement Sensor

Hello,

I am using a position laser to aquire position data of a free falling object, and have also been able to aquire a velocity curve using the basic derivite function, however there is a significant amount of noise on the velocity curve generated when the sample rate is set higher(i.e 10KHZ) as shown below. The laser outputs a +-10V analog signal. I have the program set to auto trigger right before Impact. An offset and multipler is calculated based on the displactment of impact, and the upper and lower bounds.

Position and Velocity Data.PNG

 

To filter out the noise I found some information on the Savitzky-Golay Filter but I am having some trouble implementing it and was wondering if anyone could help. The velocity cure above was not recording with the attached VI that includes the filter.

 

Best,

Dave

0 Kudos
Message 1 of 10
(3,610 Views)

What values are you using for the SG filter settings? Can you show a screenshot of how it looks when you run it with your code and real data?

 

Note that if you use the FIR Filter VI to apply the coefficients, rather than the dot-product approach shown in the help for the Filter Coefficients VI, then you need to reverse the filter coefficients array or flip the sign of the resulting derivative calculation.

0 Kudos
Message 2 of 10
(3,581 Views)

Interface.PNG

With the code I am using now, I am not showing the filtered or unfiltered result of the derivative on the second waveform graph.

 

 

0 Kudos
Message 3 of 10
(3,563 Views)

Again, what settings are you using for the SG Filter? How many side points, what order etc? You have those values all set to 0 in your VI, which will cause the filter not to do anything.

0 Kudos
Message 4 of 10
(3,551 Views)

I have been continously adjusting the settings, the latest I have tried are as follows:

Order:12

Sidepoints:19

diff:1

0 Kudos
Message 5 of 10
(3,536 Views)

Have you probed the output of both the Coefficients VI, and the results of the Filter VI, to check that you're getting data? You should be able to track down, using probes or execution highlighting, exactly where your data disappears. Or, if you wire some real data, in the form of a constant, in place of the DAQ inputs, and then upload that VI, it will be easy for someone on the forum to look at it

0 Kudos
Message 6 of 10
(3,522 Views)

Considering the type of data you showed at the beginning of this thread, you should be able to use fairly low order for the S-G filter.  Higher orders do not necessarily work better and definitely take longer to calculate.

 

It is often useful to plot the intermediate results, such as the output of the filter. The human eye-brain combination can often identify things which are not easy to determine algorithmically.

 

Can you post some data?

 

Lynn

0 Kudos
Message 7 of 10
(3,517 Views)

Sorry for the delayed response. I have set the program to run continuously while the machine cycles.

This is the probe of the signal from the position sensor going into the waveform block un-modified.

Capture2.jpg

When probing the y input, I am not entirely sure what exactly I am looking at to be honest. The numbers do not resemble much of a pattern and seem to be quite sporadic.

Capture3.jpg

When probing the output of the waveform block I am also getting some output.

Capture5.jpgHowever when I run it with an analog trigger so that I only capture the data for approximately 2 inches, I am not getting any velocity data when exported to excel. The position data looks good. I can look into wiring in the position data but I am not sure how to go about doing so.

Capture6.jpg

0 Kudos
Message 8 of 10
(3,452 Views)

It's hard to follow what you're showing in the screenshots. It would be easier if you provide the data directly, and if you also save the values you're using (for the filter order and side points, etc) as the default values, then upload the data and that VI. You could provide the data by exporting the graph of the raw data to Excel, then saving as a text file. Then, it's easy to modify your code to read in that text file instead of doing the DAQmx operations, and we could see exactly what's happening.

0 Kudos
Message 9 of 10
(3,439 Views)

I was reading the wrong channel, I was able to isolate the issue by inputing the raw data as advised. Thanks a lot for help it was much appreciated!

0 Kudos
Message 10 of 10
(3,383 Views)