def testao_outputdc_single_ch(self): """ testao_outputdc_single_ch Connect analog-out pin 0 to analog-in pin 0 Connect analog-out pin 1 to analog-in pin 1 """ ao0 = pdt.analog_output(daqid=0, channel=0) ao0.output_dc(0.5) ai0 = pdt.analog_input(daqid=0, channel=0, rsediff='rse', samplerate=1250000) a = ai0.acquire(10) print a self.assertAlmostEqual(a[0], 0.5, places=2) ao1 = pdt.analog_output(daqid=0, channel=1) ao1.output_dc(1.0) ai1 = pdt.analog_input(daqid=0, channel=1, rsediff='rse', samplerate=50000) a = ai1.acquire(10) self.assertAlmostEqual(a[0], 1.0, places=2)
def testai_finite_samples(self): """ testai """ ai0 = pdt.analog_input(daqid=0, channel=0, contfin='fin', rsediff='rse', samplerate=1250000) a = ai0.acquire(10) print a ai1 = pdt.analog_input(daqid=0, channel=[1], contfin='fin', rsediff='rse', samplerate=1250000) a = ai1.acquire(10) print a ai0C = pdt.analog_input(daqid=0, channel=[2,3], contfin='fin', rsediff='rse', samplerate=1250000) a = ai0C.acquire(10) print a a = ai0.acquire(10) print a
def testconterms(self): """ test connect terminals """ ai = pdt.analog_input() ao = pdt.analog_output() pdt.connect_terms(0,ao,ai)
def testao_outputdc_multi_ch(self): """ testao_outputdc_multi_ch Connect analog-out pin 0 to analog-in pin 0 Connect analog-out pin 1 to analog-in pin 1 """ ao = pdt.analog_output(daqid=0, channel=[0,1]) ao.output_dc([0.5,1.0]) ai = pdt.analog_input(daqid=0, channel=[0,1], rsediff='rse', samplerate=50000) a = ai.acquire(5) print a self.assertAlmostEqual(a[0], 0.5, places=2) self.assertAlmostEqual(a[5], 1.0, places=2)
def testai_continuous_samples(self): """ testai continuous sampling """ ai0 = pdt.analog_input(daqid=0, channel=0, contfin='cont', rsediff='rse', samplerate=1000) ai0.start() for i in range(10): a = ai0.acquire(1000) print 'Max:', a.max() print 'Mean: ', a.mean() print 'Min: ', a.min(), '\n' ai0.stop()
def testao_output_waveform(self): """ test counter inputs """ y = numpy.zeros(1000,dtype=numpy.float64) # create 1000 evenly spaced values from time=0 to x t = numpy.linspace(0,0.01,1000) f = 1000 A = 5 #y = A*waveforms.square(2*math.pi*f*t,duty=0.5) #y = A*waveforms.sawtooth(2*math.pi*f*t,width=0.5) for i in numpy.arange(1000): y[i] = 9.95*math.sin(i*2.0*math.pi*1000.0/16000.0) ao = pdt.analog_output(channel=[0],samplerate=10000,contfin='cont')#clock='ai/SampleClock') ai = pdt.analog_input(channel=[0],samplerate=1E6) ao.output_waveform(y) ai.AcquireAndGraph(100000) ao.output_waveform(y)
import numpy import pydaqtools as pdt import matplotlib.pyplot as plt num_samples = 10000 pwm_freq = 10000 sample_rate = 1000000 # let pydaqtools find daqs installed on system pdt.daqfind() # create analog input using first daq installed on system ai = pdt.analog_input(samplerate=sample_rate) # create a counter output to generate a pwm signal co = pdt.counter_output(frequency=pwm_freq) # start the pwm signal co.start() samples = ai.acquire(num_samples) #optional command to create figure 1(default=1) plt.figure(1) #optional command to create a subplot(default=111) plt.subplot(211) # calculate estimated acquisition time in milliseconds acqTime = (float(num_samples) / sample_rate) * 1000 # linspace(start, stop, number of steps)
sample_rate = 44100 num_samples = sample_rate / 10 # 100ms of data # let pydaqtools find daqs installed on system pdt.daqfind() # get an analog output from the sound card speakers = pdt.analog_output(daqid=daqid, channel=(0)) # output a 1kHz sin wave speakers.output_sin(freq=1000) # give it a second to start outputting on the speakers time.sleep(1) # grab the default microphone microphone = pdt.analog_input(daqid=daqid, channel=0, samplerate=sample_rate) # acquire a seconds worth of samples samples = microphone.acquire(num_samples) # stop the sound card from outputting speakers.stop() # calculate estimated acquisition time in milliseconds acqTime = (float(num_samples) / sample_rate) * 1000 # linspace(start, stop, number of steps) time = numpy.linspace(0, acqTime, num_samples) # plot all the data plt.subplot(2, 1, 1)