官方淘宝店 易迪拓培训 旧站入口
首页 > 仿真设计 > 射频仿真设计学习 > 怎样在cst 中自定义个脉冲

怎样在cst 中自定义个脉冲

05-08
' userdefined excitation function
Option Explicit
Function ExcitationFunction(dtime As Double) As Double
'Assign the excitation signal value for the given time to the function name.
Static bFirst As Boolean
bFirst=True
Static timeval() As Double
Static Valval() As Double
Static Nt As Integer
Dim i As Integer
Dim TT As String,a As String
If dtime=0 Then
bFirst=False
'read file data
Open "E:\User\time.txt" For Input As 1 % 时间参数
Open "E:\User\amp.txt" For Input As 2 % 幅度参数
Input #1,TT
Nt=CInt(TT)
ReDim timeval(1 To Nt)
ReDim Valval(1 To Nt)
i=1
For i=1 To Nt
Input #1,TT
timeval(i)=CDbl(TT)
Input #2,a
Valval(i)=CDbl(a)
Next
Close #1
Close #2
End If
For i=1 To Nt
If Abs(dtime-timeval(i)*1e+9)<0.05 Then
ExcitationFunction=Valval(i)
Exit For
End If
Next
End Function
' -------------------------------------------------------------------------------------------------
' Main: This function serves as a main program for testing purposes. (runs and plots the function)
' You need to rename this function to "Main" for debugging the excitation function.
'
' Please adjust the time step width and the number of time steps accordingly.
'
' PLEASE NOTE that a userdefined excitation file (*.usf) must not contain a main program for
' proper execution by the framework. Therefore please ensure to rename this function
' to e.g. "Main2" before the Transient Solver is started
' -------------------------------------------------------------------------------------------------
Sub Main
Dim tmax As Double, ntstep As Long
' -------------- PLEASE ADJUST THE SETTINGS BELOW ----------------------
tmax = 50.0
ntstep = 502
' -------------- PLEASE ADJUST THE SETTINGS ABOVE ----------------------
Dim signal As Object, n As Long, tstep As Double
Set signal = Result1D("")
signal.Initialize ntstep
tstep = tmax / ntstep
For n=0 To ntstep-1
signal.SetXY(n, n * tstep, ExcitationFunction(n * tstep))
Next n
signal.Save GetProjectBaseName() + GetProjectBaseNameSeparator() + "excitation function.sig"
signal.AddToTree "Excitation Signals\Userdefined Functions\signal1_plot"
SelectTreeItem "Excitation Signals\Userdefined Functions\signal1_plot"
ResultTree.RefreshView
End Sub
但是就是运行不起。 哪位 帮我看看这个程序,

不太清楚这些

:qqw :15bb :qqr :qqm :qqw :14bb :qqx

好复杂,从来没有自定义过激励函数。

2008版可以读.txt文件, 第一栏是时间, 第二栏是幅度, 非常方便.

这个改进不错~~~

Function ExcitationFunction(dtime As Double) As Double
……
End Function
以上部分是在定义激励信号的函数
Sub Main
Dim tmax As Double, ntstep As Long
……
End Sub
这部分是主函数,其定义了信号对应图形的步长等,并在左边的导航树中显示。

能具体的演示下不?

Top