vb傅里叶变换
我在做毕业设计,需要进行谐波分析,要用到快速傅里叶变换,但是在网上找了好多觉得很复杂。我得主要是对一个正弦余弦波进行傅里叶变换,不需要对虚部进行变换,希望各位能给出一些简单的vb代码,最好能给出用法,谢谢 --------------------编程问答-------------------- 你好 ··你也做毕业设计 我做的是频谱分析仪 也是需要用到FFT变换·有什么可以互相交流的呀·· --------------------编程问答--------------------
Private Function ReverseBits(ByVal Index As Long, NumBits As Long) As Long
Dim i As Byte, Rev As Long
For i = 0 To NumBits - 1
Rev = (Rev * 2) Or (Index And 1)
Index = Index \ 2
Next
ReverseBits = Rev
End Function
Public Sub FFT1D(NumBits As Long, RealIn() As Single, ImageIn() As Single, RealOut() As Single, ImagOut() As Single, Optional InverseTransform As Boolean = False)
Dim i As Long, j As Long
Dim k As Long, N As Long
Dim NumSamples As Long, AngleNumerator As Single
Dim BlockSize As Long, BlockEnd As Long
Dim DeltaAngle As Single, DeltaAr As Single
Dim Alpha As Single, Beta As Single
Dim TR As Single, TI As Single
Dim AR As Single, AI As Single
If InverseTransform Then
AngleNumerator = -2# * 3.1415926
Else
AngleNumerator = 2# * 3.1415926
End If
NumSamples = 2 ^ NumBits
For i = 0 To NumSamples - 1
j = ReverseBits(i, NumBits)
RealOut(j) = RealIn(i)
ImagOut(j) = ImageIn(i)
Next
BlockEnd = 1
BlockSize = 2
Do While BlockSize <= NumSamples
DeltaAngle = AngleNumerator / BlockSize
Alpha = Sin(0.5 * DeltaAngle)
Alpha = 2# * Alpha * Alpha
Beta = Sin(DeltaAngle)
i = 0
Do While i < NumSamples
AR = 1#
AI = 0#
j = i
For N = 1 To BlockEnd
k = j + BlockEnd
TR = AR * RealOut(k) - AI * ImagOut(k)
TI = AI * RealOut(k) + AR * ImagOut(k)
RealOut(k) = RealOut(j) - TR
ImagOut(k) = ImagOut(j) - TI
RealOut(j) = RealOut(j) + TR
ImagOut(j) = ImagOut(j) + TI
DeltaAr = Alpha * AR + Beta * AI
AI = AI - (Alpha * AI - Beta * AR)
AR = AR - DeltaAr
j = j + 1
Next
i = i + BlockSize
Loop
BlockEnd = BlockSize
BlockSize = BlockSize * 2
Loop
If InverseTransform Then
For i = 0 To NumSamples - 1 ' 'Normalize the resulting time samples...
RealOut(i) = RealOut(i) / NumSamples
ImagOut(i) = ImagOut(i) / NumSamples
Next
End If
End Sub
包含了FFT变换和FFT逆变换 --------------------编程问答-------------------- 关于这可以调用matlab函数来完成! --------------------编程问答-------------------- 路过,看看热闹~~~帮你顶~~~~~~~~ --------------------编程问答--------------------
我就是这样完成的
补充:VB , 非技术类