Saturday, October 10, 2009

Fourier Series

Fourier series are made up of sinusoids, all of which have frequencies that are integer multiples of some fundamental frequency. The trick, as with Taylor series, is to figure out what the coefficients are. In summation notation, we say (for odd functions of period 2, but that's just being picky in this context):
. . . and the trick is finding the coefficients ak. You can find those coefficients by using calculus on complex exponentials, or you can use NuCalc and just build your function out of sines.
A great thing about using Fourier series on periodic functions is that the first few terms often are a pretty good approximation to the whole function, not just the region around a special point. Fourier series are used extensively in engineering, especially for processing images and other signals. Finding the coefficients of a Fourier series is the same as doing a spectral analysis of a function.
In mathematics, a Fourier series decomposes a periodic function of periodic signal into a sum of simple oscillating functions, namely sine and cosines (or complex exponentials). The study of Fourier series is a branch of Fourier analysis. Fourier series were introduced by Joseph Fourier (1768–1830) for the purpose of solving the heat equation in a metal plate.
The heat equation is a partial differential equation. Prior to Fourier's work, there was no known solution to the heat equation in a general situation, although particular solutions were known if the heat source behaved in a simple way, in particular, if the heat source was a sine or cosine wave. These simple solutions are now sometimes called eigensolutions. Fourier's idea was to model a complicated heat source as a superposition (or linear combiantion) of simple sine and cosine waves, and to write the solution as a superposition of the corresponding eigensolutions. This superposition or linear combination is called the Fourier series.
Although the original motivation was to solve the heat equation it later became obvious that the same techniques could be applied to a wide array of mathematical and physical problems. The basic results are very easy to understand using the modern theory

Definition of Matrices

Definition of Matrices
MATLAB is based on matrix and vector algebra; even scalars are treated as 1x1 matrices. Therefore, vector and matrix operations are as simple as common calculator operations.
Vectors can be defined in two ways. The first method is used for arbitrary elements:
v = [1 3 5 7];
creates a 1x4 vector with elements 1, 3, 5 and 7. Note that commas could have been used in place of spaces to separate the elements. Additional elements can be added to the vector:
v(5) = 8;
yields the vector v = [1 3 5 7 8]. Previously defined vectors can be used to define a new vector. For example, with v defined above
a = [9 10];
b = [v a];
creates the vector b = [1 3 5 7 8 9 10].
The second method is used for creating vectors with equally spaced elements:
t = 0:.1:10;
creates a 1x101 vector with the elements 0, .1, .2, .3,...,10. Note that the middle number defines the increment. If only two numbers are given, then the increment is set to a default of 1:
k = 0:10;
creates a 1x11 vector with the elements 0, 1, 2, ..., 10.
Matrices are defined by entering the elements row by row:
M = [1 2 4; 3 6 8];
creates the matrix
There are a number of special matrices that can be defined:
null matrix:
M = [ ];
nxm matrix of zeros:
M = zeros(n,m);
nxm matrix of ones:
M = ones(n,m);
nxn identity matrix:
M = eye(n);
A particular element of a matrix can be assigned:
M(1,2) = 5;
places the number 5 in the first row, second column.
In this text, matrices are used only in Chapter 12; however, vectors are used throughout the text. Operations and functions that were defined for scalars in the previous section can also be used on vectors and matrices. For example,
a = [1 2 3];
b = [4 5 6];
c = a + b

yields:
c =
5
7
9
Functions are applied element by element. For example,
t = 0:10;
x = cos(2*t);
creates a vector x with elements equal to cos(2t) for t = 0, 1, 2, ..., 10.
Operations that need to be performed element-by-element can be accomplished by preceding the operation by a ".". For example, to obtain a vector x that contains the elements of x(t) = tcos(t) at specific points in time, you cannot simply multiply the vector t with the vector cos(t). Instead you multiply their elements together:
t = 0:10;
x = t.*cos(t);

MATLAB Basics

MATLAB is started by clicking the mouse on the appropriate icon and is ended by typing exit or by using the menu option. After each MATLAB command, the "return" or "enter" key must be depressed.
A. Definition of Variables
Variables are assigned numerical values by typing the expression directly, for example, typing
a = 1+2
yields: a = 3
The answer will not be displayed when a semicolon is put at the end of an expression, for example type a = 1+2;.

MATLAB utilizes the following arithmetic operators:
+
addition
-
subtraction
*
multiplication
/
division
^
power operator
'
transpose
A variable can be assigned using a formula that utilizes these operators and either numbers or previously defined variables. For example, since a was defined previously, the following expression is valid
b = 2*a;
To determine the value of a previously defined quantity, type the quantity by itself:
b
yields: b = 6
If your expression does not fit on one line, use an ellipsis (three or more periods at the end of the line) and continue on the next line.
c = 1+2+3+...
5+6+7;

There are several predefined variables which can be used at any time, in the same manner as user-defined variables:
i
sqrt(-1)
j
sqrt(-1)
pi
3.1416...
For example,
y= 2*(1+4*j)
yields: y = 2.0000 + 8.0000i
There are also a number of predefined functions that can be used when defining a variable. Some common functions that are used in this text are:
abs
magnitude of a number (absolute value for real numbers)
angle
angle of a complex number, in radians
cos
cosine function, assumes argument is in radians
sin
sine function, assumes argument is in radians
exp
exponential function

For example, with y defined as above,
c = abs(y)
yields: c = 8.2462
c = angle(y)
yields: c = 1.3258
With a=3 as defined previously,
c = cos(a)
yields: c = -0.9900
c = exp(a)
yields: c = 20.0855
Note that exp can be used on complex numbers. For example, with y = 2+8i as defined above,
c = exp(y)
yields: c = -1.0751 + 7.3104i
which can be verified by using Euler's formula:
c = exp(2)cos(8) + je(exp)2sin(8)

Difference Equation

Introduction
One of the most important concepts of DSP is to be able to properly represent the input/output 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 characteristics 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+7yn−1+2yn−2=xn−4xn−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.

Understanding Pole/Zero Plots on the Z-Plane

Once the Z-transform of a system has been determined, one can use the information contained in function's polynomials to graphically represent the function and easily observe many defining characteristics. The Z-transform will have the below structure, based on Rational Functions: Xz=PzQz Xz Pz Qz (1)

The two polynomials, PzPz and QzQz, allow us to find the poles and zeros of the Z-Transform.

Definition 1: zeros 1. The value(s) for zz where Pz=0 Pz 0. 2. The complex frequencies that make the overall gain of the filter transfer function zero.


Definition 2: poles 1. The value(s) for zz where Qz=0 Qz 0. 2. The complex frequencies that make the overall gain of the filter transfer function infinite.
Example 1
Below is a simple transfer function with the poles and zeros shown below it. Hz=z+1z−12z+34 Hz z 1 z 1 2 z 3 4
The zeros are: -1 1
The poles are: 12-34 1 2 3 4
The Z-Plane
Once the poles and zeros have been found for a given Z-Transform, they can be plotted onto the Z-Plane. The Z-plane is a complex plane with an imaginary and real axis referring to the complex-valued variable zz. The position on the complex plane is given by rⅇjθ r θ
and the angle from the positive, real axis around the plane is denoted by θθ. When mapping poles and zeros onto the plane, poles are denoted by an "x" and zeros by an "o". The below figure shows the Z-Plane, and examples of plotting zeros and poles onto the plane can be found in the following section. Figure 1Z-PlaneZ-Plane (zplane.jpg)
Examples of Pole/Zero Plots
This section lists several examples of finding the poles and zeros of a transfer function and then plotting them onto the Z-Plane. Example 2: Simple Pole/Zero Plot
Hz=zz−12z+34 Hz z z 1 2 z 3 4
The zeros are: 0 0
The poles are: 12-34 1 2 3 4 Figure 2: Using the zeros and poles found from the transfer function, the one zero is mapped to zero and the two poles are placed at 1212 and -3434 Pole/Zero PlotPole/Zero Plot (zp_eg1.jpg)Example 3: Complex Pole/Zero Plot
Hz=z−jz+jz−(12−12j)z−12+12j Hz z z
z 1 2 1 2 z 1 2 1 2
The zeros are: j-j
The poles are: -112+12j12−12j 1 1 2 1 2 1 2 1 2 Figure 3: Using the zeros and poles found from the transfer function, the zeros are mapped to ±j± , and the poles are placed at -11, 12+12j 1 2 1 2
and 12−12j 1 2 1 2 Pole/Zero PlotPole/Zero Plot (zp_eg2.jpg)
MATLAB - If access to MATLAB is readily available, then you can use its functions to easily create pole/zero plots. Below is a short program that plots the poles and zeros from the above example onto the Z-Plane.
% Set up vector for zeros z = [j ; -j];
% Set up vector for poles p = [-1 ; .5+.5j ; .5-.5j];
figure(1); zplane(z,p); title('Pole/Zero Plot for Complex Pole/Zero Plot Example');

Pole/Zero Plot and Region of Convergence
The region of convergence (ROC) for XzXz in the complex Z-plane can be determined from the pole/zero plot. Although several regions of convergence may be possible, where each one corresponds to a different impulse response, there are some choices that are more practical. A ROC can be chosen to make the transfer function causal and/or stable depending on the pole/zero plot.
Filter Properties from ROC
*
If the ROC extends outward from the outermost pole, then the system is causal. *
If the ROC includes the unit circle, then the system is stable.

Below is a pole/zero plot with a possible ROC of the Z-transform in the Simple Pole/Zero Plot discussed earlier. The shaded region indicates the ROC chosen for the filter. From this figure, we can see that the filter will be both causal and stable since the above listed conditions are both met. Example 4
Hz=zz−12z+34 Hz z z 1 2 z 3 4 Figure 4: The shaded area represents the chosen ROC for the transfer function. Region of Convergence for the Pole/Zero PlotRegion of Convergence for the Pole/Zero Plot (zp_roc.jpg)

Filter Design using the Pole/Zero Plot of a Z-Transform

One of the motivating factors for analyzing the pole/zero plots is due to their relationship to the frequency response of the system. Based on the position of the poles and zeros, one can quickly determine the frequency response. This is a result of the correspondence between the frequency response and the transfer function evaluated on the unit circle in the pole/zero plots. The frequency response, or DTFT, of the system is defined as: Hw=Hzz,z=ⅇjw=∑k=0M b k ⅇ-jwk∑k=0N a k ⅇ-jwk Hw z w Hz k 0 M b k w k k 0 N a k w k (1)
Next, by factoring the transfer function into poles and zeros and multiplying the numerator and denominator by ⅇjww we arrive at the following equations:

Hw= b 0 a 0 ∏k=1Mⅇjw− c k ∏k=1Nⅇjw− d k Hw b 0 a 0 k 1 M w c k
k 1 N w d k (2)
From Equation 2 we have the frequency response in a form that can be used to interpret physical characteristics about the filter's frequency response. The numerator and denominator contain a product of terms of the form ⅇjw−h w h , where hh is either a zero, denoted by c k c k or a pole, denoted by d k d k . Vectors are commonly used to represent the term and its parts on the complex plane. The pole or zero, hh, is a vector from the origin to its location anywhere on the complex plane and ⅇjw w is a vector from the origin to its location on the unit circle. The vector connecting these two points, ⅇjw−h w h , connects the pole or zero location to a place on the unit circle dependent on the value of ww. From this, we can begin to understand how the magnitude of the frequency response is a ratio of the distances to the poles and zero present in the z-plane as ww goes from zero to pi. These characteristics allow us to interpret HwHw as follows:

Hw= b 0 a 0 ∏"distances from zeros"∏"distances from poles" Hw b 0 a 0 ∏ "distances from zeros" ∏ "distances from poles" (3)
In conclusion, using the distances from the unit circle to the poles and zeros, we can plot the frequency response of the system. As ww goes from 00 to 2π 2 , the following two properties, taken from the above equations, specify how one should draw Hw Hw .
While moving around the unit circle...
1.
if close to a zero, then the magnitude is small. If a zero is on the unit circle, then the frequency response is zero at that point. 2.
if close to a pole, then the magnitude is large. If a pole is on the unit circle, then the frequency response goes to infinity at that point.




Drawing Frequency Response from Pole/Zero Plot
Let us now look at several examples of determining the magnitude of the frequency response from the pole/zero plot of a z-transform. If you have forgotten or are unfamiliar with pole/zero plots, please refer back to the Pole/Zero Plots module. Example 1
In this first example we will take a look at the very simple z-transform shown below:
Hz=z+1=1+z-1 Hz z 1 1 z -1 Hw=1+ⅇ-jw Hw 1 w
For this example, some of the vectors represented by ⅇjw−h w h , for random values of ww, are explicitly drawn onto the complex plane shown in the figure below. These vectors show how the amplitude of the frequency response changes as ww goes from 00 to 2π2, and also show the physical meaning of the terms in Equation 2 above. One can see that when w=0w0, the vector is the longest and thus the frequency response will have its largest amplitude here. As ww approaches π, the length of the vectors decrease as does the amplitude of HwHw. Since there are no poles in the transform, there is only this one vector term rather than a ratio as seen in Equation 2. Figure 1: The first figure represents the pole/zero plot with a few representative vectors graphed while the second shows the frequency response with a peak at +2 and graphed between plus and minus π. Pole/Zero Plot Frequency Response: H(w)(a) (b) Pole/Zero Plot (filt_eg1_pz.jpg) Frequency Response: H(w) (filt_eg1_fig.jpg)Example 2
For this example, a more complex transfer function is analyzed in order to represent the system's frequency response.
Hz=zz−12=11−12z-1 Hz z z 1 2 1 1 1 2 z -1 Hw=11−12ⅇ-jw Hw 1 1 1 2 w
Below we can see the two figures described by the above equations. The Figure 2(a) represents the basic pole/zero plot of the z-transform, HwHw. Figure 2(b) shows the magnitude of the frequency response. From the formulas and statements in the previous section, we can see that when w=0w0 the frequency will peak since it is at this value of ww that the pole is closest to the unit circle. The ratio from Equation 2 helps us see the mathematics behind this conclusion and the relationship between the distances from the unit circle and the poles and zeros. As ww moves from 00 to π, we see how the zero begins to mask the effects of the pole and thus force the frequency response closer to 00. Figure 2: The first figure represents the pole/zero plot while the second shows the frequency response with a peak at +2 and graphed between plus and minus π. Pole/Zero Plot Frequency Response: H(w)(a) (b)

Useful Mathematical Identities

2 + cos2 = 1 1 + tan2 = sec2 sin( − θ)
= − sinθ cos( − θ) = sinθ sin2θ
= 2sinθcosθ cos2θ = cos2 − sin2
= 2cos2θ − 1 = 1 − 2sin2θ 1 + cot2 = csc2 ejθ
= cosθ + jsinθ tan( − θ)
= cotθ