Email: helpdesk@telkomuniversity.ac.id

This Portal for internal use only!

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • Visual Paradigm
  • IBM
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Office
      • Windows
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Categories
  • Microsoft
    • Microsoft Apps
    • Office
    • Operating System
    • VLS
    • Developer Tools
    • Productivity Tools
    • Database
    • AI + Machine Learning
    • Middleware System
    • Learning Services
    • Analytics
    • Networking
    • Compute
    • Security
    • Internet Of Things
  • Adobe
  • Matlab
  • Google
  • Visual Paradigm
  • WordPress
    • Plugin WP
    • Themes WP
  • Opensource
  • Others
More Categories Less Categories
  • Get Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • My Account
    • Download
    • Cart
    • Checkout
    • Login
  • About Us
    • Contact
    • Forum
    • Frequently Questions
    • Privacy Policy
  • Forum
    • News
      • Category
      • News Tag

iconTicket Service Desk

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • Visual Paradigm
  • IBM
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Office
      • Windows
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Menu
  • Home
    • Download Application Package Repository Telkom University
    • Application Package Repository Telkom University
    • Download Official License Telkom University
    • Download Installer Application Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • All Pack
    • Microsoft
      • Operating System
      • Productivity Tools
      • Developer Tools
      • Database
      • AI + Machine Learning
      • Middleware System
      • Networking
      • Compute
      • Security
      • Analytics
      • Internet Of Things
      • Learning Services
    • Microsoft Apps
      • VLS
    • Adobe
    • Matlab
    • WordPress
      • Themes WP
      • Plugin WP
    • Google
    • Opensource
    • Others
  • My account
    • Download
    • Get Pack
    • Cart
    • Checkout
  • News
    • Category
    • News Tag
  • Forum
  • About Us
    • Privacy Policy
    • Frequently Questions
    • Contact
Home/Matlab/Working with Real-Time signals in matlab

Working with Real-Time signals in matlab

/ 2025-01-07
Working with Real-Time signals in matlab
Matlab

I am trying to work with a real time signal witht the DSP Tool box but I am finding difficult to acomplish. I have seen the demos and read the documents related with the DSP Tool box but it doesn’t really seem Matlab can work/process real time signals. My objective was to do a DAC to create a signal, an ADC to read this same signal, process it, and then do another DAC to see the processed signal. I have been able to work out an ADC and a DAC but none of the options available (at least for the 2022a version) are actually real time but trying to simulate it.
I will share the code in case anyone has curiostity, but not only it fails when approaching the frequency too nyquist’s but also seems to have a hard time when the processing is just multiplying by two, can’t imagine what would happen if I modulated the signal…
%============================================================%
%============== Continuous Real Time DAC & ADC===============%
%============================================================%
%========= Processes Data and Displays it Real Time =========%
%========= DisplaySignalV5: More advanced processes ========%
%============================================================%
% REQUIRED: Signal Processing Toolbox & DSP System Toolbox (NI Extension)
clear;
close all;
clc;
% === DAC and ADC === %
% Create DataAcquisition object for NI device
dq = daq("ni");
% Add Analog Output Channels to generate the signal on "ao0" and "ao1"
addoutput(dq, "Dev1", "ao0", "Voltage");
addoutput(dq, "Dev1", "ao1", "Voltage");
ch_out = dq.Channels(1:2);
ch_out(1).Name = "ao0_out";
ch_out(2).Name = "ao1_out";
% Add an Analog Input Channel to acquire the signal on "ai1"
addinput(dq, "Dev1", "ai1", "Voltage");
ch_in = dq.Channels(3);
ch_in.Name = "ai1_in";
% Set the sample rate
rate = 10000; % Hz
dq.Rate = rate;
% Specify the output signal – A square wave with a DC offset
f = 50; % Frequency of 10 Hz
t = (0:rate-1)/rate; % Time vector for 1 second
output = 1.25 + 0.25*square(2*pi*f*t); % Generate square wave with DC offset
% Create timescope to visualize the signals in real time
scope = timescope(‘SampleRate’, rate, ‘TimeSpanSource’, ‘Property’, ‘TimeSpan’, 0.1, …
‘YLimits’, [-2 2], ‘Title’, ‘Output vs Input Signals’, …
‘ShowLegend’, true, ‘ChannelNames’, {‘Inintal Signal DAC_1’, ‘Processed Signal DAC_2’});
% Set the callback function to execute when data is available
batchSize = rate; % Read data for 1 second at a time for more frequent updates
dq.ScansAvailableFcnCount = batchSize;
dq.ScansAvailableFcn = @(src, evt) plotAndWriteSignals(src, output, scope, rate);
% Preload the output data for "ao0"
preloadData = [output’, zeros(length(output), 1)]; % Preload output for ao0, set ao1 to zero initially
preload(dq, preloadData);
% Start the output and input simultaneously in continuous mode
start(dq, "repeatoutput");
% Stop the generation and acquisition after key press
disp(‘Press any key to stop the continuous generation and acquisition.’);
pause();
stop(dq);
disp("Generation and acquisition stopped.");
% Callback function to read data, plot input and output using timescope, and write to ao1 in real-time
function plotAndWriteSignals(src, output, scope, rate)
% Read available data in chunks as defined by ScansAvailableFcnCount
[data, ~] = read(src, src.ScansAvailableFcnCount, "OutputFormat", "Matrix");

processedSignal = 2.*data;
% Ensure that both ‘data’ and ‘outputToPlot’ are column vectors and have the same length
len = length(processedSignal);
outputToPlot = output(1:len)’;

if isrow(processedSignal)
processedSignal = processedSignal’;
end
% Update the timescope with the output and input signals
% The input data and output data must have consistent row sizes
scope([outputToPlot, processedSignal]);
% Write the acquired input data to the output channel "ao1"
% Create a matrix where each row contains values for both output channels
outputData = [outputToPlot, processedSignal]; % First column for ao0, second column for ao1
write(src, outputData);
endI am trying to work with a real time signal witht the DSP Tool box but I am finding difficult to acomplish. I have seen the demos and read the documents related with the DSP Tool box but it doesn’t really seem Matlab can work/process real time signals. My objective was to do a DAC to create a signal, an ADC to read this same signal, process it, and then do another DAC to see the processed signal. I have been able to work out an ADC and a DAC but none of the options available (at least for the 2022a version) are actually real time but trying to simulate it.
I will share the code in case anyone has curiostity, but not only it fails when approaching the frequency too nyquist’s but also seems to have a hard time when the processing is just multiplying by two, can’t imagine what would happen if I modulated the signal…
%============================================================%
%============== Continuous Real Time DAC & ADC===============%
%============================================================%
%========= Processes Data and Displays it Real Time =========%
%========= DisplaySignalV5: More advanced processes ========%
%============================================================%
% REQUIRED: Signal Processing Toolbox & DSP System Toolbox (NI Extension)
clear;
close all;
clc;
% === DAC and ADC === %
% Create DataAcquisition object for NI device
dq = daq("ni");
% Add Analog Output Channels to generate the signal on "ao0" and "ao1"
addoutput(dq, "Dev1", "ao0", "Voltage");
addoutput(dq, "Dev1", "ao1", "Voltage");
ch_out = dq.Channels(1:2);
ch_out(1).Name = "ao0_out";
ch_out(2).Name = "ao1_out";
% Add an Analog Input Channel to acquire the signal on "ai1"
addinput(dq, "Dev1", "ai1", "Voltage");
ch_in = dq.Channels(3);
ch_in.Name = "ai1_in";
% Set the sample rate
rate = 10000; % Hz
dq.Rate = rate;
% Specify the output signal – A square wave with a DC offset
f = 50; % Frequency of 10 Hz
t = (0:rate-1)/rate; % Time vector for 1 second
output = 1.25 + 0.25*square(2*pi*f*t); % Generate square wave with DC offset
% Create timescope to visualize the signals in real time
scope = timescope(‘SampleRate’, rate, ‘TimeSpanSource’, ‘Property’, ‘TimeSpan’, 0.1, …
‘YLimits’, [-2 2], ‘Title’, ‘Output vs Input Signals’, …
‘ShowLegend’, true, ‘ChannelNames’, {‘Inintal Signal DAC_1’, ‘Processed Signal DAC_2’});
% Set the callback function to execute when data is available
batchSize = rate; % Read data for 1 second at a time for more frequent updates
dq.ScansAvailableFcnCount = batchSize;
dq.ScansAvailableFcn = @(src, evt) plotAndWriteSignals(src, output, scope, rate);
% Preload the output data for "ao0"
preloadData = [output’, zeros(length(output), 1)]; % Preload output for ao0, set ao1 to zero initially
preload(dq, preloadData);
% Start the output and input simultaneously in continuous mode
start(dq, "repeatoutput");
% Stop the generation and acquisition after key press
disp(‘Press any key to stop the continuous generation and acquisition.’);
pause();
stop(dq);
disp("Generation and acquisition stopped.");
% Callback function to read data, plot input and output using timescope, and write to ao1 in real-time
function plotAndWriteSignals(src, output, scope, rate)
% Read available data in chunks as defined by ScansAvailableFcnCount
[data, ~] = read(src, src.ScansAvailableFcnCount, "OutputFormat", "Matrix");

processedSignal = 2.*data;
% Ensure that both ‘data’ and ‘outputToPlot’ are column vectors and have the same length
len = length(processedSignal);
outputToPlot = output(1:len)’;

if isrow(processedSignal)
processedSignal = processedSignal’;
end
% Update the timescope with the output and input signals
% The input data and output data must have consistent row sizes
scope([outputToPlot, processedSignal]);
% Write the acquired input data to the output channel "ao1"
% Create a matrix where each row contains values for both output channels
outputData = [outputToPlot, processedSignal]; % First column for ao0, second column for ao1
write(src, outputData);
end I am trying to work with a real time signal witht the DSP Tool box but I am finding difficult to acomplish. I have seen the demos and read the documents related with the DSP Tool box but it doesn’t really seem Matlab can work/process real time signals. My objective was to do a DAC to create a signal, an ADC to read this same signal, process it, and then do another DAC to see the processed signal. I have been able to work out an ADC and a DAC but none of the options available (at least for the 2022a version) are actually real time but trying to simulate it.
I will share the code in case anyone has curiostity, but not only it fails when approaching the frequency too nyquist’s but also seems to have a hard time when the processing is just multiplying by two, can’t imagine what would happen if I modulated the signal…
%============================================================%
%============== Continuous Real Time DAC & ADC===============%
%============================================================%
%========= Processes Data and Displays it Real Time =========%
%========= DisplaySignalV5: More advanced processes ========%
%============================================================%
% REQUIRED: Signal Processing Toolbox & DSP System Toolbox (NI Extension)
clear;
close all;
clc;
% === DAC and ADC === %
% Create DataAcquisition object for NI device
dq = daq("ni");
% Add Analog Output Channels to generate the signal on "ao0" and "ao1"
addoutput(dq, "Dev1", "ao0", "Voltage");
addoutput(dq, "Dev1", "ao1", "Voltage");
ch_out = dq.Channels(1:2);
ch_out(1).Name = "ao0_out";
ch_out(2).Name = "ao1_out";
% Add an Analog Input Channel to acquire the signal on "ai1"
addinput(dq, "Dev1", "ai1", "Voltage");
ch_in = dq.Channels(3);
ch_in.Name = "ai1_in";
% Set the sample rate
rate = 10000; % Hz
dq.Rate = rate;
% Specify the output signal – A square wave with a DC offset
f = 50; % Frequency of 10 Hz
t = (0:rate-1)/rate; % Time vector for 1 second
output = 1.25 + 0.25*square(2*pi*f*t); % Generate square wave with DC offset
% Create timescope to visualize the signals in real time
scope = timescope(‘SampleRate’, rate, ‘TimeSpanSource’, ‘Property’, ‘TimeSpan’, 0.1, …
‘YLimits’, [-2 2], ‘Title’, ‘Output vs Input Signals’, …
‘ShowLegend’, true, ‘ChannelNames’, {‘Inintal Signal DAC_1’, ‘Processed Signal DAC_2’});
% Set the callback function to execute when data is available
batchSize = rate; % Read data for 1 second at a time for more frequent updates
dq.ScansAvailableFcnCount = batchSize;
dq.ScansAvailableFcn = @(src, evt) plotAndWriteSignals(src, output, scope, rate);
% Preload the output data for "ao0"
preloadData = [output’, zeros(length(output), 1)]; % Preload output for ao0, set ao1 to zero initially
preload(dq, preloadData);
% Start the output and input simultaneously in continuous mode
start(dq, "repeatoutput");
% Stop the generation and acquisition after key press
disp(‘Press any key to stop the continuous generation and acquisition.’);
pause();
stop(dq);
disp("Generation and acquisition stopped.");
% Callback function to read data, plot input and output using timescope, and write to ao1 in real-time
function plotAndWriteSignals(src, output, scope, rate)
% Read available data in chunks as defined by ScansAvailableFcnCount
[data, ~] = read(src, src.ScansAvailableFcnCount, "OutputFormat", "Matrix");

processedSignal = 2.*data;
% Ensure that both ‘data’ and ‘outputToPlot’ are column vectors and have the same length
len = length(processedSignal);
outputToPlot = output(1:len)’;

if isrow(processedSignal)
processedSignal = processedSignal’;
end
% Update the timescope with the output and input signals
% The input data and output data must have consistent row sizes
scope([outputToPlot, processedSignal]);
% Write the acquired input data to the output channel "ao1"
% Create a matrix where each row contains values for both output channels
outputData = [outputToPlot, processedSignal]; % First column for ao0, second column for ao1
write(src, outputData);
end dsp, signal processing, digital signal processing, ni-daq, analog input, analog output MATLAB Answers — New Questions

​

Tags: matlab

Share this!

Related posts

External Mode Connection Issue with C2000 LaunchPad and Speedgoat System
2025-05-17

External Mode Connection Issue with C2000 LaunchPad and Speedgoat System

how to validate mscohere?
2025-05-17

how to validate mscohere?

Transfer history to MATLAB 2025a
2025-05-17

Transfer history to MATLAB 2025a

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Categories

  • Matlab
  • Microsoft
  • News
  • Other
Application Package Repository Telkom University

Tags

matlab microsoft opensources
Application Package Download License

Application Package Download License

Adobe
Google for Education
IBM
Matlab
Microsoft
Wordpress
Visual Paradigm
Opensource

Sign Up For Newsletters

Be the First to Know. Sign up for newsletter today

Application Package Repository Telkom University

Portal Application Package Repository Telkom University, for internal use only, empower civitas academica in study and research.

Information

  • Telkom University
  • About Us
  • Contact
  • Forum Discussion
  • FAQ
  • Helpdesk Ticket

Contact Us

  • Ask: Any question please read FAQ
  • Mail: helpdesk@telkomuniversity.ac.id
  • Call: +62 823-1994-9941
  • WA: +62 823-1994-9943
  • Site: Gedung Panambulai. Jl. Telekomunikasi

Copyright © Telkom University. All Rights Reserved. ch

  • FAQ
  • Privacy Policy
  • Term

This Application Package for internal Telkom University only (students and employee). Chiers... Dismiss