- 易迪拓培训,专注于微波、射频、天线设计工程师的培养
峰值搜索
概述
在Excel VBA中的样本程序
在HT Basic中的样本程序
概述
这个样本程序说明如何使用标记搜索功能和分析命令搜索峰值。
这个程序按两个步骤运行:首先,它使用标记搜索搜索到最大正峰值,然后,它使用分析命令搜索所有正峰值,并显示搜索结果。
参见这个程序的搜索与指定标准相匹配的点。
在Excel VBA中的样本程序
Sub PeakSearch_Click()
Dim defrm As Long
Dim vi As Long
Const TimeOutTime = 20000
'
Dim Buff As String, Img As String, Err_msg As String
Dim Excursion As String, Freq As String * 20, Resp As Variant, PeakPoint As Variant
Dim Poin As String * 5, Result As String * 1000, errmsg As String * 20
Excursion = "0.5"
' Open Analyzer
Call viOpenDefaultRM(defrm)
Call viOpen(defrm, "GPIB0::17::INSTR", 0, 0, vi)
Call viSetAttribute(vi, VI_ATTR_TMO_VALUE, TimeOutTime)
Call viVPrintf(vi, "*CLS" & vbLf, 0)
'
' Setup Analyzer
Call viVPrintf(vi, ":SENS1:FREQ:CENT 947.5E6" & vbLf, 0)
Call viVPrintf(vi, ":SENS1:FREQ:SPAN 200E6" & vbLf, 0)
Call viVPrintf(vi, ":CALC1:PAR1:DEF S11" & vbLf, 0)
Call viVPrintf(vi, ":DISP:WIND1:TRAC1:Y:AUTO" & vbLf, 0)
'
Call viVPrintf(vi, ":CALC1:PAR1:SEL" & vbLf, 0)
Call viVPrintf(vi, ":CALC1:MARK1:FUNC:TYPE PEAK" & vbLf, 0)
Call viVPrintf(vi, ":CALC1:MARK1:FUNC:PEXC " & Excursion & vbLf, 0)
Call viVPrintf(vi, ":CALC1:MARK1:FUNC:PPOL POS" & vbLf, 0)
Call viVPrintf(vi, ":CALC1:MARK1:FUNC:EXEC" & vbLf, 0)
Call ErrorCheck(vi)
Call viVPrintf(vi, ":CALC1:MARK1:X?" & vbLf, 0)
Call viVScanf(vi, "%t", Freq)
'
Call viVPrintf(vi, ":CALC1:MARK1:Y?" & vbLf, 0)
Call viVScanf(vi, "%t", Result)
'
Resp = Split(Result, ",")
Cells(5, 5).Value = Val(Freq)
Cells(5, 6).Value = Val(Resp(0))
'
Call viVPrintf(vi, ":CALC1:FUNC:DOM OFF" & vbLf, 0)
Call viVPrintf(vi, ":CALC1:FUNC:TYPE APE" & vbLf, 0)
Call viVPrintf(vi, ":CALC1:FUNC:PEXC " & Excursion & vbLf, 0)
Call viVPrintf(vi, ":CALC1:FUNC:PPOL NEG" & vbLf, 0)
Call viVPrintf(vi, ":CALC1:FUNC:EXEC" & vbLf, 0)
Call ErrorCheck(vi)
'
Call viVPrintf(vi, ":CALC1:FUNC:POIN?" & vbLf, 0)
Call viVScanf(vi, "%t", Poin)
Call viVPrintf(vi, ":CALC1:FUNC:DATA?" & vbLf, 0)
Call viVScanf(vi, "%t", Result)
PeakPoint = Split(Result, ",")
'
j = 1
For i = 1 To Val(Poin) / 2
Cells(6 + i, 5).Value = Val(PeakPoint(j))
Cells(6 + i, 6).Value = Val(PeakPoint(j + 1))
j = j + 2
Next i
'
Call viClose(vi)
Call viClose(defrm)
'
End Sub
Sub ErrorCheck(vi)
Dim err As String * 50, ErrNo As Variant, Response As VbMsgBoxResult
Call viVQueryf(vi, ":SYST:ERR?" & vbLf, "%t", err)
ErrNo = Split(err, ",")
If Val(ErrNo(0)) <> 0 Then
Response = MsgBox(CStr(ErrNo(1)), vbOKOnly)
End If
End Sub
在HT Basic中的样本程序(search.htb)
10 DIM Buff$[9],Img$[50],Err_msg$[100]
20 REAL Excursion,Freq,Resp,Result(1:100,1:2)
30 INTEGER Poin,Err_no
40 !
50 ASSIGN @Agte507x TO 717
60 Excursion=.5
70 !
80 OUTPUT @Agte507x;"*ESE 60"
90 OUTPUT @Agte507x;"*SRE 32"
100 OUTPUT @Agte507x;"*CLS"
110 OUTPUT @Agte507x;"*OPC?"
120 ENTER @Agte507x;Buff$
130 ON INTR 7 GOTO Err
140 ENABLE INTR 7;2
150 !
160 PRINT "Maximum Peak Search using Marker 1"
170 !
180 OUTPUT @Agte507x;":CALC1:PAR1:SEL"
190 OUTPUT @Agte507x;":CALC1:MARK1:FUNC:TYPE PEAK"
200 OUTPUT @Agte507x;":CALC1:MARK1:FUNC:PEXC ";Excursion
210 OUTPUT @Agte507x;":CALC1:MARK1:FUNC:PPOL POS"
220 OUTPUT @Agte507x;":CALC1:MARK1:FUNC:EXEC"
230 OUTPUT @Agte507x;":CALC1:MARK1:X?"
240 ENTER @Agte507x;Freq
250 OUTPUT @Agte507x;":CALC1:MARK1:Y?"
260 ENTER @Agte507x;Resp
270 Img$="8A,MD.4DE,2X,MD.6DE"
280 PRINT " Frequency Response"
290 PRINT USING Img$;"Peak: ",Freq,Resp
300 !
310 PRINT "All Peaks Search using Command"
320 !
330 OUTPUT @Agte507x;":CALC1:FUNC:DOM OFF"
340 OUTPUT @Agte507x;":CALC1:FUNC:TYPE APE"
350 OUTPUT @Agte507x;":CALC1:FUNC:PEXC ";Excursion
360 OUTPUT @Agte507x;":CALC1:FUNC:PPOL POS"
370 OUTPUT @Agte507x;":CALC1:FUNC:EXEC"
380 OUTPUT @Agte507x;":CALC1:FUNC:POIN?"
390 ENTER @Agte507x;Poin
400 REDIM Result(1:Poin,1:2)
410 OUTPUT @Agte507x;":CALC1:FUNC:DATA?"
420 ENTER @Agte507x;Result(*)
430 Img$="4A,2D,2A,MD.4DE,2X,MD.6DE"
440 PRINT " Frequency Response"
450 FOR I=1 TO Poin
460 PRINT USING Img$;"Peak",I,": ",Result(I,2),Result(I,1)
470 NEXT I
480 GOTO No_err
490 Err: OFF INTR 7
500 OUTPUT @Agte507x;";:SYST:ERR?"
510 ENTER @Agte507x;Err_no,Err_msg$
520 PRINT "Error occurred!!"
530 PRINT " No:";Err_no,"Description: "&Err_msg$
540 No_err: OFF INTR 7
550 END