Using MATLAB to Illustrate the 'Phenomenon of Aliasing' Sol Neeman, Ph.D
Total Page:16
File Type:pdf, Size:1020Kb
Johnson & Wales University ScholarsArchive@JWU Engineering Studies Faculty Publications and College of Engineering & Design Creative Works 1995 Using MATLAB to Illustrate the 'Phenomenon of Aliasing' Sol Neeman, Ph.D. Johnson & Wales University - Providence, [email protected] Follow this and additional works at: https://scholarsarchive.jwu.edu/engineering_fac Part of the Computer Engineering Commons, Electrical and Computer Engineering Commons, Engineering Science and Materials Commons, Mechanical Engineering Commons, Operations Research, Systems Engineering and Industrial Engineering Commons, and the Other Engineering Commons Repository Citation Neeman,, Sol Ph.D., "Using MATLAB to Illustrate the 'Phenomenon of Aliasing'" (1995). Engineering Studies Faculty Publications and Creative Works. 8. https://scholarsarchive.jwu.edu/engineering_fac/8 This Conference Proceeding is brought to you for free and open access by the College of Engineering & Design at ScholarsArchive@JWU. It has been accepted for inclusion in Engineering Studies Faculty Publications and Creative Works by an authorized administrator of ScholarsArchive@JWU. For more information, please contact [email protected]. Session 1620 USING MATLAB TO ILLUSTRATE THE' PHENOMENON OF ALIASING Sol Neeman Johnson and Wales University Abstract n. > 2 · nn The phenomenon of aliasing is important when sam (the frequency 2 . nn is called the Nyquist sampling pling analog signals. In cases where the signal is ban rate) dlimited, one can avoid aliasing by ensuring that the If this condition is not satisfied, aliasing will occur, re sampling rate is higher than the Nyquist rate. But in sulting in distortion in the reconstructed signal from its cases where the signal is not bandlimited, aliasing is un samples. When signals are not bandlimited, anti aliasing avoidable if the signal is not filtered before it is sampled. filters can be used to minimize the effect by attenuating It is then crucial to understand the phenomenon in order the undesired high frequency components. In addition, to estimate the distortion generated when the signal is wideband additive noise may fill in the high frequency reconstructed from its samples. Using the software pack range and then be aliased into the lower frequency range. age MATLAB by MathWorks, Inc., two examples are In order to evaluate quantitatively the distortion in the presented. The first is a pure sinusoid which is sampled reconstructed signal, it is necessary to understand why at both higher and lower than the Nyquist rate, and the the high frequency components are aliased into the lower frequency spectrum of both sampled sinusoids are com range. pared to illustrate the effect of aliasing. The second and more interesting case is a square wave which has an un limited bandwidth. The square wave is a periodic wave Why and how Aliasiug Occurs that has Fourier expansion with odd harmonics only, the amplitudes of which drop as lin. A square wave is To get an insight into this phenomenon, we analyze synthesized using MATLAB and its Fourier transform the Fourier transform of the sampled signal and compare is presented graphically (The synthesized square wave it to the Fourier transform of the analog (continuous) inherently produces aliased components). The odd har signal[lj: monics and the aliased components seen on the graph Let xa(t) represent an analog signal with the highest are analyzed and compared to the predicted theoretical frequency component at nn, and set) represent a peri results. Graphs generated by MATLAB accompany the odic impulse train, with a period T , that is: analysis for both signals. set) = L 8(t - nT) Introduction n where 8(t) is the unit impulse function. If Xa(t) is Physical signals in nature are continuous, both in time sampled at a period T , the sampled signal, xs (t) , can be and in amplitude. On digital computers, they can be represented as the product of the two, that is : represented by finite sequences with finite precision. To do this, the signal has to be sampled and the ampli Xs(t) xa(t) . set) xa(t) . 8(t - nT) tude of the samples be approximated by a finite number = = L n of bits (quantization of the signal). Nyquist theorem states that the analog signal can be reconstructed from Since multiplication in the time domain translates its samples, provided the sampling rate is greater than into convolution in the frequency domain, the relation twice the highest frequency component in the analog ship between the Fourier transforms of the three func signal. Thus if the highest frequency component is nn tions is given by: (called the Nyquist frequency), the sampling frequency, n., has to satisfy: x.un) = 2l7l'XaUn) * Sun) 1995 ASEE Annual Conference Proceedings 612 where n represents analog frequency. The Fourier versions of a group of pure sinusoids[21. Consider the transform of s(t), the periodic impulse train, is a pe continuous sinusoid of frequency Wo : riodic impulse train in the frequency domain, that is: x(t) = sin(wo' t) sun) = :; L 8(n - k ;7r) = :; L 8(n - kn.) When sampled at a sampling period T, the resulting k k sampled sequence is: Carrying out the convolution in the previous equation, results in: x(n) = sin(wo . n· T) for n=0,±1,±2, ... Now consider the group of sinusoids of frequency w, where: This equation states that the Fourier transform of the sampled signal is a superposition of infinitely many shifted copies of Xaun), resulting in repeated copies 27rk for k = 0, ±l, ±2, ... of Xa un) in integer multiples of n., in both direc w=wo+ T tion of the frequency axis. If the sampling rate is not greater than twice the Nyquist frequency, the copies, When sampled at a sampling period T, any sinusoid: when superimposed, will overlap and higher frequ~ncies will be aliased into the lower frequency range; therefore y(t) = sin[(wo + 2;k) . tj we would not be able to reconstruct the original signal from its samples by the use of a filter. On the other from this group, will result in a sequence which is hand if the sampling rate is satisfied, no overlapping of identical to the sampled sequence of frequency woo To the copies will happen and with the appropriate filter see that, we observe: it is possible to reconstruct the original signal from its samples. y(n) = sin[(wo + 2;k) . nT] Fig. 1 represents the Fourier transform of xa(t) and =sin[(wo . nT + 27rkn)] x s (t) and the two cases described above. = sin[wo . nT] ~.\'.( j ll l Thus x(t) and any ofthe sinusoids represented by y(t) , , \I cannot be distinguished when sampled at a sampling -IlN Us period T. Note that Wo is considered in tandem with S(j\1) j ¥t -wo ° t t t ): U - 1· 11., - II., lis :!. · lls Bin# and Actual Frequency No ",Iia.s ill~ : 0 ,,; > 2· fiN Relationship in FFT Computation When a sampled signal, x$(t) is represented by a - fls . sequence x(n), the Fourier transform of the sequence, X(eiw ), is a frequency scaled version of x.(jn) with the scaling w = nT. Thus the analog frequency n = n. (where n .. = 27r/T ), is normalized to w = 27r. The FFT of a sequence of length N, produces N points (re ferred to as bin # 's). In MATLAB, the first N/2 + 1 - Os -fix n,\' Po ... points correspond to the frequency range DC to 1./2 (Nyquist frequency). The rest of the points correspond Fig.1 Fourier Transform of an analog signal, xa(t) to negative frequencies (which will be truncated in . the and its sampled form, x.(t). following examples). Aliasing can also be demonstrated in a simpler way, Thus, to translate the values of the bin #'s to the when we analyze the relationship between the sampled actual frequency f , we use the equation: ~i 1995 ASEE Annual Conference Proceedings 1",IIoO\O'l' 613 • Hz 1, the first frequency vector, runs from DC to 1, OOOH z. f = (bin# -1)· fs/N H z2, the second frequency vector, runs from DC to 500Hz. The next lines are the commands in MA TLAB needed Graphing FFT Values Versus the to produce both sequences, compute their FFT and plot Actual Frequency, in Hz[3,41 the results [31: To graph the FFT values Of a signal versus the actual t1=0:.0005:.5115; frequency in Hz rather than versus the bin #, we have Hz 1=(2000/2)*(0: 1024/2) / (lO24/2); to generate a frequency vector of length N /2 1, evenly + xl=sin(2*pi*550*tl ); spaced, which represents the frequency range: DC to Xl=abs(fft(xl fs/2 . For example, let X(n) represent N points FFT »; Xl(514:1024)=[ ]; with N even and a sampling frequency fs ; In MATLAB, subplot(211) ; we can produce a frequency vector Hz via: plot( tl( 1:64),xl(1 :64)); subplot(212); Hz = Us/2) * (0: N/2)/(N/2); plot(Hz 1 ,Xl); Since X (n) is of length N and we need only the first (Fig. 2 shows MATLAB plots for xl and Xl) N /2 + 1 elements, we have to truncate the portion that corresponds to negative frequencies. This is done via: t2=0:.00l:1.023; Hz2=( 1000/2)*(0: 1024/2) / (lO24/2); X(N/2 +2 : N) = []; x2=sin( 2*pi * 550*t2); X2=abs(fft(x2)); Then we can plot IX (n) I versus Hz. X2(514:1024)=[ ]; subplot(21l); plot( t2(1 :256),x2( 1:256)); Aliasing When Undel'sampling a pure sinusoid subplot(212); plot(Hz2,X2); To illustrate aliasing when a pure sinusoid is undersam (Fig. 3 shows MATLAB plots for x2 and X2) pled, we use MATLAB to synthesize a sinusoid of fre quency 550Hz, then represent it by two sequences: -_.