estimate the transfer function of a circuit with adalm1000 -凯发k8网页登录
this example shows how to use matlab to connect to an adalm1000 source-measurement unit, configure it to generate an arbitrary signal, make live measurements, and use the measurements to calculate the transfer function of the connected circuit.
introduction
in this example you have an r-c circuit consisting of a 1 k resistor in series with a 0.1 f capacitor. the r-c circuit is attached to the adalm1000 device with channel a of the device providing the voltage stimulus consisting of a chirp signal. the output of channel a is connected to the resistor, and the ground is connected to the capacitor. channel b of the device is used to measure the voltage across the capacitor. the following circuit diagram shows the measurement setup.
you can use the stimulus and the measured waveforms to estimate the transfer function of the r-c circuit, and compare the measured response to the theoretical response of the r-c circuit.
discover devices connected to your system
daqlist("adi")
ans=1×4 table
deviceid description model deviceinfo
________ _______________________________ ___________ ________________________
"smu1" "analog devices inc. adalm1000" "adalm1000" [1×1 daq.adi.deviceinfo]
create a dataacquisition for the adalm1000 device
adidaq = daq("adi")
adidaq = dataacquisition using analog devices inc. hardware: running: 0 rate: 100000 numscansavailable: 0 numscansacquired: 0 numscansqueued: 0 numscansoutputbyhardware: 0 ratelimit: [] show channels show properties and methods
add voltage source and measurement channels
the adalm1000 device is capable of sourcing and measuring voltage simultaneously on separate channels. set up the device in this mode.
to source voltage, add an analog output channel with device id smu1 and channel id a, and set its measurement type to voltage.
addoutput(adidaq,'smu1','a','voltage');
to measure voltage, add an analog input channel with device id smu1 and channel id b, and set its measurement type to voltage.
addinput(adidaq,'smu1','b','voltage');
confirm the configuration of the channels.
adidaq.channels
ans=1×2 object
index type device channel measurement type range name
_____ ____ ______ _______ _____________________ _________________ ________
1 "ao" "smu1" "a" "voltage (singleend)" "0 to 5.0 volts" "smu1_a"
2 "ai" "smu1" "b" "voltage (singleend)" "0 to 5.0 volts" "smu1_b"
define and visualize a chirp waveform for stimulating the circuit
use a chirp waveform of 1 volt amplitude, ranging in frequency from 20 hz to 20 khz for stimulating the circuit. the chirp occurs in a period of 1 second.
fs = adidaq.rate;
t = 0:1/fs:1;
excitationsignal = chirp(t,20,1,20e3,'linear');
add a dc offset of 2 v to ensure that the output voltage of the device is always above 0 v.
offset = 2; excitationsignal = excitationsignal offset;
visualize the stimulus signal in the time-domain.
figure(1) plot(t, excitationsignal,'blue') xlim([0 0.15]) xlabel('time (s)') ylabel('magnitude (v)') title('time domain plot of stimulus signal')
visualize the stimulus signal in the frequency domain.
figure(2) spectrogram(excitationsignal,1024,1000,1024,fs,'yaxis') title('frequency domain view of stimulus signal')
stimulate the circuit and simultaneously measure the frequency response
generate device output and measure measure the voltage across the capacitor at the same time on the other channel.
measuredtable = readwrite(adidaq,excitationsignal'); measuredsignal = measuredtable{:,1};
plot the stimulus and the measured signals
figure(1) hold on; plot(t,measuredsignal,'red'); xlim([0 0.15]) ylim([1 3]) title('time domain plot of stimulus and measured signal') legend('excitation signal','measured signal')
figure(3) spectrogram(measuredsignal,1024,1000,1024,fs,'yaxis') title('frequency domain view of the the measured signal')
calculate the transfer function of the circuit
compare the measured signal and the stimulus signal to calculate the transfer function of the r-c circuit, and plot the magnitude response.
remove dc offset before processing.
measuredsignal = measuredsignal - mean(measuredsignal); excitationsignal = excitationsignal - offset; [tfxy,freq] = tfestimate(excitationsignal,measuredsignal,[],[],[],fs); mag = abs(tfxy);
compare the estimated transfer function to the theoretical magnitude response.
r = 1000; % resistance (ohms) c = 0.1e-6; % capacitance (farads) tfmagtheory = abs(1./(1 (1i*2*pi*freq*c*r))); figure(4); semilogy(freq,tfmagtheory,freq,mag); xlim([0 20e3]) xlabel('frequency (hz)') ylim([0.05 1.1]) ylabel('magnitude') grid on legend('theoretical frequency response','measured frequency response') title({'magnitude response of the theoretical'; 'and estimated transfer functions'});
clear the dataacquisition and figures
clear adidaq close all