It appeared "Compile error: Sub or Function not defined" when I run the code. I have been finding the solutions but they all did not work. Anyone know please help me. I don't know about coding this is my homework. The professor give this code for us to process the data from our experiment. Here it my code
Function FFTRec(N As Integer, theta As Double, ar() As Double, ai() As Double, tmpr() As Double, tmpi() As Double)
Dim nh As Integer, j As Integer
Dim xr, xi, wr, wi, tmp2r(512) As Double, tmp2i(512) As Double
If N > 1 Then
nh = N / 2
For j = 0 To nh - 1
tmpr(j) = ar(j) + ar(nh + j)
tmpi(j) = ai(j) + ai(nh + j)
xr = ar(j) - ar(nh + j)
xi = ai(j) - ai(nh + j)
wr = Cos(theta * j)
wi = Sin(theta * j)
tmp2r(j) = xr * wr - xi * wi
tmp2i(j) = xi * wr + xr * wi
Next j
Call FFTRec(nh, 2 * theta, tmpr, tmpi, ar, ai)
Call FFTRec(nh, 2 * theta, tmp2r, tmp2i, ar, ai)
For j = 0 To nh - 1
ar(2 * j) = tmpr(j)
ai(2 * j) = tmpi(j)
ar(2 * j + 1) = tmp2r(j)
ai(2 * j + 1) = tmp2i(j)
Next j
End If
End Function
Public Sub FFT()
Dim xr(512) As Double, xi(512) As Double, tmpr(512) As Double, tmpi(512) As Double
Dim pi, wm, theta As Double
Dim i, Tr, N As Integer
Dim curStartTime, curEndTime, curFreq As Currency
i = 0: N = 512: Tr = 6
pi = WorksheetFunction.pi
theta = 2 * pi / N
For i = 1 To N
xr(i - 1) = Cells(i + Tr - 1, 2): xi(i - 1) = 0
Next i
Call QueryPerformanceFreQuency(curFreq)
Call QueryPerformanceCounter(curStartTime)
Call FFTRec(N, theta, xr, xi, tmpr, tmpi)
Call QueryPerformanceCounter(curEndTime)
Cells(1, 9) = "Processing Time " & CStr((curEndTime - curStartTime) / curFreq) & " Second"
Cells(Tr - 1, 9) = "xr(i)_FFT": Cells(Tr - 1, 10) = "xi(i)_FFT": Cells(Tr - 1, 11) = "P_FFT"
For i = 0 To N - 1
Cells(i + Tr, 9) = xr(i)
Cells(i + Tr, 10) = xi(i)
Cells(i + Tr, 11) = Sqr(xr(i) ^ 2 + xi(i) ^ 2)
Next i
End Sub
By the way I am not a native speaker.
Thank you.