Hello,
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
@njit
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