02-09-2012 11:33 PM
I have an NI USB-6351 DAQ and I can continuously generate a signal. I need to be able to continuously generate a signal and change the frequency 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 LABVIEW forums, but I have not found the method with matlab and I don't have labview..... 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
02-10-2012 12:56 PM
Hi MSUS,
You can post this to the MATLAB answers site as you are using Data Acquisition Toolbox in MATLAB.
-Manisha