DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

linear regression

Hi,
 
I would like to know how I could do the following linear regression calculation.  I have two data channels, the first one corresponding to time information and the second one about aceleration. I must do linear regression with this acceleration data each second, but taking into account that the time channel has 10585 points for example for 44.1 seconds, corresponding to a 240msec sampling frecuency. I suppose that I must use the ChnRegrXYCalc function but I would like to know what the parameters should be.
 
REgards
 
Koniker.
0 Kudos
Message 1 of 9
(5,526 Views)
Hello Koniker,

if I get you right, you want to have a result channel containing 45 values, one for each second (starting with second 0). You can do this regression function but it requires one preparation. Since we only can work with integer intervals you would have to shorten your source channels and cut off the 0.1 seconds in the end.

If you would like to do this with a script, use the find function to analyse the timechannel and find the row where the value is bigger than 44.
Then adjust the channel length of the time and data channel.
Calculate the regression, using the value 45 for XNo and 44 for XDiv.

regards
Ingo Schumacher
Systems Engineering Manager CEERNational Instruments Germany
0 Kudos
Message 2 of 9
(5,514 Views)
Dear Ingo,
 
I am not sure about your answer. Well, I need an script as a solution. Imagine, the time data is collected in a channel, DatCha_1. There are 1000 points corresponding to 10 seconds. I have the corresponding aceleration data, in Dat_Cha_2, that is, 1000 acceleration points. So, I need to calculate the linear regression with this acceleration data each second, that is, I must obtain the a, b data of a y=a+bx  corresponding to each 100 values of the acceleration data, so 10 a values and 10 b values. I must divide the original acceleration data into 10 interval and obtain the linear regresion of each of this intervals.
 
What should be the script for this action? You mention to adjust the channel length of the time and data channel, but I do not know what you mean. In fact the function is:
 
Call CHNREGRYCALC("Time","Acceleration","Time","Regress_Y","linear") '... X,Y,XCHNNO,E,REGRTYPE
 
Could I use a new time channel only with 10 values and the original aceleration with 1000 values?

So, please could you send me a little example of the script I would need to solve the problem?
 
Regards,
 
Koniker
0 Kudos
Message 3 of 9
(5,499 Views)
Hello Koniker,

I see, here I got you slightly wrong. So you dont need a regression curve that consists out of one point for every second. You need to do one separate calculation for every second. Unfortunately, the CHNREGRYCALC function does not accept start and and row as parameters, so what you would have to do is: copy the data corresponding to one second into temporary channels, calculate the the regression and save the a and b values in result channels. This has to be done separately for each second - so its most convenient to realize that with a script.

Regards
Ingo Schumacher
Systems Engineering Manager CEERNational Instruments Germany
0 Kudos
Message 4 of 9
(5,493 Views)

Dear Ingo,

I thought I had to divide the data into intervals, but I misunderstood you reply. And your are right, I need a script.

Could you please send me an example of how I could divide the data into intervals of 1 sec, copy in temporary channels, and do the regression?

Regards,

Koniker

0 Kudos
Message 5 of 9
(5,489 Views)
Hello Koniker,

Because of a bank holiday I won't be in the office tomorrow.
I'll create and post an example on monday.

Ingo Schumacher
Systems Engineering Manager CEERNational Instruments Germany
0 Kudos
Message 6 of 9
(5,472 Views)
Here comes the example I promised.

' Create some data

Call DATADELALL(1)                   
Call CHNLINGENIMP("GenImplicit",1001,1,0.01)
Cn(1)="Time"

Call FormulaCalc("ch(#)            :=  sin(ch(1)*10)*ch(1)")
Cn(2)="Data"


' Allocate temporary and result channels - if channels allready exist, delete them

if cno("Temp_x") > 0 then Chndel("Temp_x")
Call chnalloc("Temp_x",1024): Tx=cno("Temp_x")

if cno("Temp_y") > 0 then Chndel("Temp_y")
Call chnalloc("Temp_y",1024): Ty=cno("Temp_y")

if cno("Regression_Time") > 0 then Chndel("Regression_Time")
Call chnalloc("Regression_Time",1024): Rt=cno("Regression_Time")

if cno("RegrCoeffA") > 0 then Chndel("RegrCoeffA")
Call chnalloc("RegrCoeffA",1024): Rx=cno("RegrCoeffA")

if cno("RegrCoeffB") > 0 then Chndel("RegrCoeffB")
Call chnalloc("RegrCoeffB",1024): Ry=cno("RegrCoeffB")

 

first = 1                          ' first row of data to calculate
sec = trunc(cmin("Time"))+1        ' actual second to ccalculate
count = 1                          ' number of calculations (seconds)

do
  last = Find("ch(1)>="&str(sec))  ' last row of data to calculate
  if last <> 0 and last <> first then
    call datablcopy("1,2",first,last-first,str(Tx)&","&str(Ty),1) 'copy to temporary channels
    Call CHNREGRXYCALC(Tx,Ty,Tx,Ty,"linear","Partition complete area",2,1) 'calculate regression
    chd(count,Rt)=sec - 0.5        ' store regression results in result channels
    chd(count,Rx)=RegrCoeffA 
    chd(count,Ry)=RegrCoeffB
    count = count+1
    first=last                     ' prepare search for next interval
  end if
  sec=sec+1
loop until last = 0

call Chndel("Temp_x")               'delete temporary channels
call Chndel("Temp_y")
Ingo Schumacher
Systems Engineering Manager CEERNational Instruments Germany
0 Kudos
Message 7 of 9
(5,449 Views)

Dear Ingo,

Thanks very much for your help.

Only one note. The "CHNLINGENIMP" function is not recognized by Diadem 8.1 that I have to use, so I could not manage to run your example directly, but I will find a solution.

Regards,

Koniker

0 Kudos
Message 8 of 9
(5,438 Views)
Hello Koniker,

but that does not matter, its just a command for generating a channel, on DIAdem 8.1 you can use this line instead:
Call CHNLINGEN("gen_X_Kanal",1,10,1001)
Ist working much in the same way.
Regards
Ingo Schumacher
Systems Engineering Manager CEERNational Instruments Germany
0 Kudos
Message 9 of 9
(5,434 Views)