LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Point by Point p-th order derivative using Savitzky Golay filter coefficients

I am trying to implement a Point by Point p-th order derivative using Savitzky Golay filter coefficients.  The  point by point available in LV doesn't use the Differential Filter coefficients.  I tried converting it so it could but it didn't differentiate for me, it just gave hte original signal (probably smoothed).  Refer to my attachment.  So I then took a look at another method partly documented in the NI help file.

 

In prior posts Damien (DFGray) has described the Savitzky Golay derivative filter as"essentially a convolution filter".    The latest LV help file example shows this by using the dot product to calculate the p'th order derivative using such a filter.  So my plan now is to convert that NI help example below (from here) into a point by point version (sorry no LV code existed that I could find, just a pic).  Before I try this out, will this work with just one shift register or do I need a shift register history that is 2k+1 deep ?

 

Savitzky Golay p-th order derivative filter.png

 

 

 

thanks

Peter
0 Kudos
Message 1 of 5
(4,691 Views)

You almost got it right.  You need to specify line 1 instead of line 0 (first derivative, not zeroth) when you get the subset of the derivative matrix.  There is also a minus one error somewhere, but I did not try to track that down, I just fixed it.  Attached is my fixed code and test.

Download All
Message 2 of 5
(4,679 Views)
Damien, thanks for such a quick response ! I will try this out in the office later today, unfortunately LabVIEW doesn't run on my Android HTC smartphone yet 😉

Regards
Peter.
Peter
0 Kudos
Message 3 of 5
(4,672 Views)

Hi Damien,

 

I tested this out and it works perfectly, thanks for finding the bug in my implementation.   I am using it to differentiate a volume signal to provide the resultant flow. (flow is the rate of change in volume w.r.t. time)

 

In order for it to be effective in my application which has some serious (unwanted) discontinuities in the volume, I am using a poly order of 5 and 100 side points.  Given my underlying sampling rate of 512Hz this introduces a delay of approximately 200ms (100 samples).

 

regards

Peter
0 Kudos
Message 4 of 5
(4,658 Views)

I replied a tad too soon.  I discovered that the amplitude output from the derivative had been scaled down by (100/2xPI) for some reason I don't understand,Smiley Indifferent so I updated both the test harness and the point by point vi and attached them.

 

I added a sine wave input for one test signal and my example volume input (without the glitches I'm trying to remove though) for another test signal.  Both derivative outputs show discontinuities at the input as expected,  additionally each are delayed by the number of Side Points (currently constants on the BD)

 

BTW, thanks for adding in the dx/dt text into the icon, I was going to but was too lazy !!

Peter
Download All
0 Kudos
Message 5 of 5
(4,656 Views)