Jump to content

Linear regression function?


Evert

Recommended Posts

Hi All,

I'm new here so let me start with a short introduction. I work for a company doing applied research on renewable energy technologies, building small to pilot scale factories.  We've been using some outdated data acquisition systems that desperately needed to be upgraded. For a new project we've decided to try out the Unitronics PLC system with Unilogic programming, to see if that's suitable for our applications. First impressions are very good!

Now my question, in my process I have a weight cell, combined with converter to get 4-20 mA output signal. This signal is converted to the actual mass by linearize function. However I would also like to calculate the change in mass in time, to display the mass flow. In Excel I usually take the linear regression function, but after searching around I cant find an example how to program it in Unilogic. I'm not a math wizard, but the linear regression basically takes a specified number of measurements (mass, y-axis) for a specified number of times (x-axis) and then calculates the slope of the line (least squares method). So I need to collect say 10-20 measurements to calculate the slope, and then ideally each iteration have the first measurement out and a new one in...

Surely this must have been done before right? Is there someone here that can point me in the right direction? I hope I placed this in the right topic...

Regards,

Evert

 

 

  • Upvote 1
Link to comment
Share on other sites

20 hours ago, Dave said:

You could try using the DataSampling function, found in the Solution Explorer

Thank you for the reponse and your tip, the DataSampling is very useful for storing my data and creating graphs!

For the linear regression I think the data-table feature might be easier though? I haven't figured it out yet but if I can just have 10 or 20 rows filled with my measurement value, every 1 second, than I should be able to calculate flow quite easily. Still struggling with all the data-table though. 

 

edit: it seems that I can only use the data from the first or last row from the data table, that would not give the solution I'm looking for I think.

  • Upvote 1
Link to comment
Share on other sites

Unitronics PLCs has no embedded functions, like "regression function", etc.

Look at Helpdesk article:

Calculate Totalizing or Integral

https://support.unitronics.com/index.php?/selfhelp/view-article/calculate-totalizing-or-integral

In common, PLC scan time should be as small as possible.

Complex functions will take long time and enlarge scan time.

So if you decide to realize "regression function", you should take care to minimize disturbance to scan time.

B.R.

 

  • Thanks 2
Link to comment
Share on other sites

  • MVP 2023

Evert, I am not a Unistream user.  I only use Vision.  But from what you are saying, my approach must be easily achieved in Unilogic.

My understanding is that you basically need a FIFO list of data.   In Vision, I wouldn't be using a data table. It would be a simple matter of storing numbers into the first area of a vector of FIFO MIs, doing appropriate maths on that entire vector length  (perhaps using the Maths/Formula), getting the result you need, updating the MI vector by shifting all the data along the vector the single read amount (using the most convenient method, perhaps even using an "intermediary vector copy" which copies the entire vector to an area and then reads back just the required shorter one), doing the next read and then repeating the entire process.

The things you need to decide are the time interval between reads, and the sample size.  The two are obviously intertwined but are crucial to the accuracy of the result.  As Alex says, scan time should be as small as possible, but it needs to allow for all the needed operations.  Although I can't find them quickly, there have been numerous questions and answers on this sort of thing on the Vision forum.  Although it is not exactly what you want, a method of flow calculation that might be a basis for your ask might be this one:

https://forum.unitronics.com/topic/4599-totalizer-to-gpm/?do=findComment&comment=17077

I would suggest a read of the entire topic as well.

cheers, Aus

  • Thanks 1
Link to comment
Share on other sites

  • 9 months later...

Hi to everybody,

Regarding linear regression calculation the following website has C code for that purpose.

https://www.codesansar.com/numerical-methods/linear-regression-method-using-c-programming.htm

You may use the C programming function in Unistream and take advantage of the code to get the "a" and "b" coefficients.

😀

 

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...