FFT (simulated)

 1'''
 2FFT - fourier_transform_simulate.py.
 3
 4This example demonstrates how to use fourier transform with simulated data
 5
 6For other examples please check:
 7    https://github.com/WPC-Systems-Ltd/WPC_Stand-alone_Python_release/tree/main/examples
 8
 9Copyright (c) 2024 WPC Systems Ltd.
10All rights reserved.
11'''
12
13from ulab import numpy as np
14import pywpc
15
16## Parameters
17Fs = 256                ## sampling rate
18Ts = 1.0/Fs             ## sampling interval
19t = np.arange(0, 1, Ts) ## time vector
20frequency = 50          ## frequency of the signal
21
22## Sine signal
23signal = np.sin(2*np.pi*frequency*t)
24
25## Square signal
26# signal = [1.0 if (frequency*x % 1) < 0.5 else -1.0 for x in t]
27# signal = np.array(signal)
28
29## Apply the FFT on the signal
30fourier_real, fourier_imaginary = np.fft.fft(signal)
31power_spectrum = fourier_real**2 + fourier_imaginary**2
32
33## Print result
34print(power_spectrum)
35print(len(power_spectrum))
36print(max(power_spectrum))