6.6: Test Sequences
When we design a filter, we design it for a purpose. For example, a moving average filter is often designed to pass relatively constant data while averaging out relatively variable data. In an effort to clarify the behavior of a filter, we typically analyze its response to a standard set of test signals. We will call the impulse , the step , and the complex exponential the standard test signals.
Unit Pulse Sequence
The unit pulse sequence is the sequence
\[u_{n}=\delta_{n}= \begin{cases}1, & n=0 \\ 0, & n \neq 0\end{cases} \nonumber \]
This sequence, illustrated in Figure 1, consists of all zeros except for a single one at \(n=0\). If the unit pulse sequence is passed through a moving average filter (whether finite or not), then the output is called the unit pulse response :
\[\begin{align}
h_{n} &=\sum_{k=0}^{\infty} w_{k} \delta_{n-k} \nonumber \\
&=w_{n}
\end{align} \nonumber \]
(Note that \(\delta_{n-k}=0\) unless \(n=k\).) So the unit pulse sequence may be used to read out the weights of a moving average filter. It is common practice to use \(w_k\) (the \(k^{\text {th }}\) and \(h_k\) (the \(k^{\text {th }}\) impulse response) interchangeably.
Find the unit pulse response for the finite moving average \(x_{n}=\sum_{k=0}^{N-1} w_{k} u_{n-k}\). Caution: You must consider \(n<0,0 \leq n \leq N-1\), and \(n \geq N\).
Find the unit pulse response for the recursive filter \(x_{n}=a x_{n-1}+w_{0} u_{n}\).
Unit Step Sequence
The unit step sequence is the sequence
\[u_{n}=\xi_{n}= \begin{cases}1, & n \geq 0 \\ 0, & n<0\end{cases} \nonumber \]
This sequence is illustrated in Figure 2. When this sequence is applied to a moving average filter, the result is the unit step response
\[\begin{align}
g_{n} &=\sum_{k=0}^{n} w_{k} \nonumber \\
&=\sum_{k=0}^{n} h_{k} .
\end{align} \nonumber \]
The unit step response is just the sequence of partial sums of the unit pulse response.
Find the unit step response for the finite moving average filter \(x_{n}=\sum_{k=0}^{N-1} w_{k} u_{n-k}\). Specialize your general result to the special case where \(w_{k}=\frac{1}{N}\) for \(k=0,1, \ldots, N-1\).
Find the unit step response for the recursive filter \(x_{n}=a x_{n-1}+w_{0} u_{n}\).
Complex Exponential Sequence
The complex exponential sequence is the sequence
\[u_{k}=e^{j k \theta}, k=0, \pm 1, \pm 2, \ldots \nonumber \]
This sequence, illustrated in Figure 3, is a “discrete-time phasor” that “ratchets” counterclockwise (CCW) as \(k\) moves to \(k+1\) and clockwise (CW) as \(k\) moves to \(k-1\). Each time the phasor ratchets, it turns out an angle of \(\theta\). Why should such a sequence be a useful test sequence? There are two reasons.
(i) \(e^{jk\theta}\) represents (or codes). \(\cos k\theta\). The real part of the sequence \(e^{jk\theta}\) is the cosinusoidal sequence \(\cos k\theta\):
\[\operatorname{Re}\left[e^{j k \theta}\right]=\cos k \theta \nonumber \]
Therefore the discrete-time phasor \(e^{jk\theta}\) represents (or codes) \(\cos k\theta\) in the same way that the continuous-time phasor \(e^{j \omega t}\) codes \(\cos \omega t\). If the moving average filter
\[x_{n}=\sum_{k=0}^{\infty} h_{k} u_{n-k} \nonumber \]
has real coefficients, we can get the response to a cosinusoidal sequence by taking the real part of the following sum:
\[\begin{align}
x_{n} &= \sum_{k=0}^{\infty} h_{k} \cos (n-k) \theta \nonumber \\
&=\operatorname{Re}\left[\sum_{k=0}^{\infty} h_{k} e^{j(n-k) \theta}\right] \nonumber\\
&=\operatorname{Re}\left[e^{j n \theta} \sum_{k=0}^{\infty} h_{k} e^{-j k \theta}\right]
\end{align} \nonumber \]
In this formula, the sum
\(\sum_{k=0}^{\infty} h_{k} e^{-j k \theta}\)
is called the complex frequency response of the filter and is given the symbol
\[H\left(e^{j \theta}\right)=\sum_{k=0}^{\infty} h_{k} e^{-j k \theta} \nonumber \]
This complex frequency response is just a complex number, with a magnitude \(\left|H\left(e^{j \theta}\right)\right|\) and a phase arg \(H\left(e^{j \theta}\right)\). Therefore the output of the moving average filter is
\[\begin{align}
x_{n} &= \qquad \quad \operatorname{Re}\left[e^{j n \theta} H\left(e^{j \theta}\right)\right] \nonumber \\
&=\quad \operatorname{Re}\left[e^{j n \theta}\left|H\left(e^{j \theta}\right)\right| e^{\arg H\left(e^{j \theta}\right)}\right] \nonumber\\
&=\left|H\left(e^{j \theta}\right)\right| \cos \left[n \theta+\arg H\left(e^{j \theta}\right)\right]
\end{align} \nonumber \]
This remarkable result says that the output is also cosinusoidal, but its amplitude is \(\left|H\left(e^{j \theta}\right)\right|\) rather than 1, and its phase is \(argH\left(e^{j \theta}\right)\) rather than 0. In the examples to follow, we will show that the complex “gain” \(H\left(e^{j \theta}\right)\) can be highly selective in \(\theta\), meaning that cosines of some angular frequencies are passed with little attenuation while cosines of other frequencies are dramatically attenuated. By choosing the filter coefficients, we can design the frequency selectivity we would like to have.
(ii) \(e^{jk\theta}\) is a sampled data version of \(e^{j\omega t}\). The discrete-time phasor \(e^{jk\theta}\) can be produced physically by sampling the continuous-time phasor \(e^{j\omega t}\) at the periodic sampling instants \(t_k=kT\):
\[\begin{gathered}
e^{j k \theta}=\left.e^{j \omega t}\right|_{t=k T}=e^{j \omega k T} \\
\theta=\omega T .
\end{gathered} \nonumber \]
The dimensions of \(\theta\) are radians, the dimensions of \(\omega\) are radians/second, and the dimensions of \(T\) are seconds. We call \(T\) the sampling interval and \(\frac{1}{T}\) the sampling rate or sampling frequency. If the original angular frequency of the phasor \(e^{j\omega t}\) is increased to \(\omega+m\left(\frac{2 \pi}{T}\right)\), then the discrete-time phasor remains \(e^{jk\theta}\):
\[\left.e^{j[\omega+m(2 \pi / T)] t}\right|_{t=k T}=e^{j(\omega k T+k m 2 \pi)}=e^{j k \theta} \nonumber \]
This means that all continuous-time phasors of the form \(e^{j[\omega+m(2 \pi / T)] t}\) “hide under the same alias” when viewed through the sampling operation. That is, the sampled-data phasor cannot distinguish the frequency \(\omega\) from the frequency \(\omega+m \frac{2 \pi}{T}\). In your subsequent courses you will study aliasing in more detail and study the Nyquist rule for sampling:
\[T \leq \frac{2 \pi}{\Omega} ; \quad \frac{1}{T} \geq \frac{\Omega}{2 \pi}]
This rule says that you must sample signals at a rate \(\left(\frac{1}{T}\right)\) that exceeds the bandwidth \(\frac{\Omega}{2 \pi}\) of the signal.
Let's pass the cosinusoidal sequence \(u_{k}=\cos k \theta\) through the finite moving average filter
\[\begin{gathered}
x_{n}=\sum_{k=0}^{N-1} h_{k} u_{n-k} \\
h_{k}=\frac{1}{N} k=0,1, \ldots, N-1
\end{gathered} \nonumber \]
We know from our previous result that the output is
\[x_{n}=\left|H\left(e^{j \theta}\right)\right| \cos \left[n \theta+\arg H\left(e^{j \theta}\right)\right] . \nonumber \]
The complex frequency response for this example is
\[\begin{align}
H\left(e^{j \theta}\right) &=\sum_{k=0}^{N-1} \frac{1}{N} e^{-j k \theta} \nonumber \\
&=\frac{1}{N} \frac{1-e^{-j M \theta}}{1-e^{-j \theta}}
\end{align} \nonumber \]
(Do you see your old friend, the finite sum formula, at work?) Let's try to manipulate the result into a more elegant form:
\[\begin{align}
H\left(e^{j \theta}\right) &=\frac{1}{N} \frac{e^{-j(N / 2) \theta}\left[e^{j(N / 2) \theta}-e^{-j(N / 2) \theta}\right]}{e^{-j(\theta / 2)}\left[e^{(\theta 2)}-e^{-j(\theta 2)}\right]} \nonumber \\
&=\frac{1}{N} e^{-j[(N-1) / 2] \theta} \frac{\sin \left(\frac{N}{2} \theta\right)}{\sin \left(\frac{1}{2} \theta\right)} .
\end{align} \nonumber \]
The magnitude of the function \(H(e^{j\theta})\) is
\[\left|H\left(e^{j \theta}\right)\right|=\frac{1}{N},\left|\frac{\sin \left(\frac{N}{2} \theta\right)}{\sin \left(\frac{1}{2} \theta\right)}\right| . \nonumber \]
At \(\theta=0\), corresponding to a “DC phasor,” \(H(e^{j\theta})\) equals 1; at \(\theta=\frac{2 \pi}{N}\left|H\left(e^{j \theta}\right)=0\right|\). The magnitude of the complex frequency response is plotted in Figure 4.
This result shows that the moving average filter is frequency selective, passing low frequencies with gain near 1 and high frequencies with gain near 0.
Compute the phase of the complex frequency response
\(H\left(e^{j \theta}\right)=\frac{1}{N} e^{-j[(N-1) / 2] \theta} \frac{\sin \left(\frac{N}{2} \theta\right)}{\sin \left(\frac{1}{2} \theta\right)}\)
Choose the filter length \(N\) for the filter \(h_{k}=\frac{1}{N}, k=0,1, \ldots, N-1\) so that a 60 Hz cosine, sampled at the rate \(\frac{1}{T} = 180\), is perfectly zeroed out as it comes through the filter.
(MATLAB) Write a MATLAB program to compute and plot the magnitude \(\left|H\left(e^{j \theta}\right)\right|\) and the phase arg \(H\left(e^{j \theta}\right)\) versus \(-\pi < \theta < \pi\) when
\(H\left(e^{j \theta}\right)=\frac{1}{N} e^{-j[(N-1) / 2] \theta} \frac{\sin \left(\frac{N}{2} \theta\right)}{\sin \left(\frac{1}{2} \theta\right)}\)
Choose suitable increments for \(\theta\).
Compute the complex frequency response \(H\left(e^{j \theta}\right)\) for the recursive filter \(x_{n}=a x_{n-1}+w_{0} u_{n}\).