这是我的代码:
clc;
clear all;
clc;
s = daq.createSession('ni');
s.addAnalogOutputChannel('Dev1',0,'Voltage');
s.IsContinuous = true;
fs=1000;
quality= 15;
fd=48000;
fs= fd * quality;
s.Rate = fs;
n=1;
A= 2;
y1=0;
y2=0;
wo= 2*pi*(fd/fs);
x=A*sin(wo);
pcos= 2*cos(wo);
out = [];
tic();
while(n<=quality),
y= ((x)+(pcos*y1)-(y2));
y2=y1;
y1=y;
out(n,1) = y+2.1;
x=0;
n=n+1;
end
toc()
plot(out,'*r');
grid on;
s.NotifyWhenScansQueuedBelow = lim;
lh = addlistener(s,'DataRequired', ...
@(src,event) src.queueOutputData(out)); % Here is the delay
queueOutputData(s,out)
startBackground(s);