- 注册时间
- 2011-5-29
- 最后登录
- 1970-1-1
- 威望
- 星
- 金币
- 枚
- 贡献
- 分
- 经验
- 点
- 鲜花
- 朵
- 魅力
- 点
- 上传
- 次
- 下载
- 次
- 积分
- 1404
- 在线时间
- 小时
|
发表于 2013-6-8 15:47:14
|
显示全部楼层
VB 编写的FFT(8点的基2FFT)
Ft=8
入口参数:数组 ax_sz()
出口参数: FFT_Nr()(实数部分) ;FFT_Ni() (虚数部分) 数据类型 Variant
Function FFT(ax_sz() As Variant) 'FFT2 傅里叶变换 2013-.6-08
Dim Ar(), Ai() As Variant
Dim x1(1, 8), x2(1, 8) As Variant
Dim x11(1, 8), x12(1, 8), x21(1, 8), x22(1, 8) As Variant
Dim Np, u, i As Integer
Np = Ft
ReDim Ar(Np), Ai(Np) As Variant
'Dim ax_sz(512)
x11(1, 0) = 0
x12(1, 0) = 0
x21(1, 0) = 0
x22(1, 0) = 0
x11(0, 1) = ax_sz(0)
x12(0, 1) = ax_sz(2)
x21(0, 1) = ax_sz(1)
x22(0, 1) = ax_sz(3)
x11(1, 1) = -ax_sz(4)
x12(1, 1) = -ax_sz(6)
x21(1, 1) = -ax_sz(5)
x22(1, 1) = -ax_sz(7)
x11(0, 0) = x11(0, 1) - x11(1, 1)
x12(0, 0) = x12(0, 1) - x12(1, 1)
x21(0, 0) = x21(0, 1) - x21(1, 1)
x22(0, 0) = x22(0, 1) - x22(1, 1)
'k=2
x11(0, 2) = x11(0, 1) + x11(1, 1)
x12(0, 2) = x12(0, 1) + x12(1, 1)
x21(0, 2) = x21(0, 1) + x21(1, 1)
x22(0, 2) = x22(0, 1) + x22(1, 1)
x11(1, 2) = x11(1, 0)
x12(1, 2) = x12(1, 0)
x21(1, 2) = x21(1, 0)
x22(1, 2) = x22(1, 0)
'k=3
x11(0, 3) = x11(0, 1)
x12(0, 3) = x12(0, 1)
x21(0, 3) = x21(0, 1)
x22(0, 3) = x22(0, 1)
x11(1, 3) = -x11(1, 1)
x12(1, 3) = -x12(1, 1)
x21(1, 3) = -x21(1, 1)
x22(1, 3) = -x22(1, 1)
'k=4
x11(0, 4) = x11(0, 0)
x11(1, 4) = x11(1, 0)
x12(0, 4) = x12(0, 0)
x12(1, 4) = x12(1, 0)
x21(0, 4) = x21(0, 0)
x21(1, 4) = x21(1, 0)
x22(0, 4) = x22(0, 0)
x22(1, 4) = x22(1, 0)
'FFT 值
x1(0, 0) = x11(0, 0) + x12(0, 0)
x1(1, 0) = 0
x2(0, 0) = x21(0, 0) + x22(0, 0)
x2(1, 0) = 0
x1(0, 4) = x11(0, 4) - x12(0, 4)
x1(1, 4) = 0
x2(0, 4) = x21(0, 4) - x22(0, 4)
x2(1, 4) = x1(1, 4)
For i = 1 To 3
u = 32 * i Mod 256
x1(0, i) = x11(0, i) + x12(0, i) * Sbi(0, u) - x12(1, i) * Sbi(1, u)
x1(1, i) = x11(1, i) + x12(0, i) * Sbi(1, u) + x12(1, i) * Sbi(0, u)
x1(0, 8 - i) = x1(0, i)
x1(1, 8 - i) = -x1(1, i)
x2(0, i) = x21(0, i) + x22(0, i) * Sbi(0, u) - x22(1, i) * Sbi(1, u)
x2(1, i) = x21(1, i) + x22(0, i) * Sbi(1, u) + x22(1, i) * Sbi(0, u)
x2(0, 8 - i) = x2(0, i)
x2(1, 8 - i) = -x2(1, i)
Next
x1(0, 8) = x1(0, 0)
x1(1, 8) = x1(1, 0)
x2(0, 8) = x2(0, 0)
x2(1, 8) = x2(1, 0)
FFT_Nr(0) = x11(0, 0) + x12(0, 0) + x21(0, 0) + x22(0, 0)
FFT_Ni(0) = 0
FFT_Nr(4) = x1(0, 4)
FFT_Ni(4) = -x2(0, 4)
For i = 1 To 8
u = 16 * i Mod 256
FFT_Nr(i) = x1(0, i) + x2(0, i) * Sbi(0, u) - x2(1, i) * Sbi(1, u)
FFT_Ni(i) = x1(1, i) + x2(0, i) * Sbi(1, u) + x2(1, i) * Sbi(0, u)
FFT_Nr(Np - i) = FFT_Nr(i)
FFT_Ni(Np - i) = -FFT_Ni(i)
Next
End Function |
|