Skip to content Skip to navigation

Connexions

You are here: Home » Content » MATLAB difference equation

Navigation

Content Actions

  • Download module PDF
  • Add to ...
    Add the module to:
    • My Favorites
    • A lens
    • An external social bookmarking service
    • My Favorites (What is 'My Favorites'?)
      'My Favorites' is a special kind of lens which you can use to bookmark modules and collections directly in Connexions. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need a Connexions account to use 'My Favorites'.
    • A lens (What is a lens?)

      Definition of a lens

      Lenses

      A lens is a custom view of Connexions content. You can think of it as a fancy kind of list that will let you see Connexions through the eyes of organizations and people you trust.

      What is in a lens?

      Lens makers point to Connexions materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

      Who can create a lens?

      Any individual Connexions member, a community, or a respected organization.

    • External bookmarks
  • E-mail the author

Recently Viewed

MATLAB difference equation

Module by: Don Johnson

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:1000
    y(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 y1 y 1 ? We need values for y0 , y1 , 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 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?"

Solution 1

The indices can be negative, and this condition is not allowed in MATLAB. To fix it, we must start the signals later in the array.

Comments, questions, feedback, criticisms?

Send feedback