DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

I'd like to have the average of 2 y-values for 1 x-value

Hello,
 
I have acquired data from tests. The data is logged throughout a sweep. This means that for one X value I have got two Y values.
Does anybody know how to get the averages so I got one graph. The data is stored in one channel.
 
Thanks in advance.
 
Robert 
0 Kudos
Message 1 of 5
(3,832 Views)
Hello Robert,

I think I need some more information to be able to give you a good advice.
You are writing thet bith y values are located in the same channel and that the data was recorded during a sweep.
Does that mean that you have an x-channel which contains increasing values in the first half and decreasing values in the second - representing the up - and downsweep, respectively?

There is no function whis is doing exactly this averaging but if you can give some more details I can check if I could adjust one of my examples to make it fit your needs.

regards
Ingo Schumacher
Systems Engineering Manager CEERNational Instruments Germany
0 Kudos
Message 2 of 5
(3,816 Views)

Hello,

In the sweep the X-channel goes from 0 to 8 then to -8 and then back to 0 again with steps of 0.03, therefore one X-value has to Y-values

I would like to average these values so that would create one single line in the graph.

thanks

 

 

0 Kudos
Message 3 of 5
(3,803 Views)

Hi Robert,

The easiest way to do this would be to run the "Simple Classification" ANALYSIS function in the "Statistics" palette.  Click on the "Classes" button and select the following parameters:

Determination/mode = Begin/End/Width
Width = 0.03
Begin = -8
End = 8

This will automatically average any Y values which occur within the same 0.03 DeltaX section.

Regards,
Brad Turpin
DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 4 of 5
(3,798 Views)
Alternatively, you can use the following script.
Mind that the channels need to be sorted first - the script  expects indentical x values to be subsequent in the channel. You can use the sort channel values function to prepare your channels.

Option Explicit  'Forces the explicit declaration of all the variables in a script.

' Helper function: returns the average of all values inside an array
function arrayavg(a)
dim i
dim sum :  sum = 0
  for i = 1 to ubound(a)
    sum = sum + a(i)
  next
  arrayavg = sum/(i-1)
end function


' Channel averaging procedure: Browses the x-cvhannel for subsequent lines with the same value
'   these lines will be averaged to one value in the result channel.
Sub ChnAvg(cX, cY)

 
dim cNewX : cNewX = cno(chnalloc("Avg_X",cl(cX))(0)) 'Result X Channel
  dim cNewY : cNewY = cno(chnalloc("Avg_Y",cl(cY))(0)) 'Result Y Channel

  dim valX                                             'Current X value in loop
  redim valY(0)                                        'Array of Y values that referencing the same X value
  dim line : line = 1                                  'Line index for original channels
  dim newline : newLine = 0                            'Line index in result channels
  dim valYcount :  valYcount = 0                       'Number of Y values referencing to a specific X value

  dim stp                                              'stop flag to exit loop

  do                                                   'loop scanning the original channels from first to last row
    stp = false
    valX = chdx(line,cX)
    valYcount = 0
    do                                                 'loop searching for sumsequent lines in X channel that have the same value
      valYcount = valYcount+1
      redim Preserve valY(valYcount) : valY(valYcount) = chdx(line,cY)
      line = line +1
      if line > cl(cX) then stp = true else if (chdx(line,cX) <> valX) then stp = true
   
    loop until stp 
    newline = newLine +1
    chdx(newline,cNewX) = valX
    chdx(newline,cNewY) = arrayavg(valY) 
  loop until line > cl(Cx)
  cl(cNewX) = newline
  cl(cNewY) = newline
end sub

' Main program:
' Calling the averaging algorithm.
' Mind that the original channels need to be sorted first!
call ChnAvg(3,4)

The script uses DIAdem 10.1 syntax in some lines. To use it with prior versions, some adjustments need to be made.
Ingo Schumacher
Systems Engineering Manager CEERNational Instruments Germany
0 Kudos
Message 5 of 5
(3,777 Views)