| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛

问题点数：0 回复次数：21

a = (678)'10 = 6x10^2 + 7x10^1 + 8x10^0
b = (432)'10 = 4x10^2 + 3x10^1 + 2x10^0

c = a x b = 10^4xc4 + 10^3xc3 + 10^2xc2 + 10^1xc1 + 10^0xc0
= 10000x24 + 1000x46 + 100x65 + 10x38 + 1x16
= 292896

{ a7, a6, a5, a4, a3, a2, a1, a0 } = { 0, 0, 0, 0, 0, 6, 7, 8 }
{ b7, b6, b5, b4, b3, b2, b1, b0 } = { 0, 0, 0, 0, 0, 4, 3, 2 }

ω^0~ω^7分别是1，0.7-0.7i，-i，-0.7-0.7i，-1，-0.7+0.7i，i，0.7+0.7i.

ω^0和ω^8是相等的，ω^4和ω^12是相等的，等，这就是周期性。

{ A7, A6, A5, A4, A3, A2, A1, A0 } = { 12.9+10.9i, 2+7i, 3.1-1.1i, 7, 3.1+1.1i, 2-7i, 12.9-10.9i, 21 }
{ B7, B6, B5, B4, B3, B2, B1, B0 } = { 4.1+6.1i, -2+3i, -0.1-1.9i, 3, -0.1+1.9i, -2-3i, 4.1-6.1i, 9 }

= { -13.6+123.4i, -25-8i, -2.4-5.8i, 21, -2.4+5.8i, -25+8i, -13.6-123.4i, 189 }

{ c7, c6, c5, c4, c3, c2, c1, c0 } = { 0, 0, 0, 0, 24, 46, 65, 38, 16 }

[此贴子已经被作者于2020-9-5 21:53编辑过]

'VB版快速傅里叶变换模块
'模块说明
'pr(),pi()为输入序列的实部与虚部，fr(),fi()分别是输出序列的实部与虚部。
'数组长度为n, n=2^k.
'L为0时做正变换，为1时做反变换。

Public Sub kkfft(ByRef pr() As Double, _
ByRef pi() As Double, _
ByRef fr() As Double, _
ByRef fi() As Double, _
ByVal n As Integer, _
ByVal k As Integer, ByVal L As Integer)

Dim it As Integer
Dim m As Integer
Dim iis As Integer
Dim i As Integer
Dim j As Integer
Dim nv As Integer
Dim l0 As Integer
Dim p, q, s, vr, vi, poddr, poddi As Double
For it = 0 To n - 1
m = it
iis = 0
For i = 0 To k - 1
j = Int(m / 2)
iis = 2 * iis + (m - 2 * j)
m = j
Next
fr(it) = pr(iis)
fi(it) = pi(iis)
Next
pr(0) = 1#
pi(0) = 0#
p = 6.283185306 / (1# * n)
pr(1) = Cos(p)
pi(1) = -Sin(p)
If L <> 0 Then pi(1) = -pi(1)
For i = 2 To n - 1
p = pr(i - 1) * pr(1)
q = pi(i - 1) * pi(1)
s = (pr(i - 1) + pi(i - 1)) * (pr(1) + pi(1))
pr(i) = p - q
pi(i) = s - p - q
Next
For it = 0 To n - 2 Step 2
vr = fr(it)
vi = fi(it)
fr(it) = vr + fr(it + 1)
fi(it) = vi + fi(it + 1)
fr(it + 1) = vr - fr(it + 1)
fi(it + 1) = vi - fi(it + 1)
Next
m = n / 2
nv = 2
For l0 = k - 2 To 0 Step -1
m = m / 2: nv = 2 * nv
For it = 0 To (m - 1) * nv Step nv
For j = 0 To (nv / 2) - 1
p = pr(m * j) * fr(it + j + nv / 2)
q = pi(m * j) * fi(it + j + nv / 2)
s = pr(m * j) + pi(m * j)
s = s * (fr(it + j + nv / 2) + fi(it + j + nv / 2))
poddr = p - q
poddi = s - p - q
fr(it + j + nv / 2) = fr(it + j) - podd
fi(it + j + nv / 2) = fi(it + j) - poddi
fr(it + j) = fr(it + j) + poddr
fi(it + j) = fi(it + j) + poddi
Next
Next
Next
If L <> 0 Then
For i = 0 To n - 1
fr(i) = fr(i) / (1# * n)
fi(i) = fi(i) / (1# * n)
Next
End If
End Sub

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

• 22
• 1/3页
• 1
• 2
• 3