I am acquiring data from the Analog Discovery 3 using MATLAB that is running the Diligent Toolbox 1.5.0.1 and Data Acquisition Toolbox 23.2. I have Waveforms installed v.3.22.2. For my setup, I have a microphone circuit connected to analog channel 1 on the AD3 (which is the ai0 channel in the MATLAB code). I am using the code below:
clear; clc; close all;
daqreset;
AD3ps = daq("digilent");
AD3ain = daq("digilent");
vp=3; %power supply voltage
N=100; % size of data buffer
samplingRate = 10000; % sampling rate per channel
%setup power supply
addoutput(AD3ps, "AD3_0", "V+" ,'Voltage');
write(AD3ps, vp);
pause(0.2)
%setup analog inpout channel
addinput(AD3ain, "AD3_0", "ai0", 'Voltage');
addinput(AD3ain, "AD3_0", "ai1", "Voltage");
AD3ain.Rate = samplingRate;
% read buffer of data
data=read(AD3ain,N);
time=seconds(data.Time);
voltage=data.AD3_0_ai0;
%graph data
plot(data.Time,voltage) %plot strip chart
xlabel('time (sec)')
ylabel('voltage (V)')
When I execute this code while whistling into the mic, I get a sine wave as expected, as shown in the first plot below. Since I am not using AD3 analog channel 2 (ai1 in the MATLAB code), the code should also work if I comment out the second "addinput" statement and make no other changes to the code. However, it does not work and the input signal is a constant 0.022V, regardless of whether the microphone circuit or anything else is connected to analog channel 1. Any idea what is going on?
Another issue is that if I increase the sampling rate to 20000, then I get the signal shown in the second plot below. Again, I get this same signal no matter what is connected, even if I ground the analog input channel. I thought that the AD3 and MATLAB should be able to handle a sampling rate of 20000.
Question
rgold
I am acquiring data from the Analog Discovery 3 using MATLAB that is running the Diligent Toolbox 1.5.0.1 and Data Acquisition Toolbox 23.2. I have Waveforms installed v.3.22.2. For my setup, I have a microphone circuit connected to analog channel 1 on the AD3 (which is the ai0 channel in the MATLAB code). I am using the code below:
clear; clc; close all; daqreset; AD3ps = daq("digilent"); AD3ain = daq("digilent"); vp=3; %power supply voltage N=100; % size of data buffer samplingRate = 10000; % sampling rate per channel %setup power supply addoutput(AD3ps, "AD3_0", "V+" ,'Voltage'); write(AD3ps, vp); pause(0.2) %setup analog inpout channel addinput(AD3ain, "AD3_0", "ai0", 'Voltage'); addinput(AD3ain, "AD3_0", "ai1", "Voltage"); AD3ain.Rate = samplingRate; % read buffer of data data=read(AD3ain,N); time=seconds(data.Time); voltage=data.AD3_0_ai0; %graph data plot(data.Time,voltage) %plot strip chart xlabel('time (sec)') ylabel('voltage (V)')
When I execute this code while whistling into the mic, I get a sine wave as expected, as shown in the first plot below. Since I am not using AD3 analog channel 2 (ai1 in the MATLAB code), the code should also work if I comment out the second "addinput" statement and make no other changes to the code. However, it does not work and the input signal is a constant 0.022V, regardless of whether the microphone circuit or anything else is connected to analog channel 1. Any idea what is going on?
Another issue is that if I increase the sampling rate to 20000, then I get the signal shown in the second plot below. Again, I get this same signal no matter what is connected, even if I ground the analog input channel. I thought that the AD3 and MATLAB should be able to handle a sampling rate of 20000.
Thanks for your help.
Link to comment
Share on other sites
0 answers to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now