LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Derivative problem

Solved!
Go to solution

Hello, i am getting data from excel file into array, then i am using 'sim arbitrary signal' block to set a dt which i need and to plot signal(it is voltage signal). Then i need to get a 1st derivative of this signal. and there i am getting problems cause after using derivative from (time domain sig pallete) my derivative doesnt look proper. Is there anyone who could help me? U can see in attachments some piece of my VI, Graph of Voltage Signal and Graph of Derivative of Voltage Signal

Download All
0 Kudos
Message 1 of 25
(6,193 Views)

Are you sure your dt is correct?  Looking at the image vol.png I would guess that the dt is closer to 100 us than 4 us.  That will make a big difference in the derivative.

 

Please post your VI (rather than an image of part of the block diagram) and the data file.

 

Lynn

0 Kudos
Message 2 of 25
(6,179 Views)

I am 100% sure that my dt is 0,000004s

 

I ve attached my project, excelorto867 is main file, inside is also a setting file (settings.png)

0 Kudos
Message 3 of 25
(6,171 Views)

The problem is that your data is rather noisy and the standard differentiation techniques accentuate the noise.  Another factor is the decreasing dt at the beginning. This creates overlapping plots.

 

I tried the Savitsky-Golay smoothing and differentiation method and can definitely see the derivative.

 

Derivative.png

 

This is for the portion after the time column reaches zero and starts increasing. The setting was for 240 side points and 3rd order polynomial for the Savitsky-Golay differentiatior. The blank spaces at the ends are due to the smoothing process which cannot cleanly handle the ends of the data array.  The image below shows the same calculation with 50 sidepoints of smoothing.

 

50 Sidepoints.png

 

You can see the sinusoidal signal in there, just barely, but the extra smoothing above helps.  Note that ti takes much longer to run with more sidepoints.

 

I do not have the Excel VIs so I converted your file to a tab-delimited text file then read it once with Read from Spreadsheet File.vi. Then I created a constant from the all rows indicator and used that as my data source.

 

Lynn

0 Kudos
Message 4 of 25
(6,152 Views)

Wow, thx, u ve done a big thing. It is very helpful to me. Can u look at my attachment, how should i connect it to my VI correctly? Some kind of error is occuring

0 Kudos
Message 5 of 25
(6,141 Views)

Error -5111 is one I defined for the Differentiator and Smoother VI. The second line of the error message is the clue to the problem. L <= 2k + 1. L repesents the length of the input array. K is the number of side points. It appears that the input array is too small for the number of side points you have selected.

 

Note the constant 1709 connected to the Array Subset functions. That is based on the location of the minimum in the first column.  If you are using different data, you will need to change that or remove it for data with monotonic time values.

 

There are some things about your code I do not understand. You have a 2D array coming from the spreadsheet. You connect it to Index Array with a control wired to both Column inputs and nothing wired to the row inputs. This gives you two copies of the selected column which you then combine into a 2D array.

In my code the 2D array contains the three columns of data from the spreadsheet file which appear to be time, voltage, and current. What you have appears to generate two columns of voltage data. You should still be able to get the derivative although the graphs will not make any sense because the time data is missing.

 

Lynn

0 Kudos
Message 6 of 25
(6,130 Views)

I wish to thank you again for your invaluable support. 1st thing,  u are right that this thing to control before building an array has no sence(i am a beginner). What does excactly mean constant 1709? Ive noticed that it looks rather more like 'how many samples do u want to plot on your graph'. If i am setting 10 i see 10 samples at my plot, if i choose 1000 i see 1000 samples. 

Is it possible that u could help me to consider why not the full signal is plotting, u said that something is cutting end of the plot(array). In my opinion it is rather like, the start is cutted off and the plot is moved to the left side. Cant figure it out

0 Kudos
Message 7 of 25
(6,106 Views)

I figure it out, but i have another problem, as u can see i obtained Voltage signal and its Derivative without any cuts. But now i need to do an integral of derivative and i am getting empty array after integration. I think the problem can be first few values after derivating which are becoming NaN. Can i change that NaN values to 0?? Or what could be a problem why i am getting empty values(array,graph) after integration.

voltandder.pngempty.pngprob.pngempty.png

0 Kudos
Message 8 of 25
(6,041 Views)

menomena,

 

It is better to keep the discussion here rather than in PMs.  That way others who are following the thread or may find it in the future can benefit.

 

In the PM you asked: "U suggested and sent me a VI with Savitzky-Golay filter. I have a question to u. Why, when i am setting "side points"(24 are default, but i am setting 240 for better calculation) (to obtain derivative), the algorithm cuts on the plot first and last 24 samples(from array), or 240 samples(it obviousely depends on how many 'side points' i set. Is it possible to get a plot without any cuts?"

 

Please look at the detailed help for the Savitsky-Golay Filter Coefficients VI. It describes how the process works and how to adapt it to work on th epoints near the ends of the data set. The application I had when I developed the VI I posted did not need the end points so I created this simplified version.

 

The NaN (Not a Number) values in the Differentiator VI output are causing the problem with the Integral x(t).vi. Many VI will return NaN for the entire output if any input value is NaN because there is no way for the VI to determine an "appropriate" output for that input. The NaN values occur at the begining and ending "side points" of the output array. You can use Array Subset to extract the portion with valid data to integrate. The Waveform graph on the right is the integral produced by the code shown.

 

Lynn

 

Array Subset.png

 

Integral.png

Message 9 of 25
(6,023 Views)

I figured that invalid datas(NaN's) are the problem, and i used "subset array", it works(it was before what u've replied, i mean it is a solution). My another, last question is... is there any possibility that savitzky-golay VI(algorithm, dont know how to describe it) wont cut any samples(making begining and end samples as NaN's).

0 Kudos
Message 10 of 25
(6,012 Views)