LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Savitzky Golay derivative filter - missing points calculation

Hello,

 

I am using  Savitzky Golay filter to calculate 1st derivative. It works good for signals with some noise. But there is problem with calculating missing window samples at the beginning and at the end of my data.

I can't find any information in labview help or examples about how to use coefficients.

In matlab implementation of that filter takes care of endpoints but unfortunately calling functions from matlab is not an option.

 

Untitled.png

 

Sample code also attached.

Thanks for help 🙂

 

0 Kudos
Message 1 of 8
(6,069 Views)

The 'missing' points should match the number of sideoints 🙂 

Its all a question on what you want to have when you start and end, or , since you migth want to run in in a continous mode , how do YOU want the 'not defined' points to be treated?

The SG filter is a FIR filter and it's up to you to decide , like on any other digital filter structure.

 

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 2 of 8
(6,035 Views)

@pawhan11 wrote:

I can't find any information in labview help or examples about how to use coefficients.

 


The example that shouws how to do that is "Design and Apply Savitzky-Golay Filter".  You'll have to make use of "nth Derivative of Polynomial.vi" to convert it to calculate the first derivative.

 

0 Kudos
Message 3 of 8
(6,025 Views)

I am running this filter in continous mode and I want my derivative to have values for all samples.

 

I have found information that I should extend my data by adding side points at the beginning and at the end of my data in reverse order and filter them later but that doesn't work as expected.

Another approach says that I should extrapolate missing points but that.

 

Is there easier approach?

0 Kudos
Message 4 of 8
(6,012 Views)

You will never have derivative values for all the data points. You always lose the side points at the beginning and end.

 

If you are acquiring data continuously and reading in segments of n samples and you have k side points in the filter, then create a buffer with your data. Filter the first n points, getting derivatives for the n-2*k points in the center. Then grab a subset of length n starting at n-k and take the derivative of that subset. That will produce the derivative for data points n-k through 2*n-2*k. Repeat.  This is a sliding window process where you slide by an amount determined by the length of the data segment and the side points.  (Note the indexes might be +/-1 from the values listed. Please check.)  You may have a segment of a different length at the end.

 

Lynn

 

0 Kudos
Message 5 of 8
(5,998 Views)

Here I posted my SG derive vi that supports continous filtering and do the scaling of the coefficients. But keep in mind that you still have a group delay of $sidepoints$ samples.

And you migth add the feature NOT to calculate the coeffitients on every loop 😉

Since you do continous sampling, it's usually no problem to sample some more points before and after your signal of interest...

 

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


Message 6 of 8
(5,979 Views)

Thanks 

 

 

0 Kudos
Message 7 of 8
(5,971 Views)

pawhan11 wrote:

 


Math?   See help of SG coef vi and the fact that the sample rate also is important  (SG run with points and 'samplerate' 1) and  (later after testing 😉 ) that the sign needs to be negative on even derivatives...   (never went that much into the SG algorythm to decide whether it is a bug in the LabVIEW implementation/documentation....) however the factorial vi don't work with negative numbers, but the 'power of' vi do  that is needed anyway for the dt scaling;)

 

Test your SG derivate filter with analytical signals (example: sine of known amplitude ) where you exactly know the result.

 

ALWAYS read the documentation of the program parts you just use 😉  AND test it,  if you need to rely on the results.

 

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 8 of 8
(5,953 Views)