Hi everyone,
I am using matlab to use an AI and an AO at the same time in a loop. I basically get the signal by PCI 6229 and send back the signal to the system by PXI-6133. The code below is the code I would like to use it for this reason. The code is working fine but it is so slow. I would like to use it in a close to the real time but its far away from being real time.
May I ask you to please guide me to how to speed up my code?
Best regards,
Mohammad
x=1:1000;
y=sin(x);
AI = analoginput('nidaq','Dev1');
chan = addchannel(AI,0);
duration = 0.0005; %0.5ms second acquisition
set(AI,'SampleRate',1000)
ActualRate = get(AI,'SampleRate');
blocksize = get(AI,'SamplesPerTrigger');
Fs = ActualRate;
AO = analogoutput('nidaq','Dev4');
chan_o = addchannel(AO,0);
set(AO,'SampleRate',1000);
rampR=zeros(500,1); %% ramp rise
rampF=zeros(500,1); %% ramp fall
set([AI AO],'TriggerType','Manual')
AI.ManualTriggerHwOn = 'Trigger';
for j=1:50,
a(j)=0.04*j;
end
while (1)
previous_pos=0;
for i=0:49
slope=round(49*rand)+1;
rampR (10*i+1:10*i+10) = previous_pos+a(slope)*[1:10];
previous_pos=rampR (10*i+10);
end
rampR=rampR/max(rampR);
ramp=[rampR;rampR];
putdata(AO,ramp)
start([AI AO])
trigger([AI AO])
data = getdata(AI);
[f,mag] = daqdocfft(data,Fs,blocksize);
mag1=max((10.^(mag/10))/1000000)
end
delete(AI)
clear AI
delete(AO)
clear AO
|