FFT (AI Nsample)

 1'''
 2FFT - fourier_transform_simulate.py.
 3
 4This example demonstrates how to use fourier transform with AI N-sample data
 5
 6
 7For other examples please check:
 8    https://github.com/WPC-Systems-Ltd/WPC_Stand-alone_Python_release/tree/main/examples
 9
10Copyright (c) 2024 WPC Systems Ltd.
11All rights reserved.
12'''
13
14from ulab import numpy as np
15import pywpc
16
17## Parameters
18sampling_rate = 1000
19sample = 1024
20delay = 2000
21
22## Start AI acquisition
23pywpc.AI_start(sampling_rate, sample)
24
25## Read data acquisition
26ai_sample = pywpc.AI_readNsample(sample, delay)
27
28## Convert AI data
29ai_sample_cvt = [list(i) for i in zip(*ai_sample)]
30
31## Convert from list to array
32ai_sample_cvt_arr = np.array(ai_sample_cvt)
33
34## Apply the FFT on the signal
35## Get channel 1 data
36fourier_real, fourier_imaginary = np.fft.fft(ai_sample_cvt_arr[1])
37power_spectrum = fourier_real**2 + fourier_imaginary**2
38
39## Print result
40print(power_spectrum)
41print(len(power_spectrum))
42print(max(power_spectrum))