ECE4330 Lecture 23 Sampling and Signal Reconstruction Prof. Mohamad Hassoun

Sampling of Continuous-Time Analog Signals

Discrete-time system implementation is very convenient because it takes advantage of the flexibility and efficiency of digital processors. In practice, most discrete-time systems require us to discretize the (physical) continuous input signal. A sequence 푓[푛] (or 푓[푘]) can be obtained from a continuous-time signal 푓(푡) through sampling. Here, the value of 푓[푛] for some integer 푛 is equal to 푓(푛푇푠), the value of 푓(푡) at time 푡 = 푛푇푠. So, we sample at regular intervals of width 푇푠 seconds or, equivalently, with a 1 sampling rate of 푓푠 = Hz. It is kind of intuitive to argue that sampling 푇푠 generally leads to loss of signal information. But we may also argue that this loss of information about the signal 푓(푡) can be made insignificant if we sample at a very high rate (i.e., select very small 푇푠).

The question now is whether or not, for a finite sampling rate, 푓푠, we can perfectly reconstruct 푓(푡) from its samples, 푓[푛]. If the answer is yes, then we need to answer the following questions: (1) What is a sufficient sampling rate that allows for perfect signal reconstruction? (2) Are there restrictions on the nature of the continuous-time signal 푓(푡) being sampled? (3) Can we derive a formula to reconstruct 푓(푡) from its samples 푓[푛]? (4) Can we realize a physical (or simulated) system that accepts 푓[푛] and generates 푓(푡)?

Surprisingly, the answer to the above questions is affirmative. This is captured by Shannon’s Sampling Theorem: Let 푓(푡) be a real-valued, continuous-time, bandlimited (finite bandwidth) signal with bandwidth 퐵. And let 푓[푛] be the sequence of numbers obtained by sampling 푓(푡) at a sampling rate of 푓푠 samples per second (Hz); i.e., a sample is taken every 1 푇푠 = seconds. Then, 푓(푡) can be perfectly reconstructed from its 푓푠 samples 푓[푛] if and only if 푓푠 > 2퐵. The sampling rate must exceed twice the bandwidth of the signal (2퐵 is referred to as Nyquist sampling rate). Furthermore, 푓(푡) can be uniquely reconstructed by the following formula:

∞ ∞ sin [휋푓푠(푡 − 푛푇푠)] 푓(푡) = ∑ 푓(푛푇푠) = ∑ 푓[푛]sinc [휋푓푠(푡 − 푛푇푠)] 휋푓푠(푡 − 푛푇푠) 푛=−∞ 푛=−∞

In the remainder of this lecture, we will prove the Sampling Theorem and discuss its practical applications to storage and reconstruction of digital data. Again, we will witness the importance of Fourier methods (transform and series) in the analysis and design of sampling systems.

The Sampling Process Today, digital computers are used to store and process physical and synthetic signals in the form of digital data. For example, an audio signal picked up by the microphone of your laptop or smart phone is first sampled and then digitized (amplitude converted into binary code) prior to processing or storage on disk. Later, before the digital audio signal can drive a speaker, the digital amplitudes (binary code) must be converted back into analog values and then reconstructed as a continuous-time signal. The analog to digital conversion is performed using an analog-to- digital convertor (ADC) circuit. Similarly, the digital to analog conversion is performed using a digital-to-analog (DAC) circuit. The following figure illustrates such steps.

In the remainder of this lecture, we will use 푓(푛푇푠) to signify the sampled signal. We will also use the symbol 푓[푛] to represent the value of the 푛th sample of 푓(푡) at time 푛푇푠. It should be stressed here that 푓[푛] is a sequence of numbers. It does not retain any information about the sampling rate or time (i.e., it can’t be displayed on an oscilloscope). On the other hand, 푓(푛푇푠) is the true sampled signal that position its non-zero values at exact time instances, 푛푇푠 (this signal will display physically on an oscilloscope). We will have more to say about this in the next lecture.

As we will see, the real signal 푓(푡) is generally not bandlimited, therefore the reconstructed signal will have some degree of distortion. Another source of distortion is the approximate nature of the reconstruction filter (a low-pass filter) that is used to reconstruct (interpolate) the signal.

Sampling, in theory, consists of simply modulating (multiplying) the signal 푓(푡) by another signal, 훿푠(푡), which consists of a train of unit- impulses separated (in time) by 푇푠 seconds. We will refer to the sampled signal as 푔(푡), and express it analytically as

푔(푡) = 푓(푡)훿푠(푡) = 푓(푡) ∑ 훿(푡 − 푛푇푠) 푛=−∞

Employing the sampling property of the delta function [namely, 푓(푡)훿(푡 − 푎) = 푓(푎)훿(푡 − 푎)] we may express the above expression as

푔(푡) = ∑ 푓(푛푇푠)훿(푡 − 푛푇푠) 푛=−∞ The following figure depicts the sampling process for an arbitrary, bandlimited signal.

We may now gain a better picture of the sampling process by considering the signals in the frequency domain. Let us apply the Fourier transform to the sampled signal

푔(푡) = 푓(푡)훿푠(푡) = 푓(푡) ∑ 훿(푡 − 푛푇푠) (1) 푛=−∞

We will employ the frequency-convolution property 푓1(푡)푓2(푡) ↔ 1 퐹 (휔) ∗ 퐹 (휔). We may also note that 훿 (푡) is a periodic signal (of 2휋 1 2 푠 2휋 fundamental frequency 휔푠 = = 2휋푓푠) having the following exponential 푇푠 Fourier series representation (derive it! This was assigned in Lecture 15)

∞ ∞ ∞ 1 휔푠 푗푛휔푠푡 푗푛휔푠푡 훿푠(푡) = ∑ 훿(푡 − 푛푇푠) = ∑ 푒 = ∑ 푒 푇푠 2휋 푛=−∞ 푛=−∞ 푛=−∞

푗푛휔표푡 By employing the Fourier Pair 푒 ↔ 2휋훿(휔 − 푛휔표) and the superposition property, then the Fourier transform of 훿푠(푡) would be

퐹{훿푠(푡)} = 휔푠 ∑ 훿(휔 − 푛휔푠) 푛=−∞

Transforming the signal 푔(푡) = 푓(푡)훿푠(푡) we obtain

∞ ∞ 1 휔 퐺(휔) = 퐹(휔) ∗ [휔 ∑ 훿(휔 − 푛휔 )] = 푠 ∑ 퐹(휔 − 푛휔 ) 2휋 푠 푠 2휋 푠 푛=−∞ 푛=−∞ where the distributive property and the convolution with a shifted impulse, 퐹(휔) ∗ 훿(휔 − 푛휔푠) = 퐹(휔 − 푛휔푠) were applied. We may also, for convenience, express the above result in terms of the Hz frequency, 푓, as 휔 (recall that 푓 = 푠) 푠 2휋

퐺(푓) = ∑ 푓푠퐹(푓 − 푛푓푠) 푛=−∞

[Do not confuse the Hz frequencies 푓 and 푓푠 with the signal 푓(푡). ]

The above equation represents a very important and elegant result. It states that, in the frequency domain, the sampled signal is essentially a superposition of shifted (by integer multiples of the sampling frequency, 푓푠) versions of the spectrum of the signal 푓(푡). Also, the amplitude of the spectrum 퐺(푓) is scaled by the sampling rate, 푓푠. The following figure depicts, graphically, the magnitude spectra |퐹(푓)| and |퐺(푓)| as a function of frequency, 푓.

Note how the magnitude spectrum |퐹(푓)| is duplicated every 푓푠 (Hz) in the spectrum for |퐺(푓)|. These duplicates are known as the image spectra. It shows that if the sampling frequency 푓푠 is twice the bandwidth (i.e., 푓푠 = 2퐵) of the bandlimited signal 푓(푡), then there will be no overlap between |퐹(푓)| and its images, therefore an ideal (brick-wall) low-pass filter with a 푓 cutoff frequency 푓 = 푠 = 퐵 (and dc gain 푇 ) can be used to perfectly 표 2 푠 reconstruct 푓(푡) (refer to the following figure, Part 푐).

Increasing the sampling rate beyond 2퐵 (푓푠 > 2퐵) allows for further separation between |퐹(푓)| and its adjacent image spectra, and may allow for a practical filter (say a 4th or higher order Butterworth filter) to properly reconstruct the signal 푓(푡) [refer to (푑) in the following figure]. On the other hand if we under sample, 푓푠 < 2퐵, then there will be overlap with the image spectra and the reconstructed signal will always have distortion () [refer to (푏) in the following figure].

The 푓푠 = 2퐵 threshold value on the sampling frequency is known as the Nyquist sampling rate. There are some special bandlimited signals that require the sampling frequency to strictly exceed this sampling rate for perfect reconstruction. Also, for non-bandlimited signals with effective bandwidth 퐵, 푓푠 would have to significantly exceed 2퐵.

Your turn: Consider 푓(푡) = sin(2휋푡) sampled at the Nyquist rate, 푓푠 = 2Hz. Can the reconstruction lead to a unique signal? Explain.

Your turn: Compute the Nyquist sampling rate [think (95%) effective bandwidth 퐵; Lecture 18] for reconstructing the signal

푓(푡) = 0.5푒−|푡| from its samples. Sketch the spectrum, 퐺(푓), of the sampled signal assuming: (1) 푓푠 = 2퐵, (2) 푓푠 = 4퐵 and (3) 푓푠 = 8퐵. What is the smallest sampling rate that is appropriate for this non bandlimited signal? Explain.

Your turn: Repeat the above problem assuming the signal (휎 = 0.5)

푡2 − 푓(푡) = 푒 2휎2

The Sinc Interpolation Formula Next, we derive an analytical formula for reconstructing the signal 푓(푡) from its samples. Assuming the sampling condition 푓푠 ≥ 2퐵 and a brick- wall low-pass reconstruction filter, we may solve for the (zero-state) output 푦(푡) of the filter by convoluting 푔(푡) with the unit-impulse response, ℎ(푡), of the filter, 푦(푡) = 푔(푡) ∗ ℎ(푡). The transfer function of 푓 the filter (a rectangular, brick-wall spectrum with cutoff frequency 푠 and a 2 1 푓 dc gain 푇푠) can be expressed as 퐻(푓) = rect ( ), or 퐻(휔) = 푓푠 푓푠 2휋 휔 rect ( ). We may employ Fourier Pair #18 which is reproduced below 휔푠 휔푠

to find the filter’s impulse response,

2휋 휔푠 휔푠 ℎ(푡) = ( ) ( ) sinc ( 푡) = sinc(휋푓푠푡) 휔푠 2휋 2

sin(휋푓푠푡) where sinc(휋푓푠푡) = . The zero-state response of the filter to the 휋푓푠푡 sampled signal 푔(푡) is then

푓(푡) = 푔(푡) ∗ ℎ(푡) = ∑ 푓(푛푇푠)훿(푡 − 푛푇푠) ∗ sinc(휋푓푠푡) 푛=−∞ which leads to the interpolation formula

푓(푡) = ∑ 푓(푛푇푠) sinc(휋푓푠(푡 − 푛푇푠)) 푛=−∞ Example. Demonstrate the sampling theorem and the sinc interpolation 10휋푡 formula for the signal 푓(푡) = sinc2(5휋푡) = sinc2 ( ). 2

According to the above table, the Fourier transform of 푓(푡) is,

2휋 휔 휔 2휋푓 푓 퐹(휔) = ∆ ( ) = 0.2 ∆ ( ) = 0.2∆ ( ) = 0.2∆ ( ) 10휋 20휋 20휋 20휋 10

The plot of this spectrum is shown below. The even nature of 푓(푡) leads to a real 퐹(휔). Therefore, 푓(푡) is a bandlimited signal, with 퐵 = 5 Hz.

According to the sampling theorem, a sampling rate 푓푠 > 2퐵 = 10 Hz must be used for perfect reconstruction of 푓(푡) from its samples. It means 1 that the sampling period must satisfy 푇 < ≅ 0.1 sec. The following 푠 10 figure depicts the spectrum of the sampled signal,

∞ ∞ 푓 − 푛푓 퐺(푓) = 푓 ∑ 퐹(푓 − 푛푓 ) = 0.2푓 ∑ ∆ ( 푠) 푠 푠 푠 10 푛=−∞ 푛=−∞ for: (푎) Under-sampling (푇푠 = 0.2 or 푓푠 = 퐵 = 5 Hz) (푏) Nyquist sampling rate (푇푠 = 0.1 or 푓푠 = 2퐵 = 10 Hz) and (푐) Over-sampling (푇푠 = 0.05 or 푓푠 = 4퐵 = 20 Hz).

Sampling at a faster rate than the Nyquist rate would allow for signal reconstruction employing a practical low-pass filter. One possible filter (for the sampling rate 푓푠 = 20Hz) would be a fourth-order Butterworth 1 filter with dc gain of 푇푠 = = 0.05 and cutoff frequency 휔표 = 푓푠 15휋 rad/sec [determined by inspecting the above figure, Part (푐)]

0.05 퐻(푠) = 푠 4 푠 3 푠 2 푠 ( ) + 2.61 ( ) + 3.41 ( ) + 2.61 ( ) + 1 15휋 15휋 15휋 15휋 The following Mathcad simulation gives illustrates the quality of the above reconstruction. In the simulation, the dc-gain was artificially scaled by 80 in order to scale the filter spectrum to allow for ease of visualization. It is obvious that the filter will pass portions of the adjacent image spectrum and, therefore, a higher order filter (say, 푛 ≥ 6) would be required in order to reduce distortion. (Note: 푓푠 = 20Hz ≅ 126 rad/s.)

Your turn: Repeat the above Mathcad simulation with a 6th-order and an 8th-order Butterworth filter. Compare plots. The following figure show the result of solving the inverse Fourier integral numerically (using Mathcad) to obtain the filter output 푦(푡) and compares it to the signal 푓(푡). When plotting 푦(푡) we need to actually plot the real component of 푦(푡) in order to get rid of any residual imaginary values that result from the numerical integration.

The following figure duplicates the above figure but with the filter delay

푡푑 eliminated by shifting the signal 푦(푡) by 푡푑 seconds to the left.

One may solve for the proper sampling rate 푓푠 such that a practical finite- order, low-pass filter can achieve minimal reconstruction distortion. Consider the spectrum of a sampled signal of bandwidth 퐵, as show in the figure below. Determine the sampling rate 푓푠 such that a fifth-order low- pass Butterworth filter would meet the requirements of |퐻(퐵)| = .9995, and |퐻(푓푠 − 퐵)| = 0.001. (Refer to the green plot in the following figure.)

From an earlier lecture, we know that the magnitude response of an order 푛 low-pass Butterworth filter, with unit-gain at dc and cutoff frequency

휔표, is given by 1 1 |퐻(휔)| = or |퐻(푓)| = 휔 2푛 √1+( ) 푓 2푛 휔표 √1+( ) 푓표

Therefore, to meet the above specifications, we set up the following system of equations,

1 퐵 |퐻(퐵)| = = 0.9995 → = 0.501 퐵 10 푓 √1+( ) 표 푓표

1 푓푠−퐵 |퐻(푓푠 − 퐵)| = = 0.001 → = 3.981 푓표 푓 −퐵 10 √1+( 푠 ) 푓표

푓 −퐵 3.981 leading to the requirement: 푠 = ≅ 7.95, or 푓 ≅ 9퐵 (a sampling 퐵 0.501 푠 rate that is about 4.5 times the Nyquist rate). Your turn: repeat the above analysis assuming a filter with 푛 = 8. Next, let us employ the interpolation formula to construct the signal from its samples: ∞

푓(푡) = ∑ 푓(푛푇푠) sinc(휋푓푠(푡 − 푛푇푠)) 푛=−∞ ∞ 2 = ∑ sinc (5휋푛푇푠) sinc(휋푓푠(푡 − 푛푇푠)) 푛=−∞

The following Mathcad simulations are performed for 푇푠 = 0.05 (푓푠 = 20), 0.1(푓푠 = 10) and 0.15 (푓푠 = 6.67). The summation limits for 푛 are set to a finite value as opposed to ∞.

The above plot shows the reconstructed signal (blue), the actual signal (red) and the first five sinc components. The sampling rate was set to 푇푠 = 0.05. Results for 푇푠 = 0.05 (over-sampling)

Results for 푇푠 = 0.1 (Nyquist sampling rate)

Results for 푇푠 = 0.15 (under sampling)

Your turn: Utilize the interpolation formula in order to generate plots similar to the above Mathcad plots (consider over-sampling, Nyquist rate and under-sampling cases) for the bandlimited signal 푓(푡) = sinc(5휋푡).

The sinc interpolation formula is a very powerful theoretical result. It guarantees perfect reconstruction of a bandlimited signal from its samples as long as the sampling is done at a rate higher than twice the signal’s bandwidth. The formula can be programmed on a digital computer. In effect, the digital implementation implies that we are able to implement an ideal brick-wall low-pass filter with impulsive sampling (a feat that is impossible with analog circuits!). Unfortunately, from a practical stand point, the formula is not very useful; it requires the sum of a large number of everlasting sinc signals, thus making it very slow to be practical. Just imagine how long it would take to stream a movie from its digitized samples while needing to perform the calculations required by this formula, in real time.

Example. Knowing that the Nyquist rate for the bandlimited signal 푓(푡) with bandwidth 퐵 (in Hz) is 2퐵, determine the Nyquist rate for the signal

푦(푡) = 푓̇(푡) Solution. Employing the differentiation property of the Fourier transform we may write, 푌(휔) = 푗휔퐹(휔). Being a bandlimited signal with bandwidth 퐵 means that 퐹(휔) = 0, for |휔| > 2휋퐵. That is also true for 휔퐹(휔). Therefore, we conclude that 푌(휔) has the same bandwidth as 퐹(휔). In turn, 푓̇(푡) has the same Nyquist rate as 푓(푡): Differentiation has no effect on the bandwidth (or Nyquist rate) of a signal.

Your turn: Consider a signal 푓(푡) with bandwidth 퐵. Determine the bandwidth for the signals:

2 a. 푓(2푡) b. 푓 (푡) c. 푓(푡)cos(휔표푡) d. 푡푓(푡) Your turn: Compute the Nyquist sampling rate for reconstructing the following bandlimited signal from its samples,

sin(40휋푡) sin(60휋푡) 푓(푡) = 휋2푡2

Your turn: The following signal is sampled every 1/6 seconds. Plot the spectrum of the sampled signal.

sin(2휋푡) 푓(푡) = [1 + 2 cos(4휋푡)] 휋푡

Your turn: A bandlimited signal 푓(푡) has the spectrum shown in the following figure. If the signal is sampled at 10 samples per second and then passed through an ideal brick-wall low-pass filter with cutoff frequency of 5 Hz, sketch the spectrum of the output signal.

Your turn: A spoken-word narration recorded on a book-on-CD is bandlimited to 4 kHz. The narration is sampled at the standard rate of 44,100 samples/sec. To reconstruct it, the sampled narration is passed through a Butterworth low-pass filter with a cutoff frequency of 4 kHz. What is the minimum filter order required so that all parts of the sampled signal spectrum in the region |푓| > 퐵 are reduced to at most 0.001 of their values?

Your turn: Show that, ∞ sin(4휋(푡 − 푛)) sin(4휋(푡 − 푛 − 0.5)) ∑ [ − ] = cos (2휋푡) 4휋(푡 − 푛) 4휋(푡 − 푛 − 0.5) 푛=−∞ Practical Sampling and Reconstruction of Signals

In practice, we encounter three problems in the physical circuit realization of an ideal sampling system: (1) The sampling signal consists of unit- impulses which are physically impossible to generate; (2) The brick-wall filter is not possible to realize physically; and (3) Real signals are not bandlimited. This last issue will be addressed in the next section.

The brick-wall filter requirement can be alleviated by employing a high- order low-pass filter combined with . Over sampling will separate the image spectra of the sampled signal so as to allow for a practical filter to perform the filtering satisfactorily. However, too much oversampling can be disadvantageous because it leads to higher volume of data when it comes to electronic storage.

As for the sampling signal, we show next that a sampling signal consisting of a train of short duration finite-amplitude pulses can be used. Let us consider, as an example, the bandlimited signal 푓(푡) = sinc2(5휋푡) whose 휔 Fourier transform is 퐹(휔) = 0.2 ∆ ( ). Also, let us assume the pulse- 20휋 train sampling signal, 푝푇(푡), as shown in the figure below. This is a 2휋 periodic signal with a fundamental frequency 휔푠 = . 푇푠

Employing trigonometric Fourier series expansion we may express 푝푇(푡) as [푏푛 = 0 because the sampling signal has even symmetry. Refer to the Fourier Series Table in Lecture 14], ∞ ∞ 휏 2 푛휋휏 푝푇(푡) = 푎0 + ∑ 푎푛cos (푛휔푠푡) = + ∑ sin ( ) cos(푛휔푠푡) 푇푠 푛휋 푇푠 푛=1 푛=1 The sampled signal 푔(푡) is then given by (see its plot on the next page)

푔(푡) = 푓(푡)푝푇(푡) = 푎0푓(푡) + ∑ 푎푛푓(푡) cos(푛휔푠푡) 푛=1

Since the signal Bandwidth is 5 Hz, we set the sampling rate to 푓푠 = 10 Hz (leading to a pulse train period of 푇푠 = 0.1 sec). Therefore, 휔푠 = 20휋. We will assume a narrow pulse width of 휏 = 0.025 sec. This leads to a 휏 1 pulse train of duty cycle = or 25%. Therefore, the Fourier coefficients 푇푠 4 for 푝푇(푡) are 1 √2 1 √2 −√2 푎 = , 푎 = , 푎 = , 푎 = , 푎 = , … 0 4 1 휋 2 휋 3 3휋 4 5휋 Consequently, 1 √2 1 푔(푡) = 푓(푡) + 푓(푡) cos(20휋푡) + 푓(푡) cos(40휋푡) 4 휋 휋 √2 √2 + 푓(푡) cos(60휋푡) − 푓(푡) cos(80휋푡) + ⋯ 3휋 5휋 and its Fourier transform is (your turn: confirm the transform)

1 1 퐺(휔) = 퐹(휔) + [퐹(휔 − 20휋) + 퐹(휔 + 20휋)] 4 휋√2 1 + [퐹(휔 − 40휋) + 퐹(휔 + 40휋)] 2휋 1 + [퐹(휔 − 60휋) + 퐹(휔 + 60휋)] + ⋯ 3휋√2

This spectrum is depicted in the figure below.

From the last equation on the previous page we find that the fundamental 휏 spectra (centered at the origin) is scaled by 푎0 = . Also, the 푛th image 푇푠 1 푛휋휏 spectrum is scaled by 퐴푛 = sin ( ), 푛 = 0,1,2,3, … 푛휋 푇푠

Observe that the spectrum consists of the 퐴푛퐹(휔 ± 푛휔푠) components repeating periodically at 푛휔푠 = 20휋푛 (or 푛푓푠 = 10푛 Hz). Hence, there is no overlap among the adjacent image spectra and we may recover 푓(푡) by using an ideal low-pass filter with cutoff frequency of 푓표 = 5Hz, and dc 1 휏 1 gain of = 4, where 퐴0 = = is the duty cycle of the sampling pulse 퐴0 푇푠 4 signal. Hence, the output of the filter is (theoretically) a perfect 푓(푡).

Your turn: Solve Problem 5.1-6 in your textbook. −|푡| Your turn challenge: The signal 푓(푡) = 푒 has been sampled at 푓푠 = 1 Hz. Determine the optimal cutoff frequency, 휔표, for a third-order Butterworth low-pass filter such that the filter’s output 푓̃(푡) shape is “as close as possible” to that of 푓(푡). Provide a plot comparing 푓(푡) to 푓̃(푡). Formulate the problem as an optimization problem with a proper objective function, 퐼(휔표), and find the solution by applying suitable numerical methods (refer to Appendix for more on this). You may use Mathcad. Animation:

Animation.avi Simulink Examples of the Sample/Reconstruct Process

The following simulation assumes a continuous-time signal 푓(푡) = cos (1.6휋푡) is to be sampled using a unit-amplitude pulse train signal, and then reconstructed using a proper low-pass filter.

The sinusoid frequency is 푓 = 0.8Hz (which is also its bandwidth). The proper sampling rate, 푓푠, should be 푓푠 > 2퐵 = 1.6Hz. Therefore, we 1 choose 푓푠 = 5Hz leading to a pulse train period of 푇푠 = = 0.2. The 푓푠 pulse duration 휏 will be set to 0.01 which leads to a 5% duty cycle (i.e., 휏/푇푠 = 0.05). We design the filter to be an order 10 Butterworth low-pass analog filter, with cutoff frequency 푓표 = 1Hz (a frequency above the 0.8 푓 Hz signal frequency, but well under 푠 = 2.5Hz so we avoid aliasing). 2

The Simulink system is shown in the figure below. The gain block value is 1 푇 0.2 1 1 set to = 푠 = = = = 20. 휏푓푠 휏 0.01 푑푢푡푦 푐푦푐푙푒 0.05

The following are simulations with various values of sampling rates. Scope1 shows the input signal and its sampled signal. Scope shows the input signal (blue) and the filter (reconstructed) output (yellow). 푓푠 = 5 > 2퐵 = 1.6:

푓푠 = 1.25 < 2퐵 (leads to aliasing):

In order to understand the aliasing exhibited in the above figure (푓푠 = 1.25), the reader is referred to the following spectra of the sampled sinusoid. The first two sets of image spectra is represented by the pair of impulses at frequencies 1.25 ± 0.8 = 2.05, 0.45 and the pair of impulses at frequencies −1.25 ± 0.8 = −2.05, −0.45, respectively.

In addition to passing the desired impulses at ±0.8 Hz, the low-pass filter will also pass the image impulses at ±0.45 Hz. This leads to aliasing due to under sampling. In fact, one can express the reconstructed signal as

푦(푡) ≅ 20[푎0 cos(2휋(0.8)푡) + 푎1 cos(2휋(0.45푡)] 휏 1 휋휏 = 20 [ cos(2휋(0.8)푡) + sin ( ) cos(2휋(0.45푡))] 푇푠 휋 푇푠 1 = 20 [0.05 cos(2휋(0.8)푡) + sin(0.05휋) cos(2휋(0.45푡))] 휋 whose plot (see below) is very similar to the above simulation result.

In practice, the sampled signal is quantized (one value used for each pulse period) and the corresponding binary values are saved inside a digital machine. An alternative way to reconstruction is one based on a sample- and-hold circuit. The following Simulink model repeats the above simulations employing a sample-and-hold block with sample hold time of 0.1 and 0.8, respectively. Here, no amplification is needed.

Sample hold time of 0.1 sec:

Sample hold time of 0.8 sec (leads to aliasing; why?)

Your turn: Experiment with the above sampling/reconstruction models by varying the filter’s order and its cutoff frequency.

Example. Consider the non-bandlimited triangular pulse signal of amplitude 1, width 1 and center at the origin. Determine a proper sampling frequency so that the signal can be reconstructed by an 8th-order low-pass Butterworth filter. Employ Simulink. From Lecture 18, we determined that the (95%) effective bandwidth 퐵 for this signal is 퐵 = 1Hz. So, the sampling frequency should be greater than 2퐵 = 2Hz, as per the Sampling Theorem for bandlimited signals. However, since the triangular pulse signal is not bandlimited, we must use a sampling frequency that is significantly higher than 2퐵 in order to prevent aliasing. The Fourier transform of the impulse-train-sampled signal is ∞

퐺(푓) = 푓푠 ∑ 퐹(푓 − 푛푓푠) 푛=−∞

The following is a plot of the normalized spectrum for 푓푠 = 20.

The following is the (zoomed-in) plot for the first two spectral lobes at 푓푠 = 10Hz,

The following is the (zoomed-in) plot for the first two spectral lobes at 푓푠 = 40Hz,

The last plot suggests that sampling with 푓푠 = 40Hz (or 푇푠 = 0.025 sec) is appropriate (it shows very small overlap with adjacent spectral images). The sampling signal will be set to a pulse signal with 푇푠 = 0.025 and 휏/푇푠 = 5% duty cycle. This will require a gain stage of 퐾 = 푇푠/휏 = 1/0.05 = 20, after the filter. An 8th-order Butterworth low-pass filter with cutoff frequency of 푓표 = 푓푠/2 = 20Hz should be adequate to reconstruct the signal. The following are the Simulink results.

As would be expected, increasing the order of the filter will improve the reconstruction results. The following plot shows the signal at the output of the filter for a 10th-order Butterworth filter.

Distortion kicks in if we reduce the cutoff frequency of the filter, as can be th seen in the figure below for 푓표 = 5Hz (with 푓푠 = 40Hz and 8 -order). What is the source of signal distortion that you see in the figure?

The following plot depicts the signal reconstruction result for the case 푓 푓 = 10Hz and filter cutoff frequency of 푓 = 푠 = 5Hz (with filter order 푠 표 2 set to 8). What is the source of distortion in this case?

The following are the results for the system employing sample-an-hold with 푓푠 = 40Hz and filter cutoff frequency, 푓표 = 20Hz. In this case, the amplifier is not needed.

Sampled input signal,

Filter output,

Your turn: Repeat the above simulations for the signal, 푓(푡) = 푢(푡) − 푢(푡 + 1) Your turn: Show that the signal,

휋 cos ( 푡) 푓(푡) = 2 휋(1 − 푡2) can be sampled (using an impulse train) and then reconstructed perfectly ∗ using a low-pass filter. What is the smallest sampling frequency, 푓푠 , required for perfect reconstruction with a brick-wall filter having a cut-off ∗ ∗ frequency 휔표 = 2휋(푓푠 /2) = 휋푓푠 ? Perform numerical simulations (use 푓푠 = 1Hz) that solves for the reconstructed signal with a Butterworth low- pass filter 퐻(휔), with 휔표 = 휋. Try filters with order 2, 4 and 8. Assume the sampled signal spectrum is approximated as, 퐺(휔) = 퐹(휔) + 퐹(휔 − 2휋) + 퐹(휔 + 2휋) + 퐹(휔 − 4휋) + 퐹(휔 + 4휋) Experimental Demonstrations: Sampling of a Triangular Signal

Location of images: "C:\Users\aa0030\Desktop\ECE4330\Lecture 23 examples\Sampling of 1KHz triangular signal"

Experiment 1:

Signal 푓(푡): Triangular wave, 1Vpp, 1 kHz.

Sampling signal: Positive pulse train, 1V, 푓푠 = 10kHz, 20% duty cycle Reconstructed signal with 8th-order low-pass Butterworth filter. Filter cutoff frequency:

3 kHz 4 kHz

5 kHz 6 kHz

7 kHz 8 kHz

Since 푓(푡) has no jump discontinuity we would expect that most of its energy to be concentrated in the first few harmonic components (think Fourier series coefficients, 퐶푛). Also, because of the half-wave symmetry nature of 푓(푡) we would expect all even harmonics to be non-existent. Therefore, the significant harmonics of 푓(푡) are at frequencies: 1 kHz, 3 kHz, 5 kHz, 7 kHz, 9 kHz and 11 kHz. The following two plots show the magnitude spectrum of the sampled signal and that of the reconstructed signal (with filter’s cutoff frequency set to 푓표 = 7 kHz), respectively. Note how the first image spectrum (centered at 10 kHz) overlaps with the signal’s spectrum (centered at 0 Hz). In this case, the filter passes some of the first image spectrum components (at 5 kHz, 7 kHz, 9 kHz and 11 kHz). This leads to aliasing.

Magnitude spectrum of the sampled signal (푓푠 = 10 kHz):

Magnitude spectrum of the reconstructed signal (cutoff at 푓표 = 7 kHz):

Experiment 2:

Signal 푓(푡): Triangular wave, 1Vpp, 1 kHz. Sampling signal: Positive pulse train, 1V, 푓푠 = 40kHz, 20% duty cycle Reconstructed signal with 8th-order low-pass Butterworth filter. Filter cutoff frequency: 4 kHz 8 kHz

15 kHz 20 kHz

30 kHz 35 kHz

Reconstruction of Sampled Signals with a Zero-Order-Hold Circuit In the preceding Simulink simulation, we have employed a practical zero- order-hold block/circuit in order to implement the sampling process. In this section, we will investigate the theoretical basis for such a circuit and show how zero-order-hold can be used to reconstruct a sampled signal.

A zero-order-hold system is a form of simple interpolation where discrete samples are connected by a line of zero-slope (a constant), as shown in the figure below.

What is the frequency response function, 퐻0(휔) of such a system? Well, let us consider the response, 푦(푡), of a period-푇 zero-order-hold system to a single sample 푔푖(푡) = 퐴푖훿(푡). The following figure depicts the desired response,

Analytically, the response is depicted in the following figure,

We are then looking for a system whose impulse response satisfies the convolution equation

퐴푖훿(푡) ∗ ℎ0(푡) = 퐴푖[푢(푡 + 푇/2) − 푢(푡 − 푇/2)] which, upon employing the convolution property of the unit-impulse, leads to the solution,

ℎ0(푡) = [푢(푡 + 푇/2) − 푢(푡 − 푇/2)]

Therefore, the zero-order-hold system with hold time 푇 has the unit- 푡 impulse response, ℎ (푡) = rect ( ), 0 푇

The Fourier transform for this signal was derived in an earlier lecture and it is given by 푇휔 푇휔 2 sin ( ) 퐻 (휔) = 푇sinc ( ) = 2 0 2 휔

The zero-order-hold is a relatively poor reconstruction filter compared to the ideal brick-wall reconstruction filter, 휔푇 퐻(휔) = 푇 rect ( ) 2휋 The following figure compares the magnitude response of the ideal and zero-order-hold reconstruction filters.

Note that in the context of sampling, we should set the hold period according to, 푇 ≤ 푇푠. The following Mathcad simulation (with 푇 = 푇푠 = 0.2) depicts the zero-order-hold filter’s output, 푦(푡), for the sampled version of 푓(푡) = sin(휋푡). ∞

푔(푡) = sin(휋푡)훿푠(푡) = ∑ sin (휋푘푇푠)훿(푡 − 푘푇푠) 푘=−∞ The output can be expressed as ∞

푦(푡) = 푔(푡) ∗ ℎ0(푡) = ∑ sin(휋푘푇푠) ℎ0(푡 − 푘푇푠) 푘=−∞

The impulse response of the above zero-order hold is noncausal, and therefore, the filter is not realizable. In practice, we make it realizable (causal) by delaying the impulse response by 푇/2. This merely delays the output of the filter by 푇/2.

In many situations, if the hold period 푇 is small enough, the output of the zero-order hold filter is considered an adequate approximation of the original signal, 푓(푡). In the case a closer approximation is required, the jump discontinuities in the zero-order hold filter output can be smoothed by applying a low-pass filter with a cutoff frequency equal to the bandwidth of the signal being sampled, 푓(푡). In some cases, such as in the case of the reconstructed signal driving a speaker, the physical system being driven by the reconstructed signal has intrinsic low-pass filtering characteristics. In such cases, the low-pass filter is not needed.

The following simulation depicts the output (black trace) of a 3rd-order low-pass Butterworth filter [with 휔푐 = 휋 and 푇 = 푇푠 = 0.2 and 푓(푡) = sin(휋푡)푢(푡)] that receives, as input, the output from the zero-order hold filter.

Your turn: Employ Mathcad to perform a simulation that results in the above plot. Hint: Determine the unit-impulse response of the system and then employ scaling, shift and superposition. Your turn: A first-order hold filter can be used to improve on the reconstruction results achieved by the zero-order filter. The idea here is to employ a more accurate linear interpolation between the sample points; adjacent samples are connected by a line segment. It can be shown that the unit-impulse response of the first-order hold filter is the triangle pulse,

2 푇 푡 푇 4 sin ( 휔) ℎ (푡) = ∆ ( ) ↔ 퐻 (휔) = 푇 sinc2 ( 휔) = ( ) 2 1 2푇 1 2 푇 휔2

Employ Mathcad to determine and plot the response, 푦(푡), of a first-order- hold filter due to the sampled input signal 푔(푡) = sin(2휋푡) 훿푠(푡). Assume 푇 = 푇푠 = 0.3. Repeat for 푇푠 = 0.2 and 0.1. The following plot illustrates how linear interpolation/reconstruction works, for 푇푠 = 0.3.

Your turn: Consider the sampling system with zero-order hold and first- order hold as shown below. Determine and plot ℎ(푡) and 퐻(휔) for the overall filter. Also, determine and plot the zero-state response, 푦(푡).

Real Signals and the Antialiasing Filter

For a signal 푓(푡) to be bandlimited, it must be everlasting (exists for 푡 ∈ [−∞ ∞]). Physical signals are not everlasting, hence they are not band- limited. This means that the repeating (shifted) lobes of the spectrum of the sampled signal will always have some overlap. But, fortunately, most of the signal energy (information) is available within a limited band of frequencies (recall the concept of effective bandwidth, 퐵, of a signal form Lecture 18). This allows us to transform the signal 푓(푡) into a bandlimited signal 푓(̅ 푡) by simply preprocessing it through a low-pass (antialiasing) filter. This pre-filtering would also eliminate high frequency noise. The 푓 cutoff frequency of such filter is typically set at 푠, where 푓 is the 2 푠 ̅ sampling rate (푓푠 > 2퐵). Then, the signal 푓(푡) is sampled as depicted in the figure shown below.

A block diagram for a complete system that samples, digitizes and stores the samples of an analog signal is shown below. The diagram also depicts the reconstruction steps needed to recover the analog signal from its digitized samples.

In the above system, one would wonder why we multiply again by the pulse train signal 푝푇(푡) just before the reconstruction filter. Well, recall that the stored samples 푓[푛] are a sequence of values and have no time base associated with them. Therefore, they need to be converted to a physical signal 푓(푛푇푠). The multiplication of the sequence values 푓[푛] by a train of very narrow pulses and period 푇푠 leads to such a signal; i.e., consecutive samples will ride consecutive pulses.

The standard sampling rate for audio signals is 44.1 kHz. It originated in the late 1970s for recorded digital audio on video cassettes by Sony. This then became the basis for Compact Disc digital audio. Its use has continued in DVD. This sampling frequency is commonly used for MP3 and other consumer audio files, and has become the standard. Why use 풇풔 = ퟒퟒ. ퟏ kHz for Audio Signals? Since human hearing range is roughly 20 Hz to 20 kHz, the sampling rate had to be greater than 40 kHz (per the Nyquist sampling rate). It is interesting to view the human hearing system as having a bandpass filter characteristics that only passes the 20 Hz – 20 kHz frequency band. Also, it should be noted here that the bandwidth of speech signals is from 50 Hz to 10 kHz. And for music is from 15 Hz to 20 kHz. In addition, audio signals are not bandlimited and must be low-pass filtered before sampling to avoid aliasing. While an ideal low-pass filter would perfectly pass frequencies below 20 kHz (without attenuating them) and perfectly cutoff frequencies above 20 kHz, in practice a transition band is necessary. The wider this transition band is, the easier and more economical it is to make an anti-aliasing filter (the lower is the filter order). The 44.1 kHz sampling frequency allows for such transition band. It is interesting to note that the number 44,100 is the product of the squares of the first four prime numbers [(22)( 32)(52)(72)]. Another common sampling rate for audio signals is 48 kHz. This sampling rate allows for larger transition band for the aliasing filter.

Your turn: Solve Problem 5.1-4 (p. 358) in your textbook.

The second appendix in this lecture considers the effect of under sampling a sinusoid and relates it to the illusion of a human seeing a clockwise spinning wheel as spinning in the opposite direction, or even standing still!

Your Turn: (work on this problem in groups)

휋 1 3휋 Ans. 푦 (푡) = cos ( 푡) − sin ( 푡) 푓 2푇 4 4푇

Your Turn: (work on this problem in groups)

a. Sketch the Fourier transform of 푥푓(푡) for the case when 퐾 = 1 and 푇 = 1. b. Find 푇 (keeping 퐾 = 1) so that 푥푓(푡) = 푥푎(푡)? Note: there are multiple solutions. Ans. a.

2 4 b. 푇 ∈ { , , … ,2} 7 7 Appendix I Computing the inverse Fourier transform numerically with Mathcad

Consider the problem of filtering the signal 푓(푡) = 푒−|푡| using an 8th-order Butterworth low-pass filter (with 휔표 = 4), where the zero-state response of the filter is 푓̃(푡) = 퐹−1{퐻(휔)퐹(휔)}. The following Mathcad session illustrates how the numerical computation of the inverse Fourier transform is obtained.

In the above numerical computations, the real part of the inverse transform is employed because the numerical solution for the Fourier integral can exhibit a tiny imaginary part in the answers due to machine round off error. This part must be suppressed because this is a simulation of a physically realizable system.

Appendix II: Under sampling and Wagon Wheels

When a sinusoid of frequency 푓 is under sampled at a sampling rate 푓푠 < 2푓, the reconstructed signal (using an ideal brick wall filter or, equivalently, using the sinc interpolation formula, as shown below) will also be sinusoidal but with a frequency different from 푓. The following Mathcad simulation illustrates this aliasing phenomenon for a sinusoid with 푓 = 1Hz and 푓푠 = 3, 1.9, 1.5, 1 and 0.8

The following animation shows the reconstructed signal as the sampling frequency changes from under-sampling to over-sampling. At 푓푠 = 푓 the oscillation seizes.

aliasing movie Sampling_fan_demo. sinusoid.avi MOV This explains the illusion of humans seeing cart wheels or fans look as if they were spinning slowly in the opposite direction of the actual spin, or even seeing the spinning object stationary. The reason is that the human visual circuits operate at a rate about 60-100 frames/sec. So, the visual system is actually a sampling/ reconstruction system that exhibits aliasing when it under samples! Watch the following videos: Video games and frames per second https://en.wikipedia.org/wiki/Wagon-wheel_effect

Your turn: An animation shows a spinning wagon wheel on your computer screen with the graphics rendered in 20 frames per second. Assume that the wheel is spinning somewhere between 20 rpm, and 200 rpm (rotations per minute).

 Is the 20 frames per second screen refresh rate adequate to show a smoothly spinning wheel animation?  Would the human visual system oversample or undersample the spinning wheel, if it was a real-life spinning wheel?  At what non-zero value(s) of (animated) wheel rpm does a human looking at the spinning wheel video (assuming, again, a 20 Hz refresh rate) perceive a still wheel? Hint: think of the time it takes one spoke to moves from its current position to the position of its immediate neighboring spoke.  Verify your answer using the following applet: http://www.michaelbach.de/ot/mot-wagonWheel/index.html

Mini Project Design and build a sampling/reconstruction system that samples an 8 kHz sinusoid. Employ a pulse train (from a pulse generator) with 5% duty cycle to sample the signal. The oscilloscope display of the input, sampled and reconstructed signals must be included in your report.

The analog multiplier AD633 chip (or the wide bandwidth precision MPY634; refer to the attached data sheet) can be used to perform the sampling. (You will need to amplify the output by 10.) Alternatively, you may use the sample-and-hold LF398 chip.

th  The low-pass 6 -order Butterworth filter (with 휔표 = 10 kHz)from the mini project at the end of Lecture 19 may be used to reconstruct the signal  Experiment with the following sampling frequencies: 10 kHz, 16 kHz, 20 kHz, 24 kHz and 40 kHz. For each of these frequencies, sketch the spectrum of the sampled signal and superimpose on it your filter’s magnitude response.  Since you are not applying ADC/DAC to the signal, the block diagram of the system you are asked to build is shown below.

Mini project Simulink results:

Settings: Low-pass Butterworth filter with order 6 and cutoff frequency = 10 kHz Input sinusoid frequency = 8 KHz. (Note: Nyquist rate = (2)8 kHz = 16 kHz.) Sampling Pulse duty cycle is fixed at 5% (this requires a voltage amplifier, placed after the filter, of gain 20).

Simulation 1: 푓푠 = 20 kHz (Why is the output distorted? Refer to the next “Your turn” problem.)

Simulation 2: 푓푠 = 24 kHz

Simulation 3: 푓푠 = 40 kHz

Your turn: Justify the aliasing effects seen in Simulation 1 (shown above) by plotting the (steady-state) response of the 6th-order Butterworth filter (푓표 = 10 kHz) to the signal 푓(푡) = sin(2휋8000푡) + sin(2휋12000푡). You may use Mathcad to determine the filter’s response. Include this analysis in your mini project report. Where does the component signal sin(2휋12000푡) come from? Explain.

Ans.

Sample Student Result This results is based on the 6th-order low-pass Butterworth filter, of student Alex Pluff, presented at the end of Lecture 19. Input sinusoid frequency = 8 kHz and sampling signal (pulse-train) of 24 kHz at 5% duty-cycle were used.

A Practical Sampling/Reconstruction Circuit

The following is an alternative signal sampling/reconstruction circuit.

Sample Student Work Employing the Above Circuit

Watch video: https://youtu.be/2S8i9v-lD_M

Data Sheet for a Wide Band Analog Multiplier (MPY634)

Data Sheet for a Sample and Hold Circuit (LF398)