DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

how can i resample a channel belonging to an other channel

I have two channels with values, one called moment and one called angle. Now I have to search in the moment channel the first value nearst 0.1Nm then I have to take one value before, the found value and one value after, make the arithmetic mean of this three and write it in a new channel called moment_short. I have also to take the arithmetic mean of the three angle values belonging to the moment values. This values I have to write in a channel called angle_short. This I have to do for moment values from 0Nm to 10Nm, down to -10Nm and back to 0Nm in 0.1Nm steps

 

The goal is, to have in the new channels always 401 values independent of the sample rate.

 

How can I realize this?

greez Siipo
0 Kudos
Message 1 of 7
(4,155 Views)
Hello Siipo,
Since this is not a standard function, you will need to create a VBS to do an analysis like that.
I recommend to use the chnfind function to find the rows of interest (eg. "In which row is my momentum channel 0.1?")
In the next step you can use the chd variable (or chdx, which is faster) to access individual cells in the data matrix.

A quickly created a little example to proove the concept. cX and cY are the source channels which need to be adjusted. The script does not solve your application completely. It is just to show you my approach and I hope it will give you an idea how to solve the problem.

Let me know if you need further explanation to understand the code.

Option Explicit 
dim x
dim rowLong : rowLong = 1
dim rowShort : rowShort = 1

dim cX : cX = 1
dim cY : cY = 2

dim cXs : cXs = cno(chnalloc(cn(cx)&"_short",401)(0))
dim cYs : cYs = cno(chnalloc(cn(cY)&"_short",401)(0))

for x = 0 to 10 Step 0.1
  rowLong = chnfind("Ch("&cX&")>="&str(x),rowLong)
  if rowLong > 1 then
    chdx(rowShort,cXs) = (chdx(rowLong-1,cX)+chdx(rowLong,cX)+chdx(rowLong+1,cX))/3
    chdx(rowShort,cYs) = (chdx(rowLong-1,cY)+chdx(rowLong,cY)+chdx(rowLong+1,cY))/3
    rowShort = rowShort+1
  end if
next

cl(cXs) = rowshort-1
cl(cYs) = rowshort-1

Ingo Schumacher
Systems Engineering Manager CEERNational Instruments Germany
0 Kudos
Message 2 of 7
(4,147 Views)
hi Ingo,

thanks to your code, i could solve my problem.

thanks and greez

Siipo
0 Kudos
Message 3 of 7
(4,141 Views)

 Hi

I tried on the base of your code some other mathematics. Now I have the problem, if I add the values together, then it works, if I subtract the values, it didn’t work. Why?

 

chdx(rowShort,cXs) = (chdx(rowLong,cY)+chdx(rowLong+1,cY))/(chdx(rowLong,cX)+ chdx(rowLong+1,cX))     -> works

 

chdx(rowShort,cXs) = (chdx(rowLong,cY)-chdx(rowLong+1,cY))/(chdx(rowLong,cX)- chdx(rowLong+1,cX))     -> didn’t work

 

0 Kudos
Message 4 of 7
(4,098 Views)
Hi Siipo,
Since I did not want to make the script too complicated I decided to make it not completely fault save. Depending on the data set, there could occure some errors when you try to access an index of a channel that does not exist. For instance, if the find command gives a hit in the last row of a channel, (rowLong+1) is not defined. Also, the script allocates the new channels with a length of 401 values (because you mentioned the number). If there are other datasets and the channels are expected to be longer, this could be reason to an error as well.

The mathematics you are using look all right, please give me some more information about why it is not working. Is there an error message? Are the results not what you expected? Is there additional information in the DIAdem log (at the bottom of the SCRIPT window)?

With a sample of your data, I could have a closer look on what is going wrong here. You can attatch it to the thread or, alternatively, send me a mail to: ingo (dot) schumacher (at) ni (dot) com.

Ingo Schumacher
Systems Engineering Manager CEERNational Instruments Germany
0 Kudos
Message 5 of 7
(4,095 Views)

Hi,

 

At the attached zip is the code and a dataset. When I start the script it works until the sub differenzieren2. Then there is an error message with the text “overflow” this message refers to the line in which I have the following code:

chdx(rowShort,cXs) = (chdx(rowLong,cY)-chdx(rowLong+1,cY))/(chdx(rowLong,cX)- chdx(rowLong+1,cX))     -> didn’t work

 At the bottom, i have no additional infos.


If I change - to + it works.

0 Kudos
Message 6 of 7
(4,086 Views)
Hello,

chdx(rowShort,cXs) = (chdx(rowLong,cY)-chdx(rowLong+1,cY))/(chdx(rowLong,cX)- chdx(rowLong+1,cX))
is producing a division by 0 error. Line 98 and 99 in channel 6 contain identical values.
That is why the error does not occure if you are adding the values.


Ingo Schumacher
Systems Engineering Manager CEERNational Instruments Germany
0 Kudos
Message 7 of 7
(4,078 Views)