Why MATLAB does not acquire the right analog signal while LABVIEW does for the same connection?
Show older comments
Please see the simple code below to acquire an analogue sine wave with MATLAB DAQ toobox. I followed exactly many examples on matlab help and online but the acquired signal is not correct. To double check my connections. I used LABVIEW to acquire the same signal it worked perfectly. When I run the code below, MATLAB does acquire a sine wave with an offset of -4.377 V and a low peak to peak voltage. For example. The applied signal is a 100.8Hz sine wave with Vp-p=5.6V. Labview acquires the signal perfectly while MATLAB gives a sine wave signal with a correct frequency (100Hz) but with an offset of -4.377 and a peak to peak voltage of (0.377V)!
Thank you very much for your help!
Best,
mdaghrah
% This programme is to test the functionality of the analog input of the
% mcc PCI-DAS08
clear all
close all
% Step 1: Create object of the Analog Input subsystem
ai = analoginput ('mcc',0);
% Step 2: Create Input Channel
ch1 = addchannel (ai,0);
% Step 3: Configure property values
duration = 1; % 1 second acquisition
set(ai,'SampleRate',2000) % singal frequency is 200 Hz, way below.
ActualRate = get (ai,'SampleRate');
set(ai,'SamplesPerTrigger',duration*ActualRate)
set(ai,'TriggerType','Manual')
ai.ClockSource = 'Internal';
blocksize = get(ai, 'SamplesPerTrigger');
Fs = ActualRate;
% Step 4: Acquire Data
start(ai)
trigger(ai)
wait(ai,duration+1)
[data Time] = getdata(ai);
plot(Time, data);
grid on
% Step 5: Clean up
delete(ai)
clear ai
Answers (0)
Categories
Find more on Data Acquisition Toolbox Supported Hardware in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!