LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Derivative problem

Solved!
Go to solution

I have not tried it but the detailed help file for the Savitsky-Golay FIlter Coefficients VI shows a block diagram where it processes the first and last k points separately and then uses Build Array to recombine everything for smoothing. It does not say whether that will work for differentiation.

 

My VI uses mostly the Differentiation code with the central part of the smoothing code.

 

Lynn

0 Kudos
Message 11 of 25
(3,959 Views)

Maybe i didnt understand your reply, but is there any possibility to get a plot without any cuts. I mean, when i choose some number of side points, S-G VI cuts that number of samples from the begining and the end . I am too newbie to figure it out

0 Kudos
Message 12 of 25
(3,956 Views)

The basic concept of S-G is that it fits a polynomial to each central point in the data set and k side points on either side of that point. It then calculates the smoothed and derivative values from the polynomial.  So, any attempt to calculate derivatives of the first or last k points in the data set need to use some other approximation. The estimate of the derivative will be worse at the edges simply because less data is used.

 

Because the values of the derivative at the beginning and end of the dataset would be less accurate, perhaps you could think about other options. Right now you are losing 480 out of 10000 points. If you acquire 10480 points you could get good derivative calculations on 10000 points. Or acquire data continuously and process it in overlapping segments so that the endpoints can be discarded.

 

I looked at the section in Numerical Recipes on derivatives. All the techniques discussed require processing of multiple points of the data.

 

Think about it this way: When you have a finite data set, it probably represents a segment of the data measured from some continuous or ongoing process. The act of extracting a segment of the continuous data is the same as multiplying the continuous signal by a square pulse. The derivative of the product of two functions includes information about both functions. The derivative of the square pulse is two impulses, one at each edge. You can see that the derivatives of a "chopped off" real data set will have some hard to define regions at the edges.

 

What will you be doing with the derivatives after you calculate them? Do you have a mathematical model of the process which generates the data?

 

Lynn

Message 13 of 25
(3,949 Views)

Johnsold,

 

I had a look at your vis and one question came up:

Where is dt handled?  Different samplerates should give different amplitudes in the derivate. 

 

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 14 of 25
(3,935 Views)

Thx for comprehensive reply. I have no mathematical formula to make my signal more sampled. Next time i will try to aquire more samples then, for now, i can copy from my data(excel) additional 240 samples to the beggining and end(should do not like this but the difference between real measurement and copied datas will probably be like 1:10000). 

 

I am trying to obtain resistive current by combining some formulas.  To do it, i need to mix some integrals and that 1 unlucky:) derivativeof Voltage and Current signal. My another, hope last problem is to make  FFT of resistive current, cant handle with that. I ve used some FFT VIs but everytime plot is empty.

 

Ive attached my project and settings inside. Remember to set sidepoints to 240!.

 

I would appreciate if someone of u guys could take a look on it.

0 Kudos
Message 15 of 25
(3,925 Views)
Solution
Accepted by menomena

Henrik,

 

You are right. The number dialed is imaginary.  The S-G filter algorithm is based on the number of sample points and does not take into account the physical meaning of the sample interval. Proper amplitude scaling of the derivative needs to account for the magnitude of dt. The shape should be correct. Thank you for pointing this out.

 

menomena,

 

The reason you get no output from the FFT is that you have NaN values at the end of the Resistive Current array from indexes 9760 to 10239.  When you do the Array Subset you need to remove side points elements from each end, not just the beginning. In the VI I posted you can see that I used Side Points as the index value and Length of the Array - 2*Side Points as the length of the subset. When I do that for your VI, I get no NaN values and can do the FFT.

 

Lynn

0 Kudos
Message 16 of 25
(3,917 Views)

Thank you so much, FFT works

0 Kudos
Message 17 of 25
(3,910 Views)

Here is a SG diff that should scale correctly , keep in mind:

It will shorten the wfrm length one sidepoint length (to get a correct phase)

At the beginning you will have filter artifacts. To avoid them cut 4 times the sidepoint length

NOT FINALLY TESTED...

and to use it with continous wfrm blocks the recalculation of the filter values could be avoided 😉

 

SG-diff BD.png

test vi

test SG-diff.png

test SG-diff fp.png

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 ǝɥʇ'


Download All
Message 18 of 25
(3,896 Views)

Pay attention that in your vi you cut 4 times ORDER points instead of 4 times SIDEPOINTS points.

In any case, nice job!

Message 19 of 25
(3,434 Views)

Your rigth 🙂

the Q&D test routine used the order instead of sidepoints as noted

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 20 of 25
(3,427 Views)