Sampling rate error with DAQ?

8 views (last 30 days)
Osheen
Osheen on 18 Mar 2013
Hello,
I have the following code to record and display two audio channels from a microphone array. I am using a MCC DAQ which has an aggregated sampling rate of 500kHz and the FIFO buffer can hold up to 4kS of data. The DAQ continuously samples and stores data in the FIFO buffer until the scan is stopped. I get the following error:
Error using daq.analoginput_mcc_1_1/start
MCC: The maximum continuous-mode sample rate has been exceeded.
The total points acquired cannot be greater than FIFO size.
See device specifications for more information.
Error in daqdevice/start (line 62)
start( daqgetfield(obj,'uddobject') );
Error using drawnow
Error while evaluating uicontrol Callback
Error using daq.analoginput_mcc_1_1/peekdata
PEEKDATA may only be called once after stopping.
Error in analoginput/peekdata (line 75)
data = peekdata(uddobj, varargin{:});
Error in AI (line 222)
aidata=peekdata(ai,4000);
The code wont allow the sampling rate to be greater than 4kHz since the FIFO is limited to 4kS. Is there way to empty the FIFO buffer through MatLab so I can continuously sample? When i run a simple code i am able to use 30000khz.
i have a microphone attached to my DAQ and am not able to attain a clear sound.
my code and and the simple code are both as follows:
---------------------------------------------------
%ARRAY RECORDER & LOCALIZER
%==========================================================================
%CREATE NEW FIGURE
%==========================================================================
clear all
f=figure(1);
set(f, 'units', 'normalized','position', [.1 .1 .8 .8]);
%UICONTROLS
%==========================================================================
%uicontrol initial values
stopnow=0; %stops oscilloscope
beginmonitoring=0; %starts while loop to allow data monitoring
beginrecording=0; %starts the recording
PrevData1=[]; %sets initial dataset for oscilloscope loop
i=0; %initiates counter for wavefile naming and source location estimates
Samprate=4000; %sets sample rate for ai and localization programs
sigtime=[]; %initializes matrix of captured signals and associated times
%ui functions
%============
%stop ui
stopper= ['stopnow=1;', 'stop([ai]);', 'set(stopbutton,''Enable'',''off'',', '''ForegroundColor'',[.6 .6 .6]),','set(processorbutton,''Enable'',''on'',','''ForegroundColor'',[0 0 0]),','set(recorderbutton,''Enable'',''off'',', '''ForegroundColor'',[.6 .6 .6]);']; %makes ui font grey
%monitor ui
monitor= ['beginmonitoring=1;', 'start([ai]);','set(monitorbutton,''Enable'',''off'',','''ForegroundColor'',[.6 .6 .6]),', 'set(stopbutton,''Enable'',''on'',', '''ForegroundColor'',[0 0 0]),','set(recorderbutton,''Enable'',''on'',', '''ForegroundColor'',[0 0 0])']; %makes ui font black
%recorder ui
recorder=['beginrecording=1;', 'trigger([ai]);', 'tic;','set(recorderbutton,''Enable'',''off'',', '''ForegroundColor'',[.6 .6 .6]);']; %makes ui font grey
%processor ui
processor= ['locsignals=passiveloc(i,Samprate,gridax,mpos,c,srchwin,powrez,rez,fov,spma);','siginfo={locsignals(:,:) sigtime(:,1)};', 'save(''C:\Users\Zubair Kharadi\Desktop\Files\siginfo.mat'', ''siginfo'');', 'set(processorbutton,''Enable'',''off'')'];
%uicontrol definition
%====================
%stopbutton
stopbutton=uicontrol('Style', 'pushbutton', 'units','normalized', 'String', 'Stop', 'Position', [.81 .95 .05 .04],'Enable','off','Fontname','SansSeriff','Fontsize',10,'callback',stopper); %callback stopper ui when button is clicked
%beginmonitorbutton
monitorbutton=uicontrol('Style', 'pushbutton','units','normalized', 'String', 'Begin monitoring', 'Position', [.53 .95 .14 .04], 'Fontname','SansSeriff', 'Fontsize',10, 'callback',monitor);
%beginrecordingbutton
recorderbutton=uicontrol('Style', 'pushbutton', 'units','normalized', 'String', 'Begin recording', 'Position', [.68 .95 .12 .04], 'Enable','off', 'Fontname','SansSeriff', 'Fontsize',10, 'callback',recorder);
%processbutton
processorbutton=uicontrol('Style', 'pushbutton','units','normalized', 'String', 'Process', 'Position', [.87 .95 .1 .04], 'Enable','off', 'Fontname','SansSeriff', 'Fontsize',10, 'callback',processor);
%AI
%==========================================================================
%AI General
%==========
%AI device definitions
%add daq
daqregister('mcc')
ai = analoginput('mcc', 0);
%AI Properties
%=============
%Add channels to ai
ach1= addchannel(ai,0:8,{'ch11','ch12','ch13','ch14','ch15','ch16','ch17','ch18','ch19'});
% Configure the analog input parameters
set(ai,'SampleRate',4000)
% Configure the AI object to trigger manually
set(ai,'SamplesPerTrigger',inf)
set(ai, 'TriggerRepeat',inf)
set(ai, 'TriggerType', 'Manual')
%GUI
%==========================================================================
%Oscilloscope
%============
%Initialize the plots
%===================
%Channel 1 plot
sp11=subplot(2,2,1); %create subplot from a set of 4 rows and 2 columns
p11=plot(zeros(4000,1),'w'); %plot an initial set of data to prime scope
grid on; %set a grid on the subplot
ylabel('Mic 1'); %set ylabel
title('9-channel Oscilloscope') %set label for first column of subplots
set(get(sp11,'YLabel'),'Rotation',0); %rotate ylabel to be horizontal
set(get(sp11,'YLabel'),'Position',[-10000 -.2 0]); %translate ylabel
set(get(sp11,'YLabel'),'Fontname','SansSeriff'); %set ylabel font
set(get(sp11,'XLabel'),'Fontname','SansSeriff'); %set xlabel font
set(sp11, 'XLim', [0 4000]); %set x axis limits
set(sp11,'XTickLabel',[]) %remove x-tick labels
set(sp11, 'YLim', [1 4]); %set y axis limits
set(sp11, 'color', [.1 .4 .2]); %set color for subplot to green
set(sp11, 'fontname', 'SansSeriff'); %sets font
%Channel 2 plot
sp12=subplot(2,2,3);
p12=plot(zeros(Samprate,1),'w');
grid on;
ylabel('Mic 2');
set(get(sp12,'YLabel'),'Rotation',0);
set(get(sp12,'YLabel'),'Position',[-10000 -.2 0]);
set(get(sp12,'YLabel'),'Fontname','SansSeriff');
set(get(sp12,'XLabel'),'Fontname','SansSeriff');
set(sp12, 'XLim', [0 4000]);
set(sp12,'XTickLabel',[])
set(sp12, 'YLim', [1 4]);
set(sp12, 'color', [.1 .4 .2]);
set(sp12, 'fontname', 'SansSeriff');
%Sound Localization Plot
%=======================
%Initialization constants
c=348; %speed of sound indoors
k=.0169333
%Microphone placement
%mic position format [x1 x2 x3 x4....x9; y1 y2 y3 y4.....y9; z1 z2 z3 z4...z9;]
mpos=[-k 0 k -k 0 k -k 0 k; -k -k -k 0 0 0 k k k; 0 0 0 0 0 0 0 0 0;]; %microphone positions
%mic field definition
corner1=[-k -k 0;]'; %first corner of field [x1 y1 z1]
corner2=[k -k 0;]';
corner3=[-k k 0;]'; %farthest corner of field [x4 y4 z4]
fov=[corner1 corner2 corner3]; %field in which mics are placed
%Localization parameters
rez=.01; %spatial resolution of pixels (m) for use in gridax
srchwin=.03; %time window for cross correlation
powrez=900; %power resolution for cross correlation
%create a grid of pixels with width and height of 'rez' meters
gridax = {[mpos(1,1):rez:mpos(1,end)], [mpos(2,1):rez:mpos(2,end)], [0]};
%Mic Array Plot
spma=subplot(4,2,[2 4 6 8]); %create a subplot for signal localization graph
plot(mpos(1,:),mpos(2,:),'sr','MarkerSize', 12); %plot mics on graph
axis equal %set axes equal in scale
%set axes limits 10% greater than actual limits
axis([mpos(1,1)*.1+mpos(1,1),mpos(1,end)*.1+mpos(1,end), mpos(2,1)*.1+mpos(2,1),mpos(2,end)*.1+mpos(2,end)]);
xlabel('Meters') %label x axis
set(get(spma,'XLabel'),'Fontname','SansSeriff');
ylabel('Meters') %label y axis
set(get(spma,'YLabel'),'Fontname','SansSeriff');
title(['SRP image (mics in red boxes, signal location in circle)']) %set title
set(get(spma,'Title'),'Fontname','SansSeriff');
set(spma, 'color', [0 0 0]); %set subplot background to black
set(findobj(spma,'type', 'text'), 'color', 'blue'); %set mic label font
%plot the incoming data for all graphs
set(f,'doublebuffer','on'); %allows graphics to animate smoothly
warning off all; %prevents warning messages about peekdata from showing
drawnow; %draws plots
%Oscilloscope, Recorder, Wavewriter loop
%==========================================================================
while (stopnow==0); %while stopnow value is 0 continue loop
if (beginmonitoring==1); %begin oscilloscope section of loop when begin = 1
aidata=peekdata(ai,4000);
if beginrecording==1 && toc>=10; %acquire data if >10s of data available
tic; %restart timer for next loop
%acquire available data in ai engines
[data1,time1,abstime1]=getdata(ai, ai.SamplesAvailable);
WholeData1=[PrevData1; data1 time1;]; %concatenate data from last iteration
%call 'extract wavefile' function to process sound data
[PrevData1,i,sigtime]=extractwavfl(WholeData1,Samprate,i,abstime1,sigtime);
end %if Beginrecording is set to 0
set(p11,'ydata',aidata(:,1)); %set plot11's ydata to ai channel 1 data
set(p12,'ydata',aidata(:,2)); %set plot12's ydata to ai channel 2 data
end %if Beginmonitoring is set to 0
drawnow; %updates plots
end %if stopnow is set to 1
try stop(ai); end; %stops ai if it hasn't already been stopped
delete(ai); %deletes ai
%==========================================================================
when i try a simpler code i am able to sample at 30000khz
---------------------------------------------------------
daqregister('mcc')
input = analoginput('mcc',1);
addchannel(input,0);
addchannel(input,1);
set(input,'SampleRate',30000)
set(input,'SamplesPerTrigger',1)
input.TriggerRepeat = inf;
plot_time = zeros(30,1);
data = zeros (30,2);
start(input)
for k = 1:300
[Y,X] = getdata(input);
plot_time(k,1) = X(1,1);
data(k,:) = Y(1,:);
plot(plot_time,data(:,1),'b*');
axis([0,4,-5,5])
hold on;
%plot(plot_time,data(:,2));
end
dataCH1 = data(:,1);
dataCH2 = data(:,2);
stop (input)
delete (input)
%------------------

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!