Вы находитесь на странице: 1из 8

ECE 3512 Spring 2011 (Assignment #5)

Preventing the Effects of Aliasing


Nabidur Rahman & Asish Mathew
AbstractAn anti-aliasing filter is a filter that is implemented before the signal is sampled, whose primary purpose is to limit the bandwidth of a given signal to satisfy the Nyquist Theorem. The Nyquist Theorem involves the concept of sampling, a process in where a signal is converted into a numeric sequence in the discrete time domain. By converting a continuous time signal to a discrete time signal, sampling allows us to analyze a set of data points on a specified value. This process can also trigger aliasing, an effect that causes signals to become distorted and indistinguishable from other signals. Applying our knowledge of filters, our objective is to design a filter that can limit the amount of aliasing that occurs when a signal is sampled.

The figure shown shows that the continuous signal is sampled by the black dots, with 6 samples per second using equation 1. The concept of sampling was derived from the Nyquist Theorem, which states that an analog signal that has been sampled can be perfectly rebuilt from an infinite sequence of samples denoted as the variable n. In order to sufficiently sample a signal, the sampling rate must exceed twice the Nyquist frequency specified. The more samples on the original signal, the better the resulting output signal will become. The Nyquist Theorem can be defined using the two equations where is the sampling rate and f as the Nyquist frequency:

I. INTRODUCTION HE objective of this assignment is to understand what sampling is and its applications in Signal Processing. When a signal is converted from its continuous state to discrete, sampling can be done to analyze a set amount of values. To sample a signal, a sampling rate, , must be defined as it is the number of samples obtained in one second. Taking that intuition into account, the following equations can determine the sampling interval: = 1 1 = (1)

2 (2) 2

Sampling is essentially a process that involves multiplying the continuous time signal with an impulse train which is further related to x[n]. The equation and its graphical representation is given below:

xn = ( )( ) (3)

A visual representation of this principle is shown below:


Example of Sampling a Cosine Signal 1.5 Original DT Sample 1

x(t)

0.5

x(t)

-0.5

-1

Figure 2 Process of Sampling where an impulse train and a cosine signal are multiplied together to form the discrete sampling range
0 0.5 1 1.5 2 time (sec) 2.5 3 3.5 4

-1.5

Figure 1 Signal Sampling Representation where the continuous signal is in blue and the discrete samples are represented in black

Keeping this intuition in mind, its important to note that when sampling a continuous signal, the effect of aliasing occurs. Aliasing is where distortion or noise occurs if the signal is measured at an insufficient sampling rate. For example, if we were to sample a signal whose Nyquist frequency is 500 Hz, the sampling rate must be set at least 1000 Hz to avoid aliasing (Equation 2 supports this theory). If

ECE 3512 Spring 2011 (Assignment #5) we sampled the same signal at 700 Hz, some aliasing would occur which would impair the resulting output in comparison to the original. Frequency values above or close to the Nyquist frequency may distort or alias the resulting signal, so we must somehow eliminate these aliasing elements. The objective of this assignment is to answer this very question: designing an anti-aliasing filter that can eliminate frequencies above the Nyquist Frequency. In order to prevent aliasing, it is essential to pass a continuous time signal through an anti-aliasing filter before the process of sampling begins. By implementing a filter with a specified cutoff that is somewhat lower than the Nyquist frequency, we can prevent aliasing and construct almost the same inputted signal. For this assignment, we are provided with a 1 Hz square wave and are asked to sample the square wave at 50 Hz. The objective is to design an anti-aliasing filter that can reject frequencies above 25 Hz (In this case, the Nyquist frequency). Using MATLAB and knowledge of various filters, we can design filters that can function as our anti-aliasing filter. We can demonstrate what happens before and after sampling the square wave, and plot the resulting signals and Fourier Transforms for further analysis into the frequency and time domain. II. PROCEDURE AND RESULTS (PART 1) We begin the experiment by analyzing the square wave given to us and its respective Fourier Transform:
1 Hz Square Wave 1 0.5 x(t) 0 -0.5 -1 0 1 2 5 6 7 8 time (sec) Fourier Transform of Square Wave Signal 3 4 9 10

2 frequency. The following figure shows the results when the square wave is sampled at 50 Hz without an ant-aliasing filter:
Sampling at 50 Hz 2 Original Discrete-time Resampled 1 CT and DT signals

-1

-2

0.25

0.5

0.75

1 time (s)

1.25

1.5

1.75

Figure 4 Square Wave Sample at 50 Hz with the Original Signal in Blue and the Resulting output as Black. See legend for more details We can observe that the resulting output almost resembles the same as the original square wave with 50 samples per second. The reason as to why we sampled the square wave without an anti-aliasing filter is that a 1 Hz square wave barely has any energy remaining at high frequency harmonics. Since the Nyquist frequency when sampled at 50 Hz is 25 Hz, the Fourier Transform shown in Figure 3 shows that there is a minimal amount of energy left at harmonic frequencies above 25 Hz. Therefore, there will be a minimal amount of aliasing in the reconstructed signal. From Figure 4, our intuition matches the results as expected, with the black denoted signal representing the output when the square wave is sampled at 50Hz. We then decided to design a filter that can reject frequencies above the Nyquist frequency, which in our case is 25 Hz. From previous Homework Assignments, we were exposed to a variety of filtering techniques in solving numerous problems that involved filter design. In this situation, we can simply design a Low Pass Filter since its design implementation results in rejecting frequencies above the specified cutoff and retaining frequencies below it. A simple Low Pass Filter would be an ideal filter to implement in this case because of its roll-off characteristics. To see which type of Low Pass Filter would be sufficient to design in rejecting the aliasing frequencies, we designed a test-bench of the following filter types: Butterworth, Chebyshev, and Elliptical. All 3 filters mentioned are capable of handling the task of eliminating the frequencies above 25 Hz. The testbench of each filter mentioned is shown on the following page with the specified cutoff frequency:

0.4 0.3 |X(w)| 0.2 0.1 0

10

15

20 25 30 frequency (Hz)

35

40

45

50

Figure 3 Given Square Wave shown with its respective Fourier Transform

We can observe that the Fourier Transform of the given 1 Hz square wave is showing energies at all the odd harmonics. In order to sample the signal at 50 Hz, we have to band-limit the given square wave at a value where it is near the Nyquist

ECE 3512 Spring 2011 (Assignment #5)


Test Bench of each Filter and their Response 1 0.9 0.8 0.7 0.6 |X(w)| 0.5 0.4 0.3 0.2 0.1 0
X: 20 Y: 0.707

X(w) Butterworth Chebyshev Elliptical

Transfer functions:
= )( + 406.7 + 82,680 3.13 10 + 1 10 + 8.1 10 + 3.13 10

(4)

= )(

1.963 10 + 72.19 + 2.2 10 + 1.1 10 + 1.02 10 + 2 10 5.12 + 1.81 10 + 3.1 10 + 5.3 10 + 4.35 10 + 71.3 + 26,000 + 1.3 10 + 1.6 10 + 4.35 10

(5) )

= )(

(6)

Equation 4 Transfer Function of 5th order Butterworth Filter Equation 5 Transfer Function of 5th order Chebyshev Filter Equation 6 Transfer Function of 5th order Elliptical Filter
0 5 10 15 20 25 30 frequency (Hz) 35 40 45 50

Figure 5 Filter Response for each designed filter with Legend describing which filter response associated with which color. More specifically: 5th order Butterworth with a cutoff at 20 Hz 5th order Chebyshev with a cutoff at 20 Hz 5th order Elliptical with a cutoff at 20 Hz

Their respective bode plots along with pole-zero maps are shown below for further analysis:
Bode Diagram of all Three Filters 50 0 Magnitude (dB) -50 -100 -150 -200 -250 0 -90 Phase (deg) -180 -270 -360 -450 10
0

Butter Cheby Ellip

We can see from Figure 5 the resulting effects the designed filters would have in eliminating the aliasing frequencies. The cutoff frequency for each filter is mentioned in the Figure description, which we can confirm by observing the 0.707 intersecting point. The filters designed are all eliminating all frequencies 25 Hz are higher, which is our goal since it is band limiting the frequencies that cause aliasing in the resulting signal. It is also important to note the transfer function of each filter since it will describe the order of each filter and its specified cutoff. To show the order of each filter used to show Figure 2, we present the MATLAB Code used to compute the filter response: [numb,denb] = butter(5,2*pi*20,'s'); [numc,denc] = cheby1(5,3,2*pi*20,'s'); [nume,dene] = ellip(5,3,40,2*pi*20,'s');

10

10 Frequency (Hz)

10

Butterw orth PZ Plot Imaginary Ax is Imaginary Ax is 100 0 -100 -150 -100 -50 0 100 0 -100 -30

Chebyshev PZ Plot 200 Imaginary Ax is

Elliptical PZ Plot

-200 -40 -20 Real Axis 0

-20

-10

The reason as to why our filters are designed as 5th order and not higher is because the assignment has a restricted limit on the number of poles the filters can have, which is 5 total. The Butterworth filter has a order of 5 with a cutoff at 20 Hz. The Chebyshev Type 1 Filter has an order of 5 as well with a passband ripple of 3dB at a cutoff frequency of 20 Hz. Finally, the Elliptical filter has an order of 5 with a passband ripple of 3dB with a stopband gain at 40dB with the same cutoff at 20 Hz.. The subscript s is simply used to design an analog filter in MATLAB. Using the tf command, the transfer functions of each filter are shown on the right:

Real Axis

Real Axis

Figure 6 Bode Diagrams of Specified Filters along with Pole Zero Maps showing the location of the poles and zeroes of the filters transfer function From the Bode Diagram, we can see that both the Butterworth and the Chebyshev filters respond better in eliminating the desired frequencies (25 Hz is the Nyquist frequency), with the Elliptical Filter giving the steepest roll-

ECE 3512 Spring 2011 (Assignment #5) off (pole locations result in this behavior) but with some frequencies not rejected due to the stop-band and pass-bands specified. Using the intuition learned so far, we display the filtered square waves with the original sampling rate at 50:
Results after Implementing Butterworth Filter 2 Filtered discrete-time 1 CT and DT signals

The resulting filtered square waves are shown with each filtered signal giving a different result in comparison to the other. The results of the resampled signals are shown below:
Resampled Signal from Butterworth Filter 2 Resampled

Discrete Signal
0 0.25 0.5 0.75 1 time (s) 1.25 1.5 1.75 2

-1

-1

-2

-2

0.25

0.5

Results after Implementing Chebyshev Filter 2 Filtered discrete-time 1 CT and DT signals

1 1.25 1.5 time (s) Resampled Signal for Chebyshev Filter

0.75

1.75

2 Resampled

Discrete Signal
0 0.25 0.5 0.75 1 time (s) 1.25 1.5 1.75 2

-1

-1

-2

-2

0.25

0.5

0.75

1 time (s)

1.25

1.5

1.75

Results after Implementing Elliptical Filter 2 Filtered discrete-time 1 CT and DT signals


Discrete Signal 1 2

Resampled Signal for Elliptical Filter Resampled

-1

-1

-2

-2

0.25

0.5

0.75

1 time (s)

1.25

1.5

1.75

0.25

0.5

0.75

1 time (s)

1.25

1.5

1.75

Figure 7 Sampled Filtered Square Wave at n=50

Figure 8 Resampled Signal from Results shown in Figure 7

ECE 3512 Spring 2011 (Assignment #5) are shown on the right: Bode Diagram of 4th Order Low Pass Filter From Figure 8, we can observe that there is minimal amount of aliasing in the Resampled signal. Since we implemented anti-aliasing filters to reduce the amount of aliasing in the continuous signal, the results in Figure 8 should look almost exactly the same as in Figure 7. We can observe that the results follow this intuition, with almost no aliasing in the signal at all. The following Figure shows the resulting Fourier Transforms of the 1 Hz Square wave when our three designed anti-aliasing filters are applied:
Resulting FFT using Butterworth Filter 0.4 |X(w)| 0.2 0 0 5 10 20 25 30 35 frequency (Hz) Resulting FFT using Chebyshev Filter 15 40 45 50
0 Magnitude (dB) System: s_total Frequency (Hz): 8.65 Magnitude (dB): -3.01

-50

-100

0 -90 -180 -270 -360 10


0

Phase (deg)

10

10 Frequency (Hz)

10

0.4 |X(w)| 0.2 0 0 5 10 20 25 30 35 frequency (Hz) Resulting FFT using Elliptical Filter 15 40 45 50

= )(

1 (7) 4.01 10 + 2.02 10 + 0.00038 + 0.03 + 1

Figure 10 Bode Plot and Transfer Function of our 4th order Low Pass Filter with the final cutoff at 8.65 Hz

0.4 |X(w)| 0.2 0 0 5 10 15 20 25 30 frequency (Hz) 35 40 45 50

Figure 9 Resulting FFT when Filters are applied As expected, we can observe that all three filters designed were successful in eliminating the aliasing frequencies, where frequency values from 20 Hz and forward were removed. Therefore, the results of the resampled signal we received in Figures 7 and 8 are attributed to the sampling rate and the anti-aliasing filters designed. The results could have been more precise if we were allowed to implement filters higher than just 5 poles, as we could have been able to specifically target 25 Hz more accurately. Using the intuition learned so far, we decided to implement one final filter and see if we can receive a better result than the previous filters designed. In Homework #4, we designed a Low Pass Filter to see if the results vary in contrast to a Butterworth or Chebyshev filter in removing the white noise from the signal. We can employ that same intuiton here, since any type of Low Pass Filter can be designed to help solve the problem. Designing various filters provides us useful intuition in how to solve a problem and how their design characteristics affect the resulting output. By designing a simple Low Pass Filter, we can compare the resulting signal and see which one provides the best result. As we did previously, we need to set the cutoff frequency before the Nyquist frequency to eliminate the frequency values that cause aliasing. Using trial and error, we observed that a 4th order Low Pass Filter produced the best result. The Bode Plot and transfer function

The initial cutoff frequency we had specified for our Low Pass filter was 20 Hz. However, every time the order of a Low Pass Filter is increased, the cutoff frequency decreases. Since we have designed a 4th order Low Pass Filter, we can observe that the cutoff frequency has decreased from the initial 20 Hz down to a final cutoff at 8.65 Hz. Taking this intuition into account, the following Figure below shows the filtered Square Wave with the original sampling rate at 50 Hz:
Anti-Aliased Square Wave using Low Pass Filter 2 Filtered discrete-time 1

Filtered Continuous Signal

-1

-2

0.25

0.5

0.75

1 time (s)

1.25

1.5

1.75

Figure 11 Sampled Filtered Square Wave after Low Pass Anti-Aliasing Filter was Applied We can observe that the Low Pass filter gives the best result in comparison to the Butterworth, Chebyshev, and Elliptical filters we has designed previously. The resulting signal

ECE 3512 Spring 2011 (Assignment #5) resembles a square wave with minor distortion on the edges. Since the frequencies that cause aliasing are now removed from the Square Wave, the Resampled signal should look exactly like the Filtered Square Wave. Results are shown below with the Before/After Fourier Transforms to validate if our filter eliminated the intended frequencies:
Resampled Signal using Low Pass Filter 2 Resampled

1 Discrete Signal

We can observe that our designed Low Pass Filter was Figure 13 in Comparison of Before/After FFT of Square Wave successful eliminating the aliasing frequencies. The challenging aspect of this assignment is designing a filter that can retain as much of the odd harmonics of the square wave as possible while rejecting the frequencies that trigger aliasing. From our results, we have satisfied both criterias and were able to minimize the amount of aliasing in the Resampled Signal. Our intuition is that if more samples are done on a continuous signal, the more accurate the discrete time signal would become. Conversely, the lower the sampling rate, the less accurate the resulting signal in the discrete time domain. We decided to test out this intuition further: sampling both lower and higher than 50Hz. III. PROCEDURE AND RESULTS (PART 2) We decided to further explore the theoretical applications of the Nyquist theorem by sampling at a lower rate than 50 Hz. By decreasing the number of samples, the more aliasing will be triggered in the Resampled signal. To demonstrate this concept, we have decided to sample the square wave at 20 Hz. The resulting Figure below is before an Anti-aliasing filter is applied:
Sampling at 20 Hz 2 Original Discrete-time Resampled 1

-1

-2

0.25

0.5

0.75

1 time (s)

1.25

1.5

1.75

Figure 12 Resampled Signal at 50 Hz after implementing our Low Pass Filter

As expected, we can observe that the Resampled Signal matches the filtered Square Wave shown in Figure 11. As we stated earlier, the frequencies that trigger aliasing were eliminated from the Square Wave, thus minimizing the amount of aliasing in the Resampled signal. It is important to note that aliasing cannot be completely removed from a discrete signal. Implementing an analog filter to reduce aliasing is the best option to produce accurate results and to keep the harmonics of the continuous signal intact as much as possible. The resulting Fourier Transforms are shown below for further analysis:
FFT of Original Square Wave 0.4 0.3 |X(w)| 0.2 0.1 0

CT and DT signals

-1

-2

0.25

0.5

0.75

1 time (s)

1.25

1.5

1.75

Figure 14 1 Hz Square Wave sampled at 20 Hz with Resampled Signal in Black and Original Square Wave in Blue The Resampled Signal in Figure 14 shows that there is a considerable amount of aliasing being triggered due to the lower sampling rate at 20 samples per second. The resulting discrete signal has lost its square structure, showing a sinusoidal cosine wave where a straight line of a square should be. As we did in Part 1, we need to design an Anti-Aliasing Filter to remove the frequencies that trigger the aliasing. The first step in designing our filter is to observe what the Nyquist frequency is when sampling at 20 Hz. Using Equation 2 on page 1, the Nyquist frequency is 10 Hz, so we need to design a filter whose output should eliminate frequency values 10 Hz and forward. Our proposed filter in handling this task is shown on the following page along with its bode plot and transfer

10

20 25 30 35 frequency (Hz) Resulting FFT after Low Pass Filter

15

40

45

50

0.4 0.3 |X(w)| 0.2 0.1 0

10

15

20 25 30 frequency (Hz)

35

40

45

50

ECE 3512 Spring 2011 (Assignment #5) function. Filter response is shown on Page 7:
4th order Butterworth Filter Response 1 0.9 0.8 0.7 0.6 |X(w)|
0
X: 5 Y: 0.707

7 above 10 Hz, crucial harmonics that generate the square structure have been eliminated, thus resulting a signal that has round edges as opposed to straight pointy edges. Using the intuition we learned from Part 1, the resampled signal should almost resemble the filtered Square Wave since the aliasing factors have been eliminated. The Bode Plot of our filter is shown below, along with the Resampled Signal:
Bode Diagram of 4th order Butterw orth Filter

X(w) Butterworth

0.5
Magnitude (dB) Phase (deg)

0.4 0.3 0.2 0.1 0

-50

-100

-150 0

10

15

20 25 30 frequency (Hz)

35

40

45

50

-90 -180 -270 -360

Figure 15 Filter Response of 4th order Butterworth Filter with a Specified Cutoff at 5 Hz The filter we designed in properly eliminating the aliasing frequencies is a 4th order Butterworth Filter. The filter response is shown above, where we can observe the cutoff frequency of our filter to be at 5 Hz and that frequency values above 10 Hz are being rejected. This verifies that the filter designed is capable of being implemented as our AntiAliasing filter. The filtered Square Wave is shown below with a sampling rate of 20 Hz (20 samples per second):
Results after Implementing Butterworth Filter 2 Filtered discrete-time 1

10

-1

10

10 Frequency (Hz)

10

Resampled Square Wave at 20 Hz 2 Resampled

1 Discrete Signal

Continuous Filtered Signal

-1

-2

0.25

0.5

0.75

1 time (s)

1.25

1.5

1.75

-1

Figure 17 Bode Plot of 4th order Butterworth Filter (Top) Resampled Square Wave with Sampling rate at 20 Hz (Bottom)

-2

0.25

0.5

0.75

1 time (s)

1.25

1.5

1.75

Figure 16 Filtered Square Wave after Implementing Butterworth Filter with Sampling rate at 20 Hz Figure 16 shows the resulting Square Wave after our Butterworth Filter is applied. We can observe that the resulting signal resembles a square wave, but not quite an actual square wave. Since our filter rejected frequencies

As expected, Figure 17 looks extremely similar to Figure 16 (minor aliasing can be observed) since the aliasing frequencies have been eliminated. This validates the intuition we stated earlier about how the number of samples on a continuous signal results in the accuracy of the discrete signal. Lowering the sampling rate will result in a less accurate signal as opposed to a higher sampled signal resulting in a more accurate signal. To conclude this concept, we decided to increase the sampling rate from 20 Hz to an enormous 20,000 Hz. Results of this procedure can be found on the next page.

ECE 3512 Spring 2011 (Assignment #5) IV. PROCEDURE AND RESULTS (PART 3) To finalize this Assignment and to further validate the intuition learned thus far about the concept of Discrete sampling, we decided to implement one final test and observe whether it holds true to our assumption. If we were to increase the number of samples, the resulting Discrete Signal would be more accurate in comparison to its Continuous counter-part. To demonstrate this concept, we decided to increase the sampling rate from the original 50 Hz to 20,000 Hz. That means the Nyquist frequency will be 10,000 Hz. Frequencies above 10kHz would trigger aliasing. However, we expect that an Anti-Aliasing Filter might not be needed in this situation. The reason is because of the characteristics of a Square Wave and the number of data points being acquired from the Continuous signal. If we sampled the 1 Hz Square Wave at 20kHz, that is the equivalent of 20,000 samples per second. With so much data points being collected from one second, there would be minimal amount of aliasing in the signal. We know that the Fourier Transform of a Square wave has diminishing harmonics at high frequencies. If we observed the energies of the odd harmonics at 10,000 Hz, there should not be much energy left, if any. The Fourier Transform of the 1 Hz Square Wave is shown below zoomed in around 10kHz to further verify our methodology:
x 10 10 9 8 7 |X(w)| 6 5 4 3 2 1 0 0.997 0.998 0.999 1 1.001 frequency (Hz) 1.002 1.003 1.004 x 10
4 -5

8
Sampling at 20 kHz 2 Original Discrete-time Resampled 1 CT and DT signals

-1

-2

0.25

0.5

0.75

1 time (s)

1.25

1.5

1.75

Figure 19 Original v. Resampled Square wave at a Sampling Interval at 20,000 Hz We can see from Figure 19 that our perception was correct and that there is almost no aliasing occurring at all. We can observe that the black colored signal (Resampled) is completely overlapping the Original Square Wave (Blue Color, but cannot be seen). If we wanted to make the Discrete Signal perfect, we could have designed a filter to reject frequencies 10 kHz and forward but we feel that is unnecessary in this situation. This validates our intuition about the concept of sampling and how the number of samples on a continuous signal affects the resulting discrete signal. However, not all signals will follow this trait as EEG and 3G Data Signals would always need an anti-aliasing filter before the continuous signal is sampled properly. In this situation, the characteristics of a Square Wave decided the overall outcome if an Anti-Aliasing filter was to be applied at a high sample rate. It is also important to note that a sampling rate of 1,000 Hz might have given us the same results as sampling at 20 kHz. In a practical setting, 20 kHz would be an unnecessary amount of information if 1000 samples per second could have sufficed. V. DISCUSSION After completing this Assignment, we gained valuable experience in Sampling and the necessary steps to avoid Aliasing. We learned how the number of samples determines the resulting Discrete Signal and how Anti-Aliasing filters are applied to limit the amount of aliasing from a Continuous signal. We understood the concept of the Nyquist Criterion and how important it is to acknowledge this theorem when sampling a continuous signal. This assignment challenged us in designing filters with only 5 poles, a significant trade-off since higher order filters could have resulted in better results. We implemented various filters in eliminating the aliasing frequencies, further enhancing our knowledge of both sampling a signal and of filtering techniques.

FFT of Original Square Wave

Figure 18 Zoomed in view of Fourier Transform of Original Square Wave. X-axis is in 10 and Y-axis is in 10 As we assumed, the energy levels of the harmonics at 10 kHz are barely minimal, with energy levels seen at 0.00006. With such low energy levels, the Resampled Signal should show bare amounts of aliasing. Our hypothesis is the following: since the harmonic energies remaining at 10,000 Hz is extremely low, the aliasing factor can be ignored, which means an Anti-aliasing filter does not need to be applied. The following Figure shows the results of this procedure:

Вам также может понравиться