2017
Real Time Measurements with
MicroDAQ Hardware Access Functions
M.Mohamed Ibrahim
Tenet Technetronics
10-JUNE-17
Tenet Technetronics 1
Application Notes
Contents
Analog Demo
1. Analog Read Function .. 2
DSP Applications
1. Xcorr . 4
2. Random noise generator . 6
Tenet Technetronics | Varsity
2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: [email protected]
Tenet Technetronics 2
Application Notes
ANALOG DEMO
1. Analog Read:
mdaq_ai_read function is used to read the analog sensor values.
Script:
con = mdaq_open();
sample_count = 200;
y_max = 5;
y_min = 0;
clf()
plot(linspace(y_min, y_max, sample_count));
a = gca();
while(mdaq_key_read(con, 1) == %F)
data = [];
for i=1:sample_count
data = [data mdaq_ai_read(con, [1], 10, %F)]
end
a.children.children.data(:,2) = data';
end
mdaq_close(con)
It stops when you press F1 button. You can change y_min, y_max to get different ranges
on plot. sample_count can be changed to get different number of samples at once.
Tenet Technetronics | Varsity
2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: [email protected]
Tenet Technetronics 3
Application Notes
Output:
Figure 1.1: Graph for Sensor read values
Tenet Technetronics | Varsity
2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: [email protected]
Tenet Technetronics 4
Application Notes
DSP APPLICATIONS
1. xcorr
Computes discrete auto or cross correlation
Calling Sequence
[c [,lagindex]] = xcorr(x [,maxlags [,scaling]])
[c [,lagindex]] = xcorr(x,y [,maxlags [,scaling]])
Parameters
X a vector of real or complex floating point numbers.
Y a vector of real or complex floating point numbers. The default value is x.
Maxlags a scalar with integer value greater than 1. The default value is n.
Where n is the maximum of the x and y vector length.
Scaling a character string with possible value: "biased", "unbiased", "coeff",
"none". The default value is "none".
C a vector of real or complex floating point numbers with same orientation as
x.
Lagindex a row vector, containing the lags index corresponding to the c
values.
Steps involved in correlation of signals:
Step 1: Open xcos window and make an xcos model (as shown in figure 2.1) for
signal correlation using scilab script.
Tenet Technetronics | Varsity
2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: [email protected]
Tenet Technetronics 5
Application Notes
Figure 2.1: Generate sine wave for auto correlation
Note:
Here, the created xcos model saves under the correlation.zcos file name.
Step 2: To write a script using xcorr macro to correlate the sine signal.
TIME=20;
mdaq_dsp_build(mdaq_toolbox_path() + filesep() + "examples" + filesep()
+"correlation.zcos");
result = mdaq_dsp_start('correlation_scig\correlation.out');
// Register signal ID and signal size
result = mdaq_dsp_signal(123, 1);
sample_count = 500;
for i=1:(10 * TIME)
[result, s] = mdaq_dsp_signal_read(sample_count);
[c, ind] = xcorr(s, "biased");
plot(ind, c)
end
// Stop DSP execution
mdaq_dsp_stop();
Tenet Technetronics | Varsity
2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: [email protected]
Tenet Technetronics 6
Application Notes
Step 3: Run the above script, output is displayed like below.
2. Random noise generator
Noise generators are used to test signals for measuring noise figure, frequency
response, and other parameters. Here, we generate noise signal is added with
sine signal.
Generated signal is given an input to the MicroDAQ AI pin and find the
frequency of the signal using FFT.
Tenet Technetronics | Varsity
2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: [email protected]
Tenet Technetronics 7
Application Notes
Step 1: Create a xcos model as shown in figure 3.1
Figure 3.1: Random noise generator
Step 2: Save the created model (noise_gen.zcos). And then start simulation to
see the output (figure 3.2)
Figure 3.2: Noisy sine signal
Tenet Technetronics | Varsity
2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: [email protected]
Tenet Technetronics 8
Application Notes
Step 3: To find the frequency content of the signal generated using the model
(noise_gen.zcos).
Script:
// Script execution duration in seconds
TIME = 20;
// build DSP binary from Xcos model
mdaq_dsp_build(mdaq_toolbox_path() + filesep() + "examples" + filesep()
+"noise_gen.zcos");
// Start DSP application
result = mdaq_dsp_start('noise_gen_scig\noise_gen.out');
if result < 0 then
abort;
end
// Register signal ID and signal size
result = mdaq_dsp_signal(321, 1);
if result < 0 then
disp("ERROR: unable to register signal");
abort;
end
first_time = 1;
a = [];
// Process data from DSP
sample_count = 100;
Tenet Technetronics | Varsity
2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: [email protected]
Tenet Technetronics 9
Application Notes
for i=1:(10 * TIME)
[result, s] = mdaq_dsp_signal_read(sample_count);
if result < 0 then
disp("ERROR: unable to read signal data!");
abort;
end
t = 0:1/sample_count:1;
N=size(t,'*'); //number of samples
y=fft(s');
f=sample_count*(0:(N/2))/N; //associated frequency vector
n=size(f,'*');
if first_time == 1 then
clf()
plot(f,abs(y(1:n)))
first_time = 0;
a = gca();
else
a.children.children.data(:,2) = abs(y(1:n))';
end
end
// Stop DSP execution
mdaq_dsp_stop();
Tenet Technetronics | Varsity
2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: [email protected]
Tenet Technetronics 10
Application Notes
Step 4: Run the above script
Figure 3.3: Spectrum of the noisy sine signal
For more information please visit: www.tenettech.com
For technical query please send an e-mail: [email protected]
Tenet Technetronics | Varsity
2514/U, 7th Opp:B.B.M.P. Swimming Pool, 8th A Main Rd, Hampi Nagar, RPC Layout, Vijaya Nagar, Bengaluru-560104
Ph. No: 080-26722726., Website: www.tenettech.com, Email: [email protected]