Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
DAQ change frequency while continously outputing sine wave

Subject: DAQ change frequency while continously outputing sine wave

From: Mike

Date: 10 Feb, 2012 05:18:10

Message: 1 of 2

I have an NI USB DAQ and I can continuously generate a signal. I need to be able to continuously generate a signal and change the frequency from when desired, while still generating a signal. I have not been able to figure out how to change the frequency without shutting down the output first. This is the code I use to continuously generate the data:

function [source, lh] = daqWvformControl(freq, signalVoltPk, squareWv, sampleRate, Dur)
source = daq.createSession('ni');
source.IsContinuous = true;
source.addAnalogOutputChannel('Dev1', 0, 'Voltage');

source.Rate = sampleRate; %in Hz

Npts = round(Dur*source.Rate);

x = (0:(Npts-1))/source.Rate;

data = signalVoltPk*sin(freq*2*pi*x); data=data(:);

if squareWv == 1;
    data(data < 0) = - signalVoltPk; % Convert sin wave to square wave
    data(data > 0) = signalVoltPk;
end
source.queueOutputData(data);
lh = source.addlistener('DataRequired', @(src, event)src.queueOutputData(data));
source.startBackground();

I know it is possible to continously generate the sine wave and also change the frequency of the output signal from the forums, but I have not found the method with matlab... I'd think it is something in changing the queueOutputData, but I can't seem to get that to work... I also need to do it with amplitude, but I imagine the methods will be related.

Thanks for the help

Subject: DAQ change frequency while continously outputing sine wave

From: Rune

Date: 19 Mar, 2013 14:19:11

Message: 2 of 2

I am facing the same problem as you, did you find any solution as how to continuosly change the output signal without stopping it?

"Mike" wrote in message <jh29ai$7jj$1@newscl01ah.mathworks.com>...
> I have an NI USB DAQ and I can continuously generate a signal. I need to be able to continuously generate a signal and change the frequency from when desired, while still generating a signal. I have not been able to figure out how to change the frequency without shutting down the output first. This is the code I use to continuously generate the data:
>
> function [source, lh] = daqWvformControl(freq, signalVoltPk, squareWv, sampleRate, Dur)
> source = daq.createSession('ni');
> source.IsContinuous = true;
> source.addAnalogOutputChannel('Dev1', 0, 'Voltage');
>
> source.Rate = sampleRate; %in Hz
>
> Npts = round(Dur*source.Rate);
>
> x = (0:(Npts-1))/source.Rate;
>
> data = signalVoltPk*sin(freq*2*pi*x); data=data(:);
>
> if squareWv == 1;
> data(data < 0) = - signalVoltPk; % Convert sin wave to square wave
> data(data > 0) = signalVoltPk;
> end
> source.queueOutputData(data);
> lh = source.addlistener('DataRequired', @(src, event)src.queueOutputData(data));
> source.startBackground();
>
> I know it is possible to continously generate the sine wave and also change the frequency of the output signal from the forums, but I have not found the method with matlab... I'd think it is something in changing the queueOutputData, but I can't seem to get that to work... I also need to do it with amplitude, but I imagine the methods will be related.
>
> Thanks for the help

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us