|
楼主 |
发表于 2007-7-31 10:12
|
显示全部楼层
程序代码如下
Dim K As Long, N As Long
Dim Ni() As Single '信号源序列
Dim Xz() As Single '信号修正序列
Dim Xs() As Single, Xx() As Single '傅立叶变换序列fft ,Xs是实部,Xx是虚部。
Dim Xns() As Single, Xnx() As Single '傅立叶逆变换序列ifft,Xns是实部,Xnx是虚部。
Dim Nimax As Single, Nimin As Single, Xnmax As Single, Xnmin As Single
Private Sub NiInit() '{Ni()}序列初始化,即信号源序列
For i = 1 To K
If Option1.Value = True Then
Ni(i) = Sin((2 * 3.1415926 * 50) / N * i) '{Ni}为50hz正弦函数离散序列
Randomize
Ni(i) = Ni(i) + Text3 - 2 * Val(Text3) * Rnd '将rnd代换为Sqr(-2 * (Log(Rnd))) * Cos(2 * 3.1415926 * Rnd)后加的是正态噪音
If i = 1 Then
Nimax = Ni(i)
Nimin = Ni(i)
Else
If Nimax < Ni(i) Then Nimax = Ni(i)
If Nimin > Ni(i) Then Nimin = Ni(i)
End If
Else
Ni(i) = Sin((2 * 3.1415926 * 50) / N * i) + Sin((2 * 3.1415926 * 120) / N * i) '{Ni}为50hz正弦函数离散序列
Randomize
Ni(i) = Ni(i) + Text3 - 2 * Val(Text3) * Rnd '将rnd代换为Sqr(-2 * (Log(Rnd))) * Cos(2 * 3.1415926 * Rnd)后加的是正态噪音
If i = 1 Then
Nimax = Ni(i)
Nimin = Ni(i)
Else
If Nimax < Ni(i) Then Nimax = Ni(i)
If Nimin > Ni(i) Then Nimin = Ni(i)
End If
End If
Next
End Sub
Private Sub XzInit() '修正50hz为60hz信号
For i = 1 To K
Xz(i) = Sin((2 * 3.1415926 * 60) / N * i) - Sin((2 * 3.1415926 * 50) / N * i)
Next
End Sub
Private Sub XInit()
For t = 1 To K
Xs(t) = 0
Xx(t) = 0
For i = 1 To K
Xs(t) = Xs(t) + Ni(i) * Cos(2 * 3.1415926 * (t - 1) * (i - 1) / K)
Xx(t) = Xx(t) - Ni(i) * Sin(2 * 3.1415926 * (t - 1) * (i - 1) / K)
Next
Next
For t = 1 To K
For i = 1 To K
Xs(t) = Xs(t) + Xz(i) * Cos(2 * 3.1415926 * (t - 1) * (i - 1) / K)
Xx(t) = Xx(t) - Xz(i) * Sin(2 * 3.1415926 * (t - 1) * (i - 1) / K)
Next
Next
End Sub
Private Sub XnInit()
For i = 1 To K
Xns(i) = 0
Xnx(i) = 0
For t = 1 To K
Xns(i) = Xns(i) + Xs(t) * Cos(2 * 3.1415926 * (t - 1) * (i - 1) / K) - Xx(t) * Sin(2 * 3.1415926 * (t - 1) * (i - 1) / K)
Xnx(i) = Xnx(i) + Xs(t) * Sin(2 * 3.1415926 * (t - 1) * (i - 1) / K) + Xx(t) * Cos(2 * 3.1415926 * (t - 1) * (i - 1) / K)
Next
Xns(i) = Xns(i) / K
If i = 1 Then
Xnmax = Xns(i)
Xnmin = Xns(i)
Else
If Xnmax < Xns(i) Then Xnmax = Xns(i)
If Xnmin > Xns(i) Then Xnmin = Xns(i)
End If
Next
End Sub
Private Sub Com_bp_Click()
XzInit
XInit
XnInit
If Nimax < 0 Then
Nimax = 0
Else
Nimax = Nimax * 1.1
End If
If Nimin > 0 Then
Nimin = 0
Else
Nimin = Nimin * 1.1
End If
Pic1.Scale (0, Nimax)-(K + 2, Nimin)
Pic1.CurrentX = 1
Pic1.CurrentY = Ni(1)
For i = 2 To K
Pic1.Line -(i + 1, Ni(i))
Next
For i = 1 To K
Pic1.Circle (i + 1, Ni(i)), 0.2, vbRed
Next
'''''''''''''''''''''''''''''''''
If Xnmax < 0 Then
Xnmax = 0
Else
Xnmax = Xnmax * 1.1
End If
If Xnmin > 0 Then
Xnmin = 0
Else
Xnmin = Xnmin * 1.1
End If
Pic2.Scale (0, Xnmax)-(K + 2, Xnmin)
Pic2.CurrentX = 1
Pic2.CurrentY = Xns(1)
For i = 2 To K
Pic2.Line -(i + 1, Xns(i))
Next
For i = 1 To K
Pic2.Circle (i + 1, Xns(i)), 0.2, vbRed
Next
End Sub
Private Sub Com_csh_Click()
K = Text1
N = Text2
ReDim Ni(K), Xz(K), Xs(K), Xns(K), Xx(K), Xnx(K)
NiInit
XzInit
End Sub
Private Sub Comm_cp_Click()
Pic1.Cls
Pic2.Cls
End Sub
Private Sub Form_Load()
Com_csh_Click
Option1.Value = True
End Sub
Private Sub Option1_Click()
Option1.Value = True
Option2.Value = False
End Sub
Private Sub Option2_Click()
Option2.Value = True
Option1.Value = False
End Sub:victory: |
评分
-
1
查看全部评分
-
|