micropython-ulab/tests/1d/numpy/fft.py
Zoltán Vörös c0b3262be4
Add keyword arguments to spectrogram (#657)
* re-work spectrogram method, so that RAM can be re-used

* update docs with spectrogram changes
2024-09-14 12:18:14 +02:00

45 lines
1.1 KiB
Python

import math
try:
from ulab import numpy as np
use_ulab = True
except ImportError:
import numpy as np
use_ulab = False
x = np.linspace(-np.pi, np.pi, num=8)
y = np.sin(x)
if use_ulab:
if 'real' in dir(np):
a = np.fft.fft(y)
c = np.real(np.fft.ifft(a))
else:
a, b = np.fft.fft(y)
c, d = np.fft.ifft(a, b)
# c should be equal to y
cmp_result = []
for p,q in zip(list(y), list(c)):
cmp_result.append(math.isclose(p, q, rel_tol=1e-09, abs_tol=1e-09))
print(cmp_result)
z = np.zeros(len(x))
if 'real' in dir(np):
a = np.fft.fft(y)
c = np.real(np.fft.ifft(a))
else:
a, b = np.fft.fft(y, z)
c, d = np.fft.ifft(a, b)
# c should be equal to y
cmp_result = []
for p,q in zip(list(y), list(c)):
cmp_result.append(math.isclose(p, q, rel_tol=1e-09, abs_tol=1e-09))
print(cmp_result)
else:
a = np.fft.fft(y)
c = np.fft.ifft(a)
# c should be equal to y
cmp_result = []
for p,q in zip(list(y), list(c.real)):
cmp_result.append(math.isclose(p, q, rel_tol=1e-09, abs_tol=1e-09))
print(cmp_result)