AnsweredAssumed Answered

Matlab and Simulink with Analog Discovery

Question asked by Deiv on Jun 23, 2013

Support for the Analog Discovery to be used as a Data Acquisition device with the Mathwork's Matlab is provided via a support package downloadable at the link below.


Here below is an example of how to use the Matlab with the Sessions-Based Interface.


But support for continuous sampling is not available !


My target was to continually sample a channel at low (8kHz) sample rate continually, make a real time digital signal processing with Simulink and send it to the AWG outputs.


1. Can someone help on how a low frequency continual sampling is possible?

2. Also how to use it in conjunction with the Simulink?


I tried out some code as below... This code continually updates the data samples every 100ms. It has flexible voltage ranging and also sampling.


% Repetitive data acquisition from Analog Discovery - Analog input Channel 1


time = 0.1;

rate = 32e3/time;

if rate > 1e6

    rate = 1e6;

    time = 32e3/rate;



xmin = 0;

xmax = time;


% Acquiring Code

ch1 = daq.createSession('digilent');

ch1.addAnalogInputChannel('AD1', 1, 'Voltage');

ch1.Rate = rate;

ch1.Channels.Range = [-25 25];

ch1.DurationInSeconds = xmax;


%[data, timestamps, triggerTime] = ch1.startForeground;

while true


    [data, timestamps, triggerTime] = ch1.startForeground;


    ymax = max(data);

    ymin = min(data);


    if(max(abs(ymax), abs(ymin)) <= 2.5)

        ch1.Channels.Range = [-2.5 2.5];


        ch1.Channels.Range = [-25 25];



    plot(timestamps, data, 'g');

    axis([xmin xmax ymin ymax]);



If this question is not to be addressed here, please advise if Mathworks or Digilent can help. Thanks.


- Deiv