马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
Public Sub hilbertTransform1(N As Integer, A() As Double, B() As Double)
' Dim B() As Double
ReDim B(N) As Double
sA = A
M = 0
T1 = N
While (T1 <> 1)
M = M + 1
T1 = T1 / 2
Wend
For i = 0 To N - 1
j = 0
i1 = i
For s = 0 To M - 1
i2 = i1
t = Int((M - 1 - s) ^ 2)
j = j + (i2 - 2 * Int(i2 / 2)) * t
i1 = Int(i2 / 2)
Next s
If (j >= i) Then
Dim t3 As Double
t3 = A(i)
A(i) = A(j)
A(j) = t3
End If
Next i
tx = N
k = 1
P = 3.1415927
For Ln = 1 To M
Dim U1, U2, C, w1, W2 As Double
U1 = 1
U2 = 0
C = P / k
w1 = Math.Cos(C)
W2 = -Math.Sin(C)
For E = 0 To k - 1
For L = E To N - 1 Step L + 2 * k
T1 = A(L + k) * U1 - B(L + k) * U2
T2 = A(L + k) * U2 + B(L + k) * U1
A(L + k) = A(L) - T1
B(L + k) = B(L) - T2
A(L) = A(L) + T1
B(L) = B(L) + T2
Next L
Dim V1, V2 As Double
V1 = U1 * w1 - U2 * W2
V2 = U1 * W2 + U2 * w1
U1 = V1
U2 = V2
Next E
k = 2 * k
Next Ln
sB = B
For i = 1 To N / 2 - 1
A(i) = A(i) * 2
B(i) = B(i) * 2
Next i
For i = N / 2 To N - 1
A(i) = 0
B(i) = 0
Next i
For i = 0 To N - 1
B(i) = B(i) * -1
Next i
For i = 0 To N - 1
j = 0
i1 = i
For s = 0 To M - 1
i2 = i1
t = Int((M - 1 - s) ^ 2)
j = j + (i2 - 2 * Int(i2 / 2)) * t
i1 = Int(i2 / 2)
Next s
If (j >= i) Then
t3 = A(i)
A(i) = A(j)
A(j) = t3
t4 = B(i)
B(i) = B(j)
B(j) = t4
End If
Next i
k = 1
For Ln = 1 To M
U1 = 1
U2 = 0
C = P / k
w1 = Math.Cos(C)
W2 = -Math.Sin(C)
For E = 0 To k - 1
For L = E To N - 1 Step L + 2 * k
T1 = A(L + k) * U1 - B(L + k) * U2
T2 = A(L + k) * U2 + B(L + k) * U1
A(L + k) = A(L) - T1
B(L + k) = B(L) - T2
A(L) = A(L) + T1
B(L) = B(L) + T2
Next L
V1 = U1 * w1 - U2 * W2
V2 = U1 * W2 + U2 * w1
U1 = V1
U2 = V2
Next E
k = 2 * k
Next Ln
For i = 0 To N - 1
B(i) = B(i) * -1
Next i
For i = 0 To N - 1
A(i) = Math.Sqr(A(i) * A(i) + B(i) * B(i)) * 2 / N
Next i
End Sub
|