This code will capture, process and show you the FFT of the signal on AIN0.CH0.
In [1]:
import Box0
import Gadfly
##### PART 1 - Capture
# Allocate resources
dev = Box0.Usb.open_supported()
ain0 = Box0.ain(dev)
# Prepare AIN0 for snapshot mode
Box0.snapshot_prepare(ain0)
# Read data from AIN0
bitsize, sampling_freq = Box0.bitsize_speed_get(ain0)
data = Array(Float32, 1000)
Box0.snapshot_start(ain0, data)
# Free the resources
Box0.close(ain0)
Box0.close(dev)
##### PART 2 - Process
# perform FFT on captured data
fft_amp = abs(fft(data))
fft_freq = linspace(0, sampling_freq, length(fft_amp))
##### PART 3 - Visualize
# Show the time domain results (unable to show both plot at once - fix later!...never ;)
#time_x = linspace(0, length(data) / sampling_freq, length(data))
#Gadfly.plot(x=time_x, y=data, Gadfly.Geom.line)
# Show the frequency domain results
Gadfly.plot(x=fft_freq, y=fft_amp, Gadfly.Geom.line)
Out[1]: