image thumbnail

EXPO 2011 Signal Processing Workflow Demo Files

by

 

MATLAB EXPO 2011 Signal Processing Workflow Demo Files

hardware_daq.m
%% I[fBIC^[tF[X𗘗p^EĐ
clear all, close all

%% gK𗘗pM
Thresh = 0.6;
Trigger = 1	% 1:Software Trigger, 0:Immediate
duration = 5;
sampleRate = 22050;
ai = analoginput('winsound');
ch = addchannel(ai, 1);  

set(ai, 'SampleRate',sampleRate)
get(ai, 'SamplesPerTrigger')
requiredSamples = floor(sampleRate * duration);
set(ai, 'SamplesPerTrigger', requiredSamples); 

% gKݒ
if Trigger	% Software Triggger
	set(ai,'TriggerChannel',ch)
	set(ai,'TriggerType','Software')	% \tggK
% 	set(ai,'TriggerType','Immediate')	% gK
	set(ai,'TriggerCondition','Rising')
	set(ai,'TriggerConditionValue',Thresh)
end
% The best practice is to use the |wait| command before bringing the data in 
% to MATLAB(R). Set the duration of the |wait| command to be more than the 
% actual duration of the acquisition. This ensures that the object has 
% sufficient time to acquire the data even with system overhead with object
% setup and triggering. The recommended wait time is 110% of the duration 
% +0.5 seconds. The |wait| function returns to MATLAB as soon as the 
% acquisition completes and does not pause execution for the whole waitTime.
waitTime = duration * 1.1 + 1.5
%% Acquisition and Plot
start(ai)
wait(ai, waitTime);
% Get Data
[data, time] = getdata(ai);
% Plot the data acquired in MATLAB
figure;
plot(time,data);
xlabel('Time (s)');  % Setting up the xlabel
ylabel('Signal (Volts)'); % Setting up the ylabel
title('Data Acquired using Microphone'); % Setting up the title
grid on;


%% Clear input
delete(ai);
clear ai; 
daqreset

Contact us