Created
November 7, 2011 18:09
-
-
Save jsnyder/1345697 to your computer and use it in GitHub Desktop.
data acquisition setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% ME224 Basic Data Output Script | |
try | |
stop(ai); delete(ai); | |
catch | |
end | |
% Settings | |
Fsi = 1000; % input sample rate | |
time_length = 1; % length of time to capture samples (seconds) | |
samples = time_length*Fsi; % How many samples to get | |
channels = 0; % Channels to get data on | |
% Get Handle for Analog Output Device | |
mccdaqinfo = daqhwinfo('mcc'); | |
mccdaqids = find(ismember(mccdaqinfo.BoardNames,'USB-1208FS')==1); | |
% Create AO and AI handles | |
ai = analoginput('mcc', mccdaqinfo.InstalledBoardIds{mccdaqids(1)}); | |
addchannel(ai,channels,'in'); | |
set(ai,'SampleRate',Fsi); | |
set(ai,'SamplesPerTrigger',samples); | |
start(ai); | |
data = getdata(ai,samples); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% ME224 Basic Data Output Script | |
try | |
stop(ao); delete(ao); | |
catch | |
end | |
try | |
stop(ai); delete(ai); | |
catch | |
end | |
% Settings | |
Fso = 10000; % output sample rate | |
Fsi = 10000; % input sample rate | |
time_length = 5; % length of time to capture samples (seconds) | |
samples = time_length*Fsi; % How many samples to get | |
channels = 0; % Channels to get data on | |
% Get Handle for Analog Output Device | |
mccdaqinfo = daqhwinfo('mcc'); | |
mccdaqids = find(ismember(mccdaqinfo.BoardNames,'USB-1208FS')==1); | |
% Create AO and AI handles | |
ao = analogoutput('mcc', mccdaqinfo.InstalledBoardIds{mccdaqids(2)}); | |
ai = analoginput('mcc', mccdaqinfo.InstalledBoardIds{mccdaqids(1)}); | |
addchannel(ao,channels,'out'); | |
addchannel(ai,channels,'in'); | |
set(ao,'SampleRate',Fso); | |
set(ai,'SampleRate',Fsi); | |
set(ai,'SamplesPerTrigger',samples); | |
t = 0:1./Fso:time_length-1./Fso; | |
outdata = (chirp(t,0.1,time_length-0.3,500)+1)'; | |
putdata(ao, outdata); | |
start(ai); | |
start(ao); | |
[data time]= getdata(ai,samples); | |
flushdata(ai) % get rid of any queued data | |
figure(1); | |
[X,f] = myFFT(data - mean(data),Fsi); | |
[Xo,fo] = myFFT(outdata - mean(outdata),Fso); | |
plot(f,smooth(abs(X./Xo))); | |
set(gca,'xlim',[0 500]); | |
set(gca,'ylim',[0 3]); | |
xlabel('Frequency (Hz)') | |
ylabel('Vo/Vin') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [X,freq]=myFFT(x,Fs) | |
x = x'; | |
N = length(x); | |
if mod(N,2) | |
k = (-(N-1)/2):((N-1)/2); % if odd, use symmetrical k | |
else | |
k = (-N/2):((N-1)/2); % if even, one extra negative value | |
end | |
Tlen = N/Fs; | |
freq = k./Tlen; % scale k by time length to get frequencies | |
X=fft(x)./N; % scale fft by length | |
X=fftshift(X); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment