Страница: 1 |
Вопрос: алгоритм для БПФ
Добавлено: 01.03.13 00:55
Автор вопроса: merr
Доброго времени суток, товарищи!
Может кто писал или видел пример алгоритма для быстрых преобразований Фурье (БПФ) на VB6?
Не имею морального права расспрашивать детали... Но буду признателен за ссылку ;)
Ответить
Номер ответа: 2Автор ответа: AWP
ICQ: 345685652 Вопросов: 96Ответов: 1212
Web-сайт: xawp.narod.ru Профиль | | #2
Добавлено: 01.03.13 01:02
Public Sub FFTC1D(ByRef A() As Complex, ByVal N As Long )
Dim Plan As FTPlan
Dim I As Long
Dim Buf() As Double
If N = 1# Then
Exit Sub
End If
ReDim Buf(0 To 2# * N - 1)
For I = 0# To N - 1# Step 1
Buf(2# * I + 0#) = A(I).X
Buf(2# * I + 1#) = A(I).Y
Next I
Call FTBaseGenerateComplexFFTPlan(N, Plan)
Call FTBaseExecutePlan(Buf, 0#, N, Plan)
For I = 0# To N - 1# Step 1
A(I).X = Buf(2# * I + 0#)
A(I).Y = Buf(2# * I + 1#)
Next I
End Sub
Public Sub FFTC1DInv(ByRef A() As Complex, ByVal N As Long )
Dim I As Long
For I = 0# To N - 1# Step 1
A(I).Y = -A(I).Y
Next I
Call FFTC1D(A, N)
For I = 0# To N - 1# Step 1
A(I).X = A(I).X / N
A(I).Y = -(A(I).Y / N)
Next I
End Sub
Public Sub FFTR1D(ByRef A() As Double , ByVal N As Long , ByRef F() As Complex)
Dim I As Long
Dim N2 As Long
Dim Idx As Long
Dim Hn As Complex
Dim HmnC As Complex
Dim V As Complex
Dim Buf() As Double
Dim Plan As FTPlan
Dim i_ As Long
If N = 1# Then
ReDim F(0 To 1# - 1)
F(0#) = C_Complex(A(0#))
Exit Sub
End If
If N = 2# Then
ReDim F(0 To 2# - 1)
F(0#).X = A(0#) + A(1#)
F(0#).Y = 0#
F(1#).X = A(0#) - A(1#)
F(1#).Y = 0#
Exit Sub
End If
If N Mod 2# = 0# Then
N2 = N \ 2#
ReDim Buf(0 To N - 1)
For i_ = 0# To N - 1# Step 1
Buf(i_) = A(i_)
Next i_
Call FTBaseGenerateComplexFFTPlan(N2, Plan)
Call FTBaseExecutePlan(Buf, 0#, N2, Plan)
ReDim F(0 To N - 1)
For I = 0# To N2 Step 1
Idx = 2# * (I Mod N2)
Hn.X = Buf(Idx + 0#)
Hn.Y = Buf(Idx + 1#)
Idx = 2# * ((N2 - I) Mod N2)
HmnC.X = Buf(Idx + 0#)
HmnC.Y = -Buf(Idx + 1#)
V.X = -Sin(-(2# * Pi() * I / N))
V.Y = Cos(-(2# * Pi() * I / N))
F(I) = C_Sub(C_Add(Hn, HmnC), C_Mul(V, C_Sub(Hn, HmnC)))
F(I).X = 0.5 * F(I).X
F(I).Y = 0.5 * F(I).Y
Next I
For I = N2 + 1# To N - 1# Step 1
F(I) = Conj(F(N - I))
Next I
Exit Sub
Else
ReDim F(0 To N - 1)
For I = 0# To N - 1# Step 1
F(I) = C_Complex(A(I))
Next I
Call FFTC1D(F, N)
Exit Sub
End If
End Sub
Public Sub FFTR1DInv(ByRef F() As Complex, _
ByVal N As Long , _
ByRef A() As Double )
Dim I As Long
Dim H() As Double
Dim FH() As Complex
If N = 1# Then
ReDim A(0 To 1# - 1)
A(0#) = F(0#).X
Exit Sub
End If
ReDim H(0 To N - 1)
ReDim A(0 To N - 1)
H(0#) = F(0#).X
For I = 1# To Int(N / 2#) - 1# Step 1
H(I) = F(I).X - F(I).Y
H(N - I) = F(I).X + F(I).Y
Next I
If N Mod 2# = 0# Then
H(Int(N / 2#)) = F(Int(N / 2#)).X
Else
H(Int(N / 2#)) = F(Int(N / 2#)).X - F(Int(N / 2#)).Y
H(Int(N / 2#) + 1#) = F(Int(N / 2#)).X + F(Int(N / 2#)).Y
End If
Call FFTR1D(H, N, FH)
For I = 0# To N - 1# Step 1
A(I) = (FH(I).X - FH(I).Y) / N
Next I
End Sub
Public Sub FFTR1DInternalEven(ByRef A() As Double , _
ByVal N As Long , _
ByRef Buf() As Double , _
ByRef Plan As FTPlan)
Dim X As Double
Dim Y As Double
Dim I As Long
Dim N2 As Long
Dim Idx As Long
Dim Hn As Complex
Dim HmnC As Complex
Dim V As Complex
Dim i_ As Long
If N = 2# Then
X = A(0#) + A(1#)
Y = A(0#) - A(1#)
A(0#) = X
A(1#) = Y
Exit Sub
End If
N2 = N \ 2#
For i_ = 0# To N - 1# Step 1
Buf(i_) = A(i_)
Next i_
Call FTBaseExecutePlan(Buf, 0#, N2, Plan)
A(0#) = Buf(0#) + Buf(1#)
For I = 1# To N2 - 1# Step 1
Idx = 2# * (I Mod N2)
Hn.X = Buf(Idx + 0#)
Hn.Y = Buf(Idx + 1#)
Idx = 2# * (N2 - I)
HmnC.X = Buf(Idx + 0#)
HmnC.Y = -Buf(Idx + 1#)
V.X = -Sin(-(2# * Pi() * I / N))
V.Y = Cos(-(2# * Pi() * I / N))
V = C_Sub(C_Add(Hn, HmnC), C_Mul(V, C_Sub(Hn, HmnC)))
A(2# * I + 0#) = 0.5 * V.X
A(2# * I + 1#) = 0.5 * V.Y
Next I
A(1#) = Buf(0#) - Buf(1#)
End Sub
Public Sub FFTR1DInvInternalEven(ByRef A() As Double , _
ByVal N As Long , _
ByRef Buf() As Double , _
ByRef Plan As FTPlan)
Dim X As Double
Dim Y As Double
Dim T As Double
Dim I As Long
Dim N2 As Long
If N = 2# Then
X = 0.5 * (A(0#) + A(1#))
Y = 0.5 * (A(0#) - A(1#))
A(0#) = X
A(1#) = Y
Exit Sub
End If
N2 = N \ 2#
Buf(0#) = A(0#)
For I = 1# To N2 - 1# Step 1
X = A(2# * I + 0#)
Y = A(2# * I + 1#)
Buf(I) = X - Y
Buf(N - I) = X + Y
Next I
Buf(N2) = A(1#)
Call FFTR1DInternalEven(Buf, N, A, Plan)
A(0#) = Buf(0#) / N
T = 1# / N
For I = 1# To N2 - 1# Step 1
X = Buf(2# * I + 0#)
Y = Buf(2# * I + 1#)
A(I) = T * (X - Y)
A(N - I) = T * (X + Y)
Next I
A(N2) = Buf(1#) / N
End Sub
Ответить
Страница: 1 |
Поиск по форуму