Numba for numpy.fft.fft

I am trying to use @jit for optimizing a function using numpy.fft.fft
Below is my code
import numpy as np
import math
from numba import njit

def fft_analysis(x, fs):
# function to transform time domain signal to frequency domain
# using Fast Fourier Transform
y = np.array(np.fft.fft(x))
len_data = len(x)
p2 = abs(y/len_data)
p1 = p2[0:math.floor(len_data/2)+1]
p1[1:(-1)-1] = (2*p1[1:(-1)-1])
df = int(fs/len_data)
freq_data = [x * df for x in range(0, math.floor(len_data/2)+1)]
return p1, freq_data

def avg_fft_analysis(sig_data, fs, time_space):
# function to calculate the avg 1sec fft over the time given
time_end = math.floor(len(sig_data) / (time_space * fs))
# Memory Pre allocation
rows = math.floor(fs / 2)
row_increment = math.floor(time_end)
a = np.zeros(shape=(rows+1, row_increment))
# perform 1sec fft averaging
for i in range(1, row_increment+1):
signal_comp = sig_data[fs*(i-1):(fs*i)]
[a[:, i-1], freq_data] = fft_analysis(signal_comp, fs)

# compute average FFT
avg_amp = a.mean(axis=1)

return freq_data, avg_amp

Below is the error I receive
“numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Untyped global name ‘fft_analysis’: Cannot determine Numba type of <class ‘function’>”

Any solutions will be appreciated

hi @krishnamoparthi , this part tells you what you need to know Untyped global name ‘fft_analysis’: Cannot determine Numba type of <class ‘function’>”. You are using a function called fft_analysis which is not jitted, so it cannot be used inside a jit function.

Thank you. I have numpy.fft.fft used in the fft_analysis.
Does numba support numpy.fft.fft

you can find everything that is supported here: Supported NumPy features — Numba 0.52.0-py3.7-linux-x86_64.egg documentation

Hi @krishnamoparthi

This issue tracks the general “FFT support” request: Support for np.fft.fft, np.fft.ifft etc. · Issue #5864 · numba/numba · GitHub, the main issue is this: Support for np.fft.fft, np.fft.ifft etc. · Issue #5864 · numba/numba · GitHub

Hope this helps?

Hello @luk-f-a
Thank you for the help

Hello @stuartarchibald
Thank you