Hello
I acquire with a NI PCI-4454 board and I need to acquire
data with high frequency (above 20kHz) for several
minutes; I would also like to plot the data (at least one
per second) while acquiring them.
Is it possible?
At first I tried with this cicle:
for i=1:NumberOfMeasures
tic
start(ai);
trigger(ai);
data=getdata(ai);
MeanValue(i)=mean(data);
plot(MeanValue);
t=toc;
end
The problem is that the toc time is about 0.3 seconds,
that is too much to acquire fast-changing potentials...
but if I use a unique acquisition I cannot make it last
more than few minutes, because the number of data acquired
is too big!
Is there a solution?
Sorry I posted the same message 5 times, but it seemed the
connection didn't work!
Davide B.
"Davide Borelli" <davidepub@microonda.net> wrote in
message <fj60m2$p81$1@fred.mathworks.com>...
> Hello
> I acquire with a NI PCI-4454 board and I need to acquire
> data with high frequency (above 20kHz) for several
> minutes; I would also like to plot the data (at least
one
> per second) while acquiring them.
> Is it possible?
> At first I tried with this cicle:
>
> for i=1:NumberOfMeasures
> tic
> start(ai);
> trigger(ai);
> data=getdata(ai);
> MeanValue(i)=mean(data);
> plot(MeanValue);
> t=toc;
> end
>
> The problem is that the toc time is about 0.3 seconds,
> that is too much to acquire fast-changing potentials...
> but if I use a unique acquisition I cannot make it last
> more than few minutes, because the number of data
acquired
> is too big!
> Is there a solution?
>
> Than you
> Davide B.
"Davide Borelli" <davidepub@microonda.net> wrote in message
<fj60ps$qi6$1@fred.mathworks.com>...
> Sorry I posted the same message 5 times, but it seemed
the
> connection didn't work!
> Davide B.
Yes, sorry again, I did not do it on purpose.
Davide B.
"Davide Borelli" <davidepub@microonda.net> wrote in
message <fj60m2$p81$1@fred.mathworks.com>...
> Hello
> I acquire with a NI PCI-4454 board and I need to acquire
> data with high frequency (above 20kHz) for several
> minutes; I would also like to plot the data (at least
one
> per second) while acquiring them.
> Is it possible?
> At first I tried with this cicle:
>
> for i=1:NumberOfMeasures
> tic
> start(ai);
> trigger(ai);
> data=getdata(ai);
> MeanValue(i)=mean(data);
> plot(MeanValue);
> t=toc;
> end
>
> The problem is that the toc time is about 0.3 seconds,
> that is too much to acquire fast-changing potentials...
> but if I use a unique acquisition I cannot make it last
> more than few minutes, because the number of data
acquired
> is too big!
> Is there a solution?
>
> Than you
> Davide B.
"Davide Borelli" <davidepub@microonda.net> wrote in message
<fj6223$af1$1@fred.mathworks.com>...
> Yes, sorry again, I did not do it on purpose.
> Davide B.
There are a few things you can do here to decrease your
cycle time:
- Pre-allocate your MeanValue array (zeros, NaNs,
whatever). This will have a huge effect on speed and will
prevent your loop from slowing down over time.
- Set up your plot outside of the loop and store a handle
to it: h=plot(MeanValue); Now modify the handle's ydata in
the loop rather than replotting. I don't have ML today so
can't test it - you may need to set the erasemode and/or
use drawnow to refresh the plot.
Ok, thank you to everyone, I don't know Matlab very well,
so it will keep me some days to test your suggestion.
I have a question: what is the difference between this
type of data acquisition (the one I use in my m-file) and
the audio acquisition with a soundcard? I mean: with a
normal soundcard and a common audio acquisition program I
can acquire data at 44kHz for several minutes without
stopping, and plotting them in real time; is it possible
to do that with my pci4454?
Thank you.
Davide B.
Yes, I already use the acquisition toolbox to acquire with
Matlab.
My question was different: which kind of code should I use
to make a continuous acquisition like the one you make
with a soundcard? I would like to see the structure of a
program designed for a continuous acquisition like that,
because I have a m-file which doesn't allow to make
continuous acquisition, but several very short (and
possibly fast) acquisition.
Davide B.
"Lars Warmbold" <mustermann.klaus.TO.REMOVE@gmx.de> wrote
in message <fjb0ua$cfc$1@fred.mathworks.com>...
> If the hardware is supported by the daq-toolbox yes. Use
> provided code and replace
>
> %% create 'LineIn'
> > ai = analoginput('winsound');
> > chan = addchannel(ai,1);
>
> by something like
>
> %% create 'LineIn'
> > ai = analoginput('nidaq', 1);
> > chan = addchannel(ai,0);
>
> See also
>
> >> help daq
>
> To see if Matlab recognizes your hardware you can check
out
>
> >> hw = daqhwinfo;
> >> hw.installedadapters
>
> Note that you may need the traditional NIdaq-driver.
>
> If you like infinite length of aqcuisition it is very
> usefull to implement your programm as a GUI.
>
> >> help guide
>
> LARS
"Davide Borelli" <davidepub@microonda.net> wrote in message
<fjbaqs$mu0$1@fred.mathworks.com>...
> Yes, I already use the acquisition toolbox to acquire with
> Matlab.
> My question was different: which kind of code should I use
> to make a continuous acquisition like the one you make
> with a soundcard? I would like to see the structure of a
> program designed for a continuous acquisition like that,
> because I have a m-file which doesn't allow to make
> continuous acquisition, but several very short (and
> possibly fast) acquisition.
> Davide B.
>
I don't understand your Problem, cause the provided code
does exactly what you want. Just replace
>> pause(5)
>> stop(ai)
by some other control (i.E. stop button in GUI) or remove them.
Once you started 'ai' it runs infinitely. You can also type
>> stop(ai)
into the command window when aqcuisition is done.
The code I provided plots the data and deletes them. If you
want to store them, you should look after the log to disk
mode of analoginput.
LARS
Ok, thank you, I had not read carefully your previous
answer to my post. I will try with the two separate .m
file (just a curiosity: what is the difference between
making two different files and putting that in two
different functions in the same file?).
Thank you very much
Davide B.
"Lars Warmbold" <mustermann.klaus.TO.REMOVE@gmx.de> wrote
in message <fjbgs7$ggp$1@fred.mathworks.com>...
> "Davide Borelli" <davidepub@microonda.net> wrote in
message
> <fjbaqs$mu0$1@fred.mathworks.com>...
> > Yes, I already use the acquisition toolbox to acquire
with
> > Matlab.
> > My question was different: which kind of code should I
use
> > to make a continuous acquisition like the one you make
> > with a soundcard? I would like to see the structure of
a
> > program designed for a continuous acquisition like
that,
> > because I have a m-file which doesn't allow to make
> > continuous acquisition, but several very short (and
> > possibly fast) acquisition.
> > Davide B.
> >
>
> I don't understand your Problem, cause the provided code
> does exactly what you want. Just replace
>
> >> pause(5)
> >> stop(ai)
>
> by some other control (i.E. stop button in GUI) or
remove them.
>
> Once you started 'ai' it runs infinitely. You can also
type
>
> >> stop(ai)
>
> into the command window when aqcuisition is done.
>
> The code I provided plots the data and deletes them. If
you
> want to store them, you should look after the log to disk
> mode of analoginput.
> LARS
I made it!
Now I have another problem: I want to acquire 100 samples
(at 50000 samples per second) and plot the mean values.
I tried this code for the update_plot.m file:
function update_plot(dummy1,dummy2,handles)
% GET ACQUIRED DATA FROM ai-OBJECT
data=getdata(handles.ai,handles.SamplesNumber);
Media=mean(data);
handles.Volt(:)=Media;
%PLOT DATA IN THE GUIDE WINDOW
axes(handles.PlotChannel);
plot(handles.Volt);
but every time I run the program I see handles.Volt is not
a vector with increasing dimension but a 1x1 vector, i.e.
a scalar. How can I do to make the update_plot.m file to
keep de data in an array, in order to save it in a file at
the end of the measure?
Thank you
Davide B.
"Davide Borelli" <davidepub@microonda.net> wrote in
message <fjbr8b$qi7$1@fred.mathworks.com>...
> Ok, thank you, I had not read carefully your previous
> answer to my post. I will try with the two separate .m
> file (just a curiosity: what is the difference between
> making two different files and putting that in two
> different functions in the same file?).
> Thank you very much
> Davide B.
>
>
> "Lars Warmbold" <mustermann.klaus.TO.REMOVE@gmx.de>
wrote
> in message <fjbgs7$ggp$1@fred.mathworks.com>...
> > "Davide Borelli" <davidepub@microonda.net> wrote in
> message
> > <fjbaqs$mu0$1@fred.mathworks.com>...
> > > Yes, I already use the acquisition toolbox to
acquire
> with
> > > Matlab.
> > > My question was different: which kind of code should
I
> use
> > > to make a continuous acquisition like the one you
make
> > > with a soundcard? I would like to see the structure
of
> a
> > > program designed for a continuous acquisition like
> that,
> > > because I have a m-file which doesn't allow to make
> > > continuous acquisition, but several very short (and
> > > possibly fast) acquisition.
> > > Davide B.
> > >
> >
> > I don't understand your Problem, cause the provided
code
> > does exactly what you want. Just replace
> >
> > >> pause(5)
> > >> stop(ai)
> >
> > by some other control (i.E. stop button in GUI) or
> remove them.
> >
> > Once you started 'ai' it runs infinitely. You can also
> type
> >
> > >> stop(ai)
> >
> > into the command window when aqcuisition is done.
> >
> > The code I provided plots the data and deletes them.
If
> you
> > want to store them, you should look after the log to
disk
> > mode of analoginput.
> > LARS
>
You need more than one set of samples.
Create an array lets say handles.myarray = zeros(10,
length_N) and a counter (say handles.counter=1) in the
openingFcn.
now you can compute insight the update_plot - routine
(It works like a register...) the following:
% write fresh data in selected row of myarray
handles.myarray(handles.counter, :)=getdata(handles.ai);
% compute mean of myarray
toPlot = mean(handles.myarray)
% increment lineselection
handles.counter = handles.counter+1;
% register full, overwrite from first row
if handles.counter==10
handles.counter = 1;
end
note that you must insert
>> handles = guidata(handles.figure1);
at the beginning of update_plot and
>> guidata(handles.figure1, handles);
at the end of update_plot since handles are sent to
update_plot only at initiation of function as
SamplesAcquiredFcn which you did in openingFcn.
An example of mine looks loke this (slightly shortened):
Thank you very much, it works greatly!
After two or three minutes it tells me an error:
DataMissed event occurred for the object: nidaq-AI
Is it a problem I should be able to sove with BufferingConfig and daqmem? Or I
need some other skill? I have a 2GHz Pentium pc with only 220Mb of RAM.
Another question: I make my program to save data files every 3*10^6 samples,
that means every minute (I get 50000samples per sec), in order not to have too
huge files (every file is about 47MB). Is there a way to have smaller data files
without stopping and restarting the daq board every minute? I don't loose much
time, just 0,2 sec, but I'd like to make a "more continuous" acquisition!
Anyway, I am vey happy just like that!
Thank you again
Davide B.
Sounds like your hardware 'runs dry' of input-data while
performing some other tasks (i.E. saving a file). In this
case 'getdata' causes an error because nothing is to get. If
you don't really need every single sample find out about the
use of 'peekdata' rather than 'getdata'. A (very
unintelligent) solution could also be to use try/catch.
In my opinion you should find out about the 'LogToDisk' and
'LoggingMode' properties of your hardware to avoid the
discontinuity while performing the daq. Just doubleclick the
AI in workspacebrowser and find out about what can be set in
your special hardware.
If this doesn't help:
There is a specialist around here in this forum. His name is
Rob Purser. Go to his newsreader page and contact him. He
always really helped me a lot.
The hardware is set to the "Disk&Memory" logging mode.
The great majority f the samples are stored in a file, I
use peekdata to acquire some samples just to plot some
data in order to see what's happening while measuring: I
don't plot every sample.
I noticed that error occurs when I run other application
than Matlab (Internet Explorer, for example), while my
program can run for several minutes if I close every other
application: so, the problem is not too big, I can acquire
my data without listening to music with iTunes! I'd just
like to understand better how my hardware works.
Thank you a lot
Davide B.
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.