import sys
sys.path.append("C:\Users\svejlani\Documents\expeyes-3.0.0\expeyes-3.0.0\eyes-junior")
import expeyes.eyesj
p=expeyes.eyesj.open()
t,v=p.capture(1,512,100)
#Capturing 512 samples at a sampling rate of 10KHz(100us Interval)
from pylab import *
%matplotlib inline
plot(t,v)
import numpy as np
from scipy import fftpack as f
#convert t,v to numpy array
x_n=np.array(v)
plot(x_n)
fft_x_n=f.fft(x_n)
plot(abs(fft_x_n))
#Finding Peaks using visual inspection of magnitude and finding corresponding index below
[x for x in range(len(fft_x_n)) if abs(fft_x_n[x]) > 500 ]
#Sampling freq=10KHz
#Max i/p freq = Fs/2 = 5KHz
#Max freq in DFT, is of pi which corresponds to mid-point sample in sample(post that spectrum repeats itself)
#so for 0-511 sample fft, sample 255 corresponds to max freq=5KHz.
#simple mapping results the peak's index(found above as 8) ,corresponds to as below:
(5.0/255)*8
#Freq of sine wave is around 156Hz ( The manual says "SINE wave: Fixed frequency sine wave generator, frequency is around 150Hz.")
#So in decent agreement for a 512 point FFT sampled at rate of 10KHz