10-12-2015 10:26 AM
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.
Sample code also attached.
Thanks for help 🙂
10-12-2015 03:00 PM
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.
10-12-2015 03:32 PM
@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.
10-12-2015 04:56 PM
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?
10-12-2015 07:53 PM
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
10-13-2015 02:33 AM - edited 10-13-2015 02:36 AM
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...
10-13-2015 02:54 AM
Thanks Henrik_Volkers
Using samples from previous data block will do the trick and i will have to delete points only at initialisation and at the end of aquisition.
I have another question, where doesthe coefficient scaling comes from?
10-13-2015 06:30 AM
pawhan11 wrote:
I have another question, where doesthe coefficient scaling comes from?
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.