Copyright © 1999-2020, , All Rights Reserved
搜索博文/帖子/用户
登录
VB实现FFT算法 转载
weixin_34245749
225次阅读 2013-04-17
关注
程序列如下:
Public Function fft(ByRef Data() As Double) As Double()
ReDim ffft(128, 2) As Double
Dim length As Integer
length = UBound(Data, 1) + 1
'
Dim numArray(length - 1, 2) As Double
Dim index As Integer
Dim num5 As Integer
Dim num6 As Integer
Dim num7 As Integer
Dim num10 As Integer
Dim num3 As Integer
Dim num2 As Integer
Dim num11 As Integer
Dim num9 As Integer
num9 = length
Dim num8 As Integer
num8 = CInt(Math.Log(CDbl(num9)) / Math.Log(2#))
Dim numArray2(128) As Double
Dim numArray3(128) As Double
Dim numArray4(128) As Double
Dim numArray5(128) As Double
For index = 0 To num9 - 1
numArray2(index) = Data(index)
numArray3(index) = 0#
Next
Dim a As Double
Dim num14 As Double
num14 = 6.28318530717959 / CDbl(num9)
index = 0
While index < (num9 \ 2)
numArray4(index) = Math.Sin(a)
numArray5(index) = Math.Cos(a)
a = a + num14
index = index + 1
Wend
num7 = num9
num3 = 1
For num2 = 1 To num8
num7 = num7 / 2
num6 = 0
For num11 = 1 To num3
num10 = 0
index = num6
While index <= ((num7 + num6) - 1)
num5 = index + num7
a = numArray2(index) - numArray2(num5)
num14 = numArray3(index) - numArray3(num5)
numArray2(index) = numArray2(index) + numArray2(num5)
numArray3(index) = numArray3(index) + numArray3(num5)
If num10 = 0 Then
numArray2(num5) = a
numArray3(num5) = num14
Else
numArray2(num5) = (a * numArray5(num10)) + (num14 * numArray4(num10))
numArray3(num5) = (num14 * numArray5(num10)) - (a * numArray4(num10))
End If
num10 = num10 + num3
index = index + 1
Wend
num6 = (num6 + num7) + num7
Next
num3 = num3 + num3
Next
num5 = num9 \ 2
For index = 1 To (num9 - 1)
num6 = num9
If num5 < index Then
Dim num12 As Double
num12 = numArray2(index)
numArray2(index) = numArray2(num5)
numArray2(num5) = num12
num12 = numArray3(index)
numArray3(index) = numArray3(num5)
numArray3(num5) = num12
End If
num6 = num6 / 2
Do While num5 >= num6
num5 = num5 - num6
num6 = num6 / 2
If num5 = 0 Then
Exit Do
End If
Loop
num5 = num5 + num6
Next
For index = 0 To num9 - 1
numArray(index, 0) = numArray2(index)
numArray(index, 1) = numArray3(index)
numArray(index, 2) = ((numArray2(index)) ^ 2# + (numArray3(index)) ^ 2#) ^ 0.5
Next
fft = numArray
End Function
前面的程序的说明(原稿中复制过来的):
默认了数组为128
如果你需要动态,请
redim各数组
输入:一串数据
输出:FFT变换后的数据,1维是实部 ,2维是虚部
这是vb版快速傅立叶变换fft,不懂,也不知道输出啥结果,不知道是否可以用于大整数的快速乘法。
没有找到vb版的大整数快速乘法程序。
有vc版的,不懂。