55 lines
1.2 KiB
Python
55 lines
1.2 KiB
Python
# -*- encoding:utf-8 -*-
|
|
|
|
'''
|
|
@Author : dingjiawen
|
|
@Date : 2023/6/13 21:32
|
|
@Usage :
|
|
@Desc : FFT的工具类
|
|
'''
|
|
import numpy as np
|
|
import tensorflow as tf
|
|
|
|
'''
|
|
freq_value: 可以是时域通过np.fft.fft转换而来
|
|
'''
|
|
def ifft(freq_value):
|
|
# 幅值
|
|
amp = np.abs(freq_value / len(freq_value))
|
|
# 相角
|
|
angle = np.angle(freq_value)
|
|
length = len(amp)
|
|
|
|
result = []
|
|
for t in range(length):
|
|
wk = 2 * np.pi * np.arange(length) / length
|
|
cur = np.sum(amp * np.cos(wk * t + angle))
|
|
result.append(cur)
|
|
|
|
return result
|
|
|
|
def fft(time_value):
|
|
|
|
pass
|
|
|
|
if __name__ == '__main__':
|
|
array = np.array([-0.029078494757,
|
|
-0.33095228672,
|
|
-0.12124221772,
|
|
0.553512275219,
|
|
-0.158036053181,
|
|
0.268739402294,
|
|
-0.638222515583,
|
|
0.233140587807,
|
|
-0.173265621066,
|
|
0.467218101025,
|
|
-0.372010827065,
|
|
-0.136630430818,
|
|
0.343256533146,
|
|
0.008932195604])
|
|
|
|
print(tf.signal.fft(array))
|
|
array_fft = np.fft.fft(array)
|
|
|
|
# print(ifft(array))
|
|
print(array_fft)
|