Summary: How to write a simple looping difference equation in MATLAB.
Difference equations are usually expressed in software with for loops. A MATLAB program that would compute the first 1000 values of the output has the form
for n=1:1000y(n) = sum(a.*y(n-1:-1:n-p)) + sum(b.*x(n:-1:n-q));end
An important detail emerges when we consider making this program work; in fact, as written it has (at least) two bugs. What input and output values enter into the computation of y(1) ? We need values for y(0),y(1),… , values we have not yet computed. To compute them, we would need more previous values of the output, which we have not yet computed. To compute these values, we would need even earlier values, ad infinitum. The way out of this predicament is to specify the system's initial conditions: we must provide the p output values that occurred before the input started. These values can be arbitrary, but the choice does impact how the system responds to a given input. One choice gives rise to a linear system: Make the initial conditions zero. The reason lies in the definition of a linear system: The only way that the output to a sum of signals can be the sum of the individual outputs occurs when the initial conditions in each case are zero.
EXERCISE 1
The initial condition issue resolves making sense of the difference equation for inputs that start at some index. However, the program will not work because of a programming, not conceptual, error. What is it? How can it be "fixed?"
0 comments:
Post a Comment