Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Thread Subject:
continuous real time acquisition

Subject: continuous real time acquisition

From: Yeelin Chong

Date: 20 Feb, 2008 14:42:02

Message: 1 of 4


I am currently doing a project which require to acquire
data real time in the mean time display it and do
processing as well...

However, I am only able to do real time acquisition and
display the results in specified time as I have
initialized earlier.. while all the data obtained is
processed offline...

my script is as below
AI = analoginput('nidaq','Dev1');
duration = 10; % Ten second acquisition
chan = addchannel(AI,0,'channel1');
ActualRate = get(AI,'SampleRate');
preview = duration*ActualRate/10;

P = plot(zeros(preview,1));
grid on
title('Preview Data')
ylabel('Signal Level (Volts)')

while AI.SamplesAcquired < preview
while AI.SamplesAcquired < duration*ActualRate
data = peekdata(AI,preview);

data = getdata(AI);

grid on
title('All Acquired Data')
ylabel('Signal level (volts)')

[data,time] = daqread('try1.daq');
fs = 10000; %Sampling rate
mav = abs(data) / fs; % mean absolute value
%mav = data / fs;
yy = smooth(mav,63,'moving');
grid on
title('MAV Data')
xlabel('Time (s)')
ylabel('Voltage (V)')


Can anyone help me on this? i wish to make all the
acquisition, display and data process real time and
continue until a stop command is instructed..

I am desperately looking an alternative to solve this
problem. I will be grateful if anyone can help me..
Thanks in advance...

Subject: continuous real time acquisition

From: Rob Purser

Date: 21 Feb, 2008 18:44:03

Message: 2 of 4

I'm not really following. What's preventing you from using
GETDATA instead of PEEKDATA while you're acquiring, and
doing the processing right then?


Subject: continuous real time acquisition

From: pascal

Date: 19 Apr, 2012 14:14:15

Message: 3 of 4

I am having excacly the same problem. I can configure the channels from my data aquisition card, but on the matlab guide's I can't find how to KEEP measuring until I say that matlab can stop measuring. I've tried several things for weeks and I just can't get this to work. Can somebody please help???
Maybe it has something to do with the duration tag, or must I make a loop of somekind?
Thanks in advance, greetz pascal

Subject: continuous real time acquisition

From: pascal

Date: 27 Apr, 2012 11:15:16

Message: 4 of 4

I have 2 m-files who can make this happen

M-file 1
% first *.m-file
 function plotaqcuiredata

N = 7000;
SampRate= 44100;
%% Create Plot
hPlot = plot(zeros(1, N));
axis([0 inf -0.002 0.002]);
xlabel('Time (s)')
ylabel('Signal (Volts)')
grid on;

%% create 'LineIn'
ai = analoginput('mwadlink');
chan = addchannel(ai,0);

handles.N = N; = ai;
handles.hPlot = hPlot;

%% config LineIn
set(ai,'SampleRate' , SampRate);
set(ai,'SamplesPerTrigger' , inf);
set(ai,'SamplesAcquiredFcnCount', N);
set(ai,'SamplesAcquiredFcn' ,{@update_plot, handles});

I=input('druk op 1 en enter om de meting te starten: ');
if I==1
    while I==1
        L=input('Meting stoppen...? druk op 2: ');
        if L==2;

M-file 2
function update_plot(hObject, eventdata, handles)

%% get aqcuired data from ai-Object
data = getdata(,handles.N);
%% try also
%data = peekdata(,handles.N);

%% plot data

%% ---------- End --%

Just fill in your card instead of 'mwadlink'

The only thing I can't get to manage is to keep this program running. I mean everytyme I press 1 is starts en 2 it stops, 1 again and start, 2 again to stop. etc.

I think I have to make an other loop then this one.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us