**Nathan Ryder**

How and where is this array getting populated?.....How is the data that is getting gathered from said test handled?

Is there a way to find the Minimum and Maximum values in an array without calling each indexed array value 1 at a time into a memory register?

I have a procedure that tests response and will have more than 200 tests points that I need to find the min/max values. I would like to use an array but having to call each point back into a register seems counter productive. A function such as "myArray.max()" used in vb.net would be most helpful.

Here is an example of the code.

1.007 MATH Size = 41

1.008 LIB ARRAY NEW @FreqResp1V[Size];

1.011 MATH @Freq = "10 Hz"

1.012 MATH @Level = "1 V"

1.014 MATH @Index = 0

1.015 CALL Sub Modulation Generator Freq Resp Test - N5531S

11.005 VISA *RST;*CLS;*WAI;*OPC? [I!]

11.006 VISA OUTP1:STAT OFF;*WAI;*OPC? [I!]

11.007 VISA SOUR2:FREQ:CW [V FreqHz]Hz;*WAI;*OPC? [I!]

11.008 VISA OUTP2:VOLT [V Amp]V;*WAI;*OPC? [I!]

11.009 VISA OUTP2:STAT OFF;*WAI;*OPC? [I!]

11.010 SCPI [@PSA]SYST:PRES;*WAI;*OPC? [I!]

11.011 SCPI [@PSA]ROSC:SOUR EXT;*WAI;*OPC? [I!]

11.012 SCPI [@PSA]ROSC:OUTP ON;*WAI;*OPC? [I!]

11.013 SCPI [@PSA]INST MRECEIVE;*WAI;*OPC? [I!]

11.014 SCPI [@PSA]CONF:AUDL;*WAI;*OPC? [I!]

11.015 TSET TDESC = [V @Freq] @ [V @Level]

11.016 SCPI [@PSA]INIT:AUDL;*WAI;*OPC? [I!]

11.017 TARGET -m

11.018 SCPI [@PSA]MEAS:AUDL? [I$]

11.019 MATH MEM = FLD(MEM2,1,",")

11.020 MATH MEM1 = Amp

11.021 LIB @FreqResp1V[@Index] = MEM;

11.022 MEMCX V TOL

Later in the procedure I will need to pull the Minimum and Maximum values from the array and take the difference as the Peak-to-Peak frequency response error. I could use excel, or M[Set]/M[Get], but something like

MATH @MaxVal = Max(@FreqResp1V)

would be much better and easier to follow, but this doesn't work and from what can tell the LIB FSC doesn't have a Min/Max functionality.

Could you post up what gets put into MEM2 in this line?

11.018 SCPI [@PSA]MEAS:AUDL? [I$]

I'm still unsure how you are populating the array.....Without knowing what data gets sent back via the SCPI commands.

There are 2 subprocedures, a setup sub and a test sub. An amplitude of approximately 0.707 Vrms gets transferred to the array from MEM2. The subprocedure knows which index to place the value because of @Index variable in the setup subprocedure. The test subprocedure has about 40 lines or so and the setup sub has approximately 350 lines. Once the array has been filled the test record will have about 120 tests but the data is still needed to find the Min/Max values for peak to peak response. This is the portion i'm trying to simplify.

So it would be...

Some code = max array value.

Some code = min array value.

math mem = some math

memcx dB TOL

Yeah I'd say dumping those values to excel then using that find your number would prob be the best way, Unless you dumped them into registers via the MATH MSET FSC.

Do you need to store the entire array of readings or are you just trying to determine the Peak-to-Peak response? If it's the latter, a simplified approach would be to bypass the use of arrays and just use variables to update the min and max values as the procedure runs. Just initialize them to extreme values in the beginning, outside of any test loop code; use values like Min = 99999 and Max = -99999. As the procedure runs and collects data, you can then use the MATH FSC's MIN2() and MAX2() functions to update the variables with real measurements:

MATH MinVal = MIN2(MinVal, MEM)

MATH MaxVal = MAX2(MaxVal, MEM)

-Chad

Oh thats clever....Well done.

Thanks, Nathan! I hope this tip helps.

Good thought Chad, filtering the data as its gathered.

We have several procedures that use moving block averages, and wait until std deviation of an array is below a certain level before continuing.. (This is for temperature and humidity calibration).

I use a sub procedure to handle the array (stored as csv in @sample)

=============================================================================

INSTRUMENT: Find Standard Deviation, Min, Max, Mean of CSV (v1.1)

DATE: 2013-04-03 15:01:08

AUTHOR: J Steeds

REVISION: 1.1

ADJUSTMENT THRESHOLD: 70%

NUMBER OF TESTS: 1

NUMBER OF LINES: 64

=============================================================================

; Find Standard Deviation, Min, Max, Mean of CSV (v1.0)

; - Initial issue

; Find Standard Deviation, Min, Max, Mean of CSV (v1.1)

; - Can cope with end of string being ","

STEP FSC RANGE NOMINAL TOLERANCE MOD1 MOD2 3 4 CON

1.001 IF not(isvar( "@sample" ))

1.002 DISP You have not passed this procedure a CSV string

1.003 END

1.004 ENDIF

; strip spaces from beginning and end

1.005 MATH @sample = strip( @sample )

1.006 IF zcmpi(sub(@sample, len(@sample), 1), ",") == 1

; End of string is comma which needs to be stripped off.

1.007 MATH @sample = sub(@sample, 1, len(@sample) - 1)

1.008 ENDIF

1.009 MATH sample_size = findi(@sample, ",", 0) + 1

; Find Mean, Max, and Min

1.010 MATH step = 1

1.011 DO

1.012 MATH value = fld(@sample, step, ",")

1.013 IF step == 1

1.014 MATH sum = value ; min = value ; max = value

1.015 ELSE

1.016 MATH sum = sum + value

1.017 IF value > max

1.018 MATH max = value

1.019 ENDIF

1.020 IF value < min

1.021 MATH min = value

1.022 ENDIF

1.023 ENDIF

1.024 MATH step = step + 1

1.025 UNTIL step > sample_size

1.026 MATH @mean = sum / sample_size

1.027 MATH @min = min

1.028 MATH @max = max

1.029 MATH @sum = sum

; Find Standard deviation

1.030 MATH step = 1 ; numerator = 0

1.031 DO

1.032 MATH value = fld(@sample, step, ",")

1.033 MATH numerator = numerator + (value - @mean)^2

1.034 MATH step = step + 1

1.035 UNTIL step > sample_size

1.036 MATH @std_dev = sqrt( numerator / (sample_size - 1))

1.037 END

Please sign in to leave a comment.

## 9 comments