readmefirst · 2020. 9. 9. · simulating difference equations using simulink readmefirst lab...

6
Simulating Difference Equations using Simulink ReadMeFirst Lab Summary This lab will introduce you to control using MATLAB and Simulink. Simulink is a MATLAB tool for building and simulating feedback control problems. The first part of the lab, you will walk you through Simulink and show you how to apply Simulink to model a difference equation. In the second part, you examine the recursive solution for a step response input. In the final section, are asked to solve a more complex difference equation. Lab Preparation 1) Download and Install MATLAB 2020a with SIMULINK 2) Watch the Video Simulating Difference Equations in Simulink Virtual Lab Version - Autumn 2020

Upload: others

Post on 13-Mar-2021

12 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ReadMeFirst · 2020. 9. 9. · Simulating Difference Equations using Simulink ReadMeFirst Lab Summary This lab will introduce you to control using MATLAB and Simulink. Simulink is

Simulating Difference Equations using Simulink

ReadMeFirst

Lab Summary

This lab will introduce you to control using MATLAB and Simulink. Simulink is a MATLAB tool for building and simulating feedback control problems. The first part of the lab, you will walk you through Simulink and show you how to apply Simulink to model a difference equation. In the second part, you examine the recursive solution for a step response input. In the final section, are asked to solve a more complex difference equation.

Lab Preparation

1) Download and Install MATLAB 2020a with SIMULINK

2) Watch the Video

Simulating Difference Equations in Simulink

Virtual Lab Version - Autumn 2020

Page 2: ReadMeFirst · 2020. 9. 9. · Simulating Difference Equations using Simulink ReadMeFirst Lab Summary This lab will introduce you to control using MATLAB and Simulink. Simulink is

Part 1: Beginning with MATLAB and Simulink

Follow the screencasts to learn how to make the following model for the difference equation:

y[n] = a1 * y[n-1] + a2*y[n-2] + b0*x[n] + b1*x[n-1],

where a1= -0.25 , a2 = 0.5, b0 = 1, and b1 = 0.5

Assume that the system is initially at rest. The model is shown below

******************************************************************************

NOTE: A K will be replaced by the coefficient number if you click on the gain block and drag itdiagonally to make the size larger. ******************************************************************************

Page 3: ReadMeFirst · 2020. 9. 9. · Simulating Difference Equations using Simulink ReadMeFirst Lab Summary This lab will introduce you to control using MATLAB and Simulink. Simulink is

Match the settings in the following screen capture:

Page 4: ReadMeFirst · 2020. 9. 9. · Simulating Difference Equations using Simulink ReadMeFirst Lab Summary This lab will introduce you to control using MATLAB and Simulink. Simulink is

Part 2: Difference Equation with a Step Response

You examined the impulse response of the difference equatiion.. The Model1_ExactPlot.m file is hard coded to for an impulse response. Now examine the difference equation behavior to a step function input.

Procedure:

1) Edit the file Model1_input.m to generate a step response (note that there is line of codecommented out that will do this for you).

2) Run this file and run Simulink (do not change the model).

3) Run Model1_OutputPlot.m to plot the results. The points do not match up.

4) Edit Model1_ExactPlot.m so that it recursively finds the step response.

5) After you find the correct solution, run the file and see if the points match up.

6) Continue to update Model1_ExactPlot.m until the points match.

Result 4: Take a screenshot of the step function plot and include it in your lab report.

Result 5: Take a screenshot of the step response of the Simulink model and include it in your lab report.

Result 6: Take a screenshot of the output plot from Model1_ExactPlot.m and include it in your lab report.

Checkpoint 2: Include your MATLAB plots in your lab report.

MATLAB files, Model1_input.m, Model1_OutputPlot.m and Model1_ExactPlot, will generate the input, plot the results from Simulink, and plot the recursive Simulink solution. After making the model, run the input file, the Simulink model and the output plot.

The script Model1_ExactPlot is coded for the impulse response of the difference equation. Run this file to get the recursive solution to this problem. Compare this to the Simulink solution. Does this solution match?

Result 1: Take a screenshot of the impulse input plot and include it in your lab report.

Result 2: Take screenshot of the impulse response from Simulink and include it in your lab report.

Result 3: Take a screenshot of the recursive algorithm results plot and include it in your lab report.

Checkpoint 1: Include your MATLAB plots in your lab report.

Page 5: ReadMeFirst · 2020. 9. 9. · Simulating Difference Equations using Simulink ReadMeFirst Lab Summary This lab will introduce you to control using MATLAB and Simulink. Simulink is

Part 3: A New Difference Equation

Consider the new difference equation with some initial conditions:

y[n] = a1*y[n-1] + a2*y[n-2] + a3*y[n-3] + b0*x[n]

where a1= -0.25, a2= 0.50, a3= 0.50, and b0 = 1 ; and the initial conditions are y(-1) = -1, y(-2) = 3 , y(3) = -2

Simulate the impulse response for this difference equation using Simulink (you will need to make a new model). Use an end time of 20. Find the exact solution using a recursive algorithm.

Result 7: Take a screenshot of the Simulink result plot and include it in your lab report.

Result 8: Take a screenshot of the plot from your recursive solution and include it in your lab report.

Checkpoint 3: Include your MATLAB plots in your lab report.

Page 6: ReadMeFirst · 2020. 9. 9. · Simulating Difference Equations using Simulink ReadMeFirst Lab Summary This lab will introduce you to control using MATLAB and Simulink. Simulink is

Discussion Questions

Topic 1: What 'units' are n values in the Simulink simulation?

Topic 2: What format do you use when you save your Simulink output to be used in the MATLAB workspace?

Topic 3: Which components require initial conditions?

Topic 4: What are the initial conditions for an initially-relaxed or initially-at-rest difference equation?

Topic 5: Consider the following Simulink Model:

Write the difference equation. Include initial conditions and coefficient values.