Generating two different frequencies with NI-DAQ 6251 Analog output
4 次查看(过去 30 天)
显示 更早的评论
Hi,
I want to use my DAQ as a function generator to generate two different frequencies continuously. A simple code like
ao= analogoutput(adaptor, deviceId);
addchannel(ao, 0:1);
nsample1 = freq1/sampling_rate
nsample2 = freq2/sampling_rate
wave1 = sin(linspace(0,2*pi,nsample1));
wave2 = sin(linspace(0,2*pi,nsample2));
set(ao,'RepeatOutput',inf);
putdata(ao,[wave1' wave2']);
won't work because [wave1' wave2'] are of different lengths. I can't pad any data to the end of the shorter wave because if the two frequencies are relatively prime, one of the would not be periodic.
Is there anyway around this?
Thanks!
0 个评论
采纳的回答
Walter Roberson
2011-11-9
You are not required to output to both channels simultaneously. If the job works better by separating the channels, do so. This might cause a lag between the two. If the lag gets to be too much, then adopt another method.
You can use lcm (Lowest Common Multiple) to determine how many of each side you need you would need to queue so that the queue would have full cycles for both waves.
2 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!