Instructions on Creating a Custom Waveform

advertisement
Creating custom waveforms using the Velleman PCSGU250
Function Generator
Creating waveforms from the frequency domain:
We will be using an example Bode plot to illustrate how you can create an array of variables for the
function generator:
1. If you are working directly from a frequency vs. voltage plot, not a Bode plot, go to step 4.Decide what
kind of waveform you would like in the frequency domain and create the associated transfer function.
In the following example m, k, and l are all sub-functions of the entire transfer function; m1, m2, k1,
k2, l1, l2, and l3 are all sub-functions of m, k and l respectively. Dividing the transfer function makes it
much simpler to create the needed corner frequencies without tedious calculation.
Example:
m1=tf([1/5 1],[1/25 1]);
m2=tf([1/200 1],[1/25 1]);
m=m1*m2;
k1=tf([1/200 1],[1/1600 1]);
k2=tf([1/12000 1],[1/1600 1]);
k=k1*k2;
l1=tf([1/12000 1],[1/70000 1]);
l2=tf([1],[1/70000 1]);
l3=tf([1/100000 1],[1]);
l=l1*l2*l3;
%entire transfer function = l*m*k
Transfer function:
3.472e-019 s^6 + 4.32e-014 s^5 + 9.008e-010 s^4 + 5.36e-006 s^3 +
0.002062 s^2 + 0.2102 s + 1
--------------------------------------------------------1.276e-019 s^6 + 1.827e-014 s^5 + 6.834e-010 s^4 + 2.08e-006 s^3 +
0.001703 s^2 + 0.08128 s + 1
Figure 1: Bode plot of k*m*l
2. To extract the magnitude and phase of the Bode plot into an array, we will use the [mag phase]
command.
Example:
[mag phase]= bode(k*m*l);
3. The problem with the [mag phase] command is that it places the array into the third dimension of
a three-dimensional matrix. MATLAB cannot take the Inverse Fourier Transform (IFFT) of a threedimensional matrix. To combat this problem:
i) We create a dummy matrix filled with zeros using the zeros command. The purpose of this
array will become clearer as you continue through these steps. In this example xf is the
variable in which we put the dummy array. The array is a 1 dimensional matrix with the same
length as the third dimension of the magnitude matrix (or you can also use the phase matrix)
created in step 2.
Example:
xf = zeros(1,size(mag,3));
ii) Now, we will use the length of this dummy array as a counter in a for loop. With each count of
the for loop, the associated 0 in that row of the xf matrix is replaced with the actual magnitude
and phase of the transfer function.
Example:
for ii = 1:length(xf)
xf(ii) = mag(1,1,ii).*exp(1i*phase(ii)*pi/180);
end
4. To be able to run an Inverse Fourier Transform (IFFT) in MATLAB, we must have a mirror image of
our signal about the maximum frequency. To do this, we must use the fliplr(flip left to right)
command.
Example :
xf_with_flip = [xf fliplr(xf)];
5. We are now ready to run our IFFT to transfer the signal into the time domain. Make sure you use the
absolute value of the IFFT.
Example:
xt = abs(ifft(xff));
Figure 2: Time-domain signal xt
To get the array of numbers suitable for the function generator, simply copy the values in the final
time-domain matrix (make sure you are using the absolute value of the time-domain matrix). Paste
these values into Notepad, making sure each value has its own line. Finally, save the file as a .dll file.
Make sure you save the file in the Velleman->PcLab2000LT->Lib folder.
To use the custom waveform, open the oscilloscope software, click on the “MORE FUNCT.” Button,
select “Library waveforms” and double click on your custom waveform. The figure below illustrates a
periodic version of Figure 2 at the output of the oscilloscope.
Another very useful document is found under the function generator help file in the PcLab2000LT
software.
Figure 3: Output of Oscilloscope
Download