Borrar filtros
Borrar filtros

Generating two different frequencies with NI-DAQ 6251 Analog output

2 visualizaciones (últimos 30 días)
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!

Respuesta aceptada

Walter Roberson
Walter Roberson el 9 de Nov. de 2011
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 comentarios
signal
signal el 9 de Nov. de 2011
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?
Walter Roberson
Walter Roberson el 9 de Nov. de 2011
I think the latter should be possible, but I do not know for sure.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by