01-17-2007 07:13 AM
01-19-2007 02:32 AM
01-19-2007 05:54 AM
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
01-19-2007 08:47 AM
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
01-22-2007 02:16 AM
Option Explicit 'Forces the explicit declaration of all the variables in a script.The script uses DIAdem 10.1 syntax in some lines. To use it with prior versions, some adjustments need to be made.
' 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)