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

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

hello,

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
%set(AI,'InputType','Differential')
set(AI,'InputType','SingleEnded')
chan = addchannel(AI,0,'channel1');
set(AI,'LoggingMode','Disk&Memory')
set(AI,'LogFileName','try1.daq')
set(AI,'SampleRate',1000)
ActualRate = get(AI,'SampleRate');
set(AI,'SamplesPerTrigger',duration*ActualRate)
%set(AI,'SamplesPerTrigger',inf)
preview = duration*ActualRate/10;


figure
subplot(311)
set(gcf,'doublebuffer','on')
P = plot(zeros(preview,1));
grid on
title('Preview Data')
xlabel('Samples')
ylabel('Signal Level (Volts)')


start(AI)
while AI.SamplesAcquired < preview
end
while AI.SamplesAcquired < duration*ActualRate
data = peekdata(AI,preview);
set(P,'ydata',data)
drawnow
end


wait(AI,duration+1)
wait(AI,1)
data = getdata(AI);


subplot(312)
plot(data);
grid on
title('All Acquired Data')
xlabel('Samples')
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');
subplot(313)
plot(time,yy)
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?

-Rob

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
figure(1)
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;
handles.ai = 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
    start(ai)
    while I==1
        L=input('Meting stoppen...? druk op 2: ');
        if L==2;
            stop(ai)
            break
        end
    end
end

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


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

%% plot data
set(handles.hPlot,'YData',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