Dim dft_Sin() As Double Dim dft_Cos() As Double Dim buffer() As Double
Dim n As Integer, PI As Double, temp As Double Dim m_R As Double, m_I As Double Dim counter As Integer
Public Sub Initialize(sample As Integer, harmonic As Integer) Dim j As Integer n = sample m_R = 0 m_I = 0 ReDim dft_Sin(n) ReDim dft_Cos(n) ReDim buffer(n) For j = 0 To n - 1 dft_Sin(j) = Sqr(2) * Sin(2 * harmonic * PI * j / n) / n dft_Cos(j) = Sqr(2) * Cos(2 * harmonic * PI * j / n) / n buffer(j) = 0 Next j counter = 0 End Sub Public Property Get R() As Double R = m_R End Property
Public Property Get i() As Double i = m_I End Property
Public Property Get Magnitude() As Double Magnitude = Sqr(m_R * m_R + m_I * m_I) End Property
Private Sub Class_Initialize() PI = 3.1415927 End Sub
Public Function DoDFT(v As Double) As Integer counter = counter Mod n temp = v - buffer(counter) m_R = m_R + temp * dft_Cos(counter) m_I = m_I + temp * dft_Sin(counter) buffer(counter) = v counter = counter + 1 DoDFT = counter End Function