You are on page 1of 2

EECE359: Matlab Exercise 6

EECE359: Matlab Exercise 6

EECE 359 MATLAB Exercise 6 1 Introduction


This assignment gives Matlab examples for the material covered in Chapter 6 of the Lecture Notes. Commands indicated by the >> should be typed in the Matlab Command Window. This exercise builds on the previous Matlab exercises, so please have a look at them if you have not already done so.

>> [X,f] = ctft(x,T); We can examine the frequency content of the reconstructed signal: >> plot(f,abs(X)); Is X nonzero at the proper frequency values? Now, lets choose a different sampling frequency s = 2(750) rad/sec, resulting in T = 1/750 sec. Lets create the samples and calculate the frequency content of the reconstructed signal: >> >> >> >> >> T=1/750; n=0:749; x=sin(2*pi*1000*n*T); [X,f] = ctft(x,T); plot(f,abs(X));

2 Aliasing due to Undersampling


In this section we will examine the aliasing effect, discussed on pages 200202 of the Lecture Notes. In particular, we will examine the effect of different sampling rates when sampling the following continuous-time signal: x(t) = sin(0 t) with frequency 0 = 2(1000) rad/sec. We wish to examine the frequency content that a reconstructed signal xr (t) would have, if we sampled x(t) with sampling rate s and then used ideal reconstruction to get xr (t). In order to do this, we will need to create a Matlab function we will call ctft (continuous-time Fourier transform). You should create a Matlab M-le (by going under File,New,M-File), enter the following code, function [X,f] = ctft(x,T) N = length(x); X = fftshift(fft(x,N))*(2*pi/N); f = linspace(-1,1-1/N,N)/(2*T); and save it with the lename ctft.m. This function returns values X (samples of the Fourier transform of the continuous-time signal reconstructed from discrete-time samples x) at sample points f. Lets consider a sampled version of x(t) with sampling rate s = 2(8192) rad/sec, resulting in a sample period T = 1/8192 sec. Create a series of samples of the signal >> T=1/8192; >> n=0:8191; >> x=sin(2*pi*1000*n*T); Now we use the function ctft we created to calculate the Fourier transform:

Do you see the expected spectrum? Why, or why not? (Hint: think about what is written on page 200 of the Lecture Notes). What is the Nyquist rate for this example? Try different values around the Nyquist rate for s , and examine the effect on the spectrum of the reconstructed signal.

3 Interpolation and Decimation


In this section we will discuss the topic of interpolation and decimation (see Section 6.5 of the Lecture Notes). In particular, we will study the example from pages 225226 of the Lecture Notes, where both interpolation and decimation are applied to a discrete-time signal. We will study the discrete-time signal x[n] = sinc(0.2(n 62))2 , Lets create this signal: >> n = 0:124; >> x = (sinc(0.2*(n-62))).^2 We can examine the spectrum of this signal: >> X = fft(x); >> f = linspace(0,2*pi,length(X)); >> plot(f,abs(X)) We can see this signal has X(ej ) = 0 for > 2/5. If we decimate this signal by a factor N = 2 (i.e. by taking every second sample): 0n124

EECE359: Matlab Exercise 6

>> >> >> >>

x2 = x(1:2:end); X2 = fft(x2); f2 = linspace(0,2*pi,length(X2)); plot(f2,abs(X2));

we see there is room for further downsampling, since Xb (ej ) = 0 for > 4/5. Following the method of pages 225226 of the Lecture Notes, we see that the desired Nmax = 5/2 is not an integer value. So, we rst have to upsample by a factor of 2, then downsample by a factor of 5. We will use the Matlab function resample to upsample our signal. This function does the two-step process of inserting zeros and lowpass ltering that is required during upsampling. (See the Matlab help for more details.) Lets do this now: >> >> >> >> >> >> xu x3 Xu fu X3 f3 = = = = = = resample(x,2,1); xu(1:5:end); fft(xu); linspace(0,2*pi,length(Xu)); fft(x3); linspace(0,2*pi,length(X3));

Lets look in turn at the spectra of xu and x3. First, we look at the upsampled signal: >> plot(fu,abs(Xu)); and we observe that the upsampled signal has Xu (ej ) = 0 for > /5. Now, lets look at the spectrum of x3: >> plot(f3,abs(X3)); Observe the nal signal fully occupies up to . This means we have done the maximum possible (aliasing-free) downsampling of our signal x[n].

You might also like