Page 1 ECEGR 317 - Lab #8: Introduction to Simulink Objective: By: Joe McMichael This lab is an introduction to Simulink. The student will become familiar with the Help menu, go through a short example, and finally implement a modulation and demodulation circuit in Simulink. Procedure: Part 1: Using the Help menu 1) Start and go to Help -> Matlab Help. Expand the Simulink folder and scan read through the following sections: What is Simulink? Building a Model Setting Simulink Preferences Simulink Basics Figure 1: Matlab Help: What is Simulink?
Page 2 Figure 2: Matlab Help: Building a Model 2) Build and simulate the example in the help page Building a Model. Figure 3: Matlab Help: Building a Model Simulink Schematic
Page 3 Figure 4: Matlab Help: Building a Model Simulink Output Figure 5: Matlab Help: Setting Simulink Preferences
Page 4 Figure 6: Matlab Help: Simulink Basics Figure 7: Matlab Help: Modeling and Simulating Discrete Systems
Page 5 Figure 8: Matlab Help: Signal Processing Blockset: Discrete- Time Signals Part 2: Creating and displaying signals 3) Create a model that adds 2 sinusoids, stores the result in the Workspace, and displays the result on the scope. Change the parameters of the Sine Waves, the To Workspace block, the Scope, and the Simulation. Run the model for 0.1 seconds. Figure 9: Simulink Schematic for Adder
Page 6 Figure 10: Scope Output (Summation of Two Sine Waves) at Sample Time of 1e-5 First Window: 100 Hz, Amplitude 10 Second Window: 800 Hz, Amplitude 3 Third Window: Summation 4) Plot the twosinewaves variable in the workspace. Figure 11: Matlab Workspace Displaying twosinewaves variable
Page 7 Figure 12: Matlab Plot of twosinewaves with respect to time 15 10 5 0-5 -10-15 0 2000 4000 6000 8000 10000 12000 Figure 13: Matlab Plot of twosinewaves with respect to time (zoomed in) 15 10 5 0-5 -10-15 0 500 1000 1500 2000 2500 3000
Page 8 5) To observe the samples change the sample time for both sine waves to 1e-3 seconds and run the simulation for 0.1 seconds. Figure 14: Scope Output (Summation of Two Sine Waves) at Sample Time of 1e-3 First Window: 100 Hz, Amplitude 10 Second Window: 800 Hz, Amplitude 3 Third Window: Summation 6) Next, leave one of the sample times at 1e-3 seconds and change the other sample time to 5e-3 seconds. Go to Simulation- >Configuration Parameters and change the discrete solver to a variable step. Run the model.
Page 9 Figure 15: Scope Output (Summation of Two Sine Waves) with Samples Time of 1e-3 and 1e-5 and Variable Step Solver First Window: 100 Hz, Amplitude 10, Ts=1e-5 Second Window: 800 Hz, Amplitude 3, Ts=1e-3 Third Window: Summation 7) Next, add to our model 3 more blocks: Matrix Sum, Sine Wave block, and Scope. The Sine Wave block can be configured to give you 2 or more different signals by entering vectors for the amplitude and frequency.
Page 10 Figure 16: Scope Output (Summation of Two Sine Waves) using the Matrix Sum block First Window: 100 Hz, Amplitude 10, Ts=1e-5 and 800 Hz, Amplitude 3, Ts=1e-3 Second Window: Summation 8) Finally, add to our model 3 more blocks: Matrix Sum, Signal Processing Sine Wave block, and Scope. The Sine Wave block can be configured to give you 2 or more different signals by entering vectors for the amplitude and frequency.
Page 11 Figure 17: Scope Output (Summation of Two Sine Waves) using the Matrix Sum block and DSP sine wave block First Window: 100 Hz, Amplitude 10, Ts=1e-5 and 800 Hz, Amplitude 3, Ts=1e-3 Second Window: Summation
Figure 18: Schematic for Part 2 Joe McMichael Page 12 Part 3: Computing the Fourier Transform of a Signal 9) Go through the FFT Example you can find by going to: Help- >Matlab Help->Signal Processing Blockset->Transforms->Signals in the Time Domain->Transforming Time-Domain Data into the Frequency Domain. The model is called doc_fft_tut.mdl. Figure 19: Schematic of Doc_fft_tut.mdl Example 10) Draw and run the model for 3 sinusoids with equal amplitude and frequencies of 1000, 2000, and 4000 Hz. Figure out the sample time you need to use to avoid aliasing. Answers to Questions: Nyquist Frequency = 4,000 Hz * 2 = 8 khz
Page 13 11) Use the FFT program to investigate the relationship between sampling frequency (Fs), samples/frame, and resolution. Remember to autoscale all plots. Figure 20: FFT of Three Sinusoids at 1000 Hz, 2000 Hz, and 4000 Hz Fs = 240 khz Sample Time = 1.1667e-6 128 samples/frame
Page 14 Figure 21: FFT of Three Sinusoids at 1000 Hz, 2000 Hz, and 4000 Hz Fs = 240 khz Sample Time = 1.1667e-6 2048 samples/frame
Page 15 Figure 22: FFT of Three Sinusoids at 1000 Hz, 2000 Hz, and 4000 Hz Fs = 40 khz Sample Time = 2.5e-5 128 samples/frame
Page 16 Figure 23: FFT of Three Sinusoids at 1000 Hz, 2000 Hz, and 4000 Hz Fs = 40 khz Sample Time = 2.5e-5 2048 samples/frame
Page 17 Figure 24: FFT of Three Sinusoids at 1000 Hz, 2000 Hz, and 4000 Hz Fs = 8.8 khz Sample Time = 1.13636e-4 128 samples/frame
Page 18 Figure 25: FFT of Three Sinusoids at 1000 Hz, 2000 Hz, and 4000 Hz Fs = 8.8 khz Sample Time = 1.13636e-4 2048 samples/frame Answers to Questions: One must pick a sampling rate just above the Nyquist rate in order to achieve higher spectral resolution. Oversampling will often distort the FFT, because the algorithm only calculates a finite number of points. During oversampling, these points will be too far apart (because they must span a higher frequency), and will cause the FFT to have a lower spectral resolution. When a signal is undersampled, it will not meet the Nyquist theorem and will be aliased. Taking more samples per frame will increase the spectral resolution. To achieve the best results, one must sample slightly above the Nyquist rate with a large number of samples/frame.
Page 19 For example, at an 8.8 khz sampling rate with 128 samples/frame, the spectral components are wide and slightly off, but with an 8.8 khz sampling rate with 2048 samples/frame, the spectral components are right on, at 1 khz, 2 khz, and 4 khz. The size of the frame increases with a higher sampling frequency. However, above the Nyquist frequency this is unnecessary and can make it hard to see the spectral components. Part 4: Modeling the modulator and demodulator system from previous labs 12) Create a model for the modulation, frequency division multiplexing, and demodulation system that you built in a previous lab. 13) For the modulator and demodulator simply use the multiplier blocks. Model the bandpass filter with the transfer function you had from a previous lab. Model the lowpass filter with a transfer function. Figure 26: Matlab Program for Computing Fourier Coefficients for Bandpass Filter %Compute the Transfer Function Values for a Bandpass Filter %Joe McMichael %November 27th, 2007 clear clc f0 = 20000; BW = 3000; Q = 6.667; Gain = 88.8889; C = 0.000000001; R2 = 106103.4; R1 = 596.83; w0 = (2*pi*f0); numerator = -(2*Q*w0) denominator_s2 = 1 denominator_s = w0/q denominator_1 = w0^2
Page 20 Figure 27: Matlab Output Computing Fourier Coefficients for Bandpass Filter numerator = -1.6756e+006 denominator_s2 = 1 denominator_s = 1.8849e+004 denominator_1 = 1.5791e+010 >> Figure 28: Matlab Program for Computing Fourier Coefficients for Lowpass Filter %Compute the Transfer Function Values for a Lowpass Filter %Joe McMichael %November 27th, 2007 clear clc fc = 2000; wc = (2*pi*fc); numerator = wc^2 denominator_s2 = 1 denominator_s = 2*0.707*wc denominator_1 = wc^2 Figure 29: Matlab Output Computing Fourier Coefficients for Lowpass Filter numerator = 1.5791e+008 denominator_s2 = 1 denominator_s = 1.7769e+004 denominator_1 = 1.5791e+008 >>
Page 21 Figure 30: Simulink Schematic Carrier 1: 20 khz Message 1: 1 khz Carrier 2: 10 khz Message 2: 3 khz
Joe McMichael December 4th, 2007 Page 22 Figure 31: Output in the Time Domain Carrier 1: 20 khz Message 1: 1 khz Carrier 2: 10 khz Message 2: 3 khz 1st Panel: Output of Adder Circuit 2nd Panel: Output of Bandpass Filter 3rd Panel: Output of Demodulator 4th Panel: Ouput of Low Pass Filter
Figure 32: FFT of Adder Circuit Output Carrier 1: 20 khz Message 1: 1 khz Carrier 2: 10 khz Message 2: 3 khz Joe McMichael Page 23
Figure 33: FFT of Bandpass Filter Carrier 1: 20 khz Message 1: 1 khz Carrier 2: 10 khz Message 2: 3 khz Bandpass Filter Center = 20 khz Bandwidth = 3 khz Joe McMichael Page 24
Figure 34: FFT of Demodulator Carrier 1: 20 khz Message 1: 1 khz Carrier 2: 10 khz Message 2: 3 khz Joe McMichael Page 25
Figure 35: FFT of Low Pass Filter Carrier 1: 20 khz Message 1: 1 khz Carrier 2: 10 khz Message 2: 3 khz Cutoff Frequency = 2 khz Joe McMichael Page 26 Modulation & Demodulation Successful!