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!

采纳的回答

Walter Roberson
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 个评论
signal
signal 2011-11-9
Walter, thanks for your response!
The lcm method should work very well as long as the number of samples required is not larger than the onboard memory on the DAQ, I should test this.
Regarding your first suggestion, can you elaborate more? are you suggesting that I should define two separate analog outputs like
ao1 = analogoutput(adaptor, deviceId); addchannel(ao1, 0);
ao2 = analogoutput(adaptor, deviceId); addchannel(ao2, 1);
and queue them independently?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Call Web Services from MATLAB Using HTTP 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by