# OpenStax-CNX

You are here: Home » Content » Difference Equation

### Recently Viewed

This feature requires Javascript to be enabled.

### Tags

(What is a tag?)

These tags come from the endorsement, affiliation, and other lenses that include this content.

# Difference Equation

Module by: Michael Haag. E-mail the author

Summary: (Blank Abstract)

Note: You are viewing an old version of this document. The latest version is available here.

## Introduction

One of the most important concepts of DSP is to be able to properly represent the input/ouput relationship to a given LTI system. A linear constant-coefficient difference equation (LCCDE) serves as a way to express just this relationship in a discrete-time system. Writing the sequence of inputs and outputs, which represent the charateristics of the LTI system, as a difference equation help in understanding and manipulating a system.

Definition 1: difference equation
An equation that shows the relationship between consecutive values of a sequence and the differences among them. They are often rearranged as a recursive formula so that a systems output can be computed from the input signal and past outputs.

### Example

yn+7yn1+2yn2=xn4xn1 y n 7 y n 1 2 y n 2 x n 4 x n 1
(1)

## General Formulas from the Difference Equation

As stated briefly in the definition above, a difference equation is a very useful tool in describing and calculating the output of the system described by the formula for a given sample nn. The key property of the difference equation is its ability to help easily find the transform, Hz H z , of a system. In the following two subsections, we will look at the general form of the difference equation and the general conversion to a z-transform directly from the difference equation.

### Difference Equation

The general form of a linear, constant-coefficient difference equation (LCCDE), written to easily express a recursive output, is as follows:

yn= k = 1 N a k ynk+ k = 0 M b k xnk y n k 1 N a k y n k k 0 M b k x n k
(2)
From this equation, note that ynk y n k represents the outputs and xnk x n k represents the inputs. The value of NN represents the order of the difference equation and corresponds to the memory of the system being represented. Because this equation relies on past values of the output, in order to compute a numerical solution, certain past outputs, referred to as the initial conditions, must be known.

### Conversion to Z-Transform

Using the above formula, Equation 2, we can easily generalize the transfer function, Hz H z , for any difference equation. Below are the steps taken to convert any difference equation into its transfer function, i.e. z-transform. This conversion relies on the time-shifting property of the z-transform and assumes that a 0 =1 a 0 1 .

Yz= k = 1 N a k Yzzk+ k = 0 M b k Xzzk Y z k 1 N a k Y z z k k 0 M b k X z z k
(3)
Hz=YzXz= k = 0 M b k zk1+ k = 1 N a k zk H z Y z X z k 0 M b k z k 1 k 1 N a k z k
(4)

### Conversion to Frequency Response

Once the z-transform has been calculated from the difference equation, we can go one step further to define the frequency response of the system, or filter, that is being represented by the difference equation.

#### note:

Remember that the reason we are dealing with these formulas is to be able to aid us in filter design. A LCCDE is one of the easiest ways to represent FIR filters. By being able to find the frequency response, we will be able to look at the basic properties of any filter represented by a simple LCCDE.
Below is the general formula for the frequency response of a z-transform. The conversion is simple a matter of taking the z-transform forumula, Hz H z , and replacing every instance of zz with eiw w .
Hw=Hz| z , z = eiw = k =0M b k e(iwk) k =0N a k e(iwk) H w z w Hz k 0 M b k w k k 0 N a k w k
(5)
Once you understand the derivation of this formula, look at the module concerning Filter Design from the Z-Transform for a look into how all of these ideas of the Z-transform, Difference Equation, and Pole/Zero Plots play a role in filter design.

## Example

### Example 1: Finding Difference Equation

Below is a basic example showing the opposite of the steps above: given a transfer function one can easily calculate the systems difference equation.

Hz=z+12(z12)(z+34) H z z 1 2 z 1 2 z 3 4
(6)
Given this transfer function of a time-domain filter, we want to find the difference equation. To begin with, expand both polynomials and divide them by the highest order zz.
Hz=(z+1)(z+1)(z12)(z+34)=z2+2z+1z2+2z+138=1+2z-1+z-21+14z-138z-2 H z z 1 z 1 z 1 2 z 3 4 z 2 2 z 1 z 2 2 z 1 3 8 1 2 z -1 z -2 1 1 4 z -1 3 8 z -2
(7)
From this transfer function, the coefficients of the two polynomials will be our a k a k and b k b k values found in the general difference equation formula, Equation 2. Using these coefficients and the above form of the transfer function, we can easily write the difference equation:
xn+2xn1+xn2=yn+14yn138yn2 x n 2 x n 1 x n 2 y n 1 4 y n 1 3 8 y n 2
(8)
In our final step, we can rewrite the difference equation in its more common form showing the recursive nature of the system.
yn=xn+2xn1+xn2+-14yn1+38yn2 y n x n 2 x n 1 x n 2 -1 4 y n 1 3 8 y n 2
(9)

## Content actions

### Give feedback:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

#### Definition of a lens

##### Lenses

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

##### What is in a lens?

Lens makers point to 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 member, a community, or a respected organization.

##### What are tags?

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks