Escolar Documentos
Profissional Documentos
Cultura Documentos
Purpose
To sample analog data from one or more A/D channels at a specified frequency and specified duration
Setup
Select channels
Before making a call to perform the conversion, you have to decide on which channels you want to sample. You should set up a vector indicating the desired channels. For example, if you want to sample channels AD1 and AD3, you should create the vector [1,3]. It may be advantageous to create a variable and set its value to the vector. A typical matlab command would be:
Duration = 3
The duration and frequency must satisfy the constraint Freq * Duration <=1000. In other words, you can not obtain more than 1000 samples per channel in any A/D conversion.
Source Code
function [y, t] = a2d(chnl, freq, duration) %A2D % % [y, t] = a2d(chnl, freq, duration) % % Perform A/D conversion at a specified frequency for a specified duration. % The frequency is in samples per second and duration in seconds % % Default values: % chnl: 0 % freq: 100 % duration: 1000/freq % % This function returns % y: Analog signal that is measured % t: Time vector % % Examples % % [y, t] = a2d; % scans A/D channel #0 at 100 samples per second for 3 seconds % % [y, t] = a2d(3, 75, 2); % scans A/D channel #3 at 75 samples per second for 2 seconds % % [y, t] = a2d([1,3], 75, 2); % scans A/D channels #1 and #3 at 75 samples per second for 2 seconds % Note: y will have two columns corresponding to channels 1 and 3 % % scan_data: data in channels 0, 1, ... chnl % Number of columns in scan_data is 1 more than chnl % The first column is the data in channel #0 % The second column is the data in channel #1 % etc. % %
% Author: N. Narasimhamurthi % if nargin < 1 chnl = 0; end if nargin < 2 freq=100; end if nargin < 3 duration = 1000/freq; end chrange = 0:max(chnl); craw=vscan(chrange, ones(1, max(chrange)+1), freq, duration); y=craw(:,chnl+1); t = 1:length(y); t=t(:)-1; t=t / freq;