EE 333 Communication and DSP lab
Assignment 1
Matlab Assignments:
1. To demonstrate aliasing: :
(a) Write a program to generate the following signals sampled at frequency F s for 0.5 seconds and
plot the them.
i. x1 (t) = cos(2πf1 t) + cos(2πf2 t) + cos(2πf3 t)
ii. x2 (t) = cos(2πf1 t)
iii. x3 (t) = cos(2πf4 t)
(b) Take the 1024 point FFT of the above signals as X1 [ω], X2 [ω] and X3 [ω] and plot the magnitude
spectrum of these signals.
(c) Calculate the signals yi (t) = x2i (t); i = 1, 2, 3.
(d) Compute the 1024 point FFT of yi (t) as Yi (ω).
(e) Compute (a) using 2F s and perform (b).
Find answers:
- Why signal with different frequency look same after sampling both in time domain and frequency
domain (Ref Fig. 1)?.
- What happened to the signals with different frequencies when the sampling frequency is in-
creased? (Ref Fig. 2). What sampling frequency can be used in order to get the actual
magnitude spectrum of a signal?
- Give three different signals that have the same spectrum as in X1 (ω)|.
- Identify the locations of spikes in magnitude spectrum of x21 (t) and justify them theoretically
(Ref. Fig 3)?
- Explain the effect in frequency spectrum due to squaring in time domain.
See the figures (1,2,3) for sample results with F s = 10000Hz, f1 = 1000Hz, f2 = 1500Hz, f3 =
4000Hz and f4 = 11000Hz. ( x-labels are scaled accordingly to show time in seconds and frequency
in Hz.)
Figure 1: Sample output for Qn. 1(a,b)
Figure 2: Sample output for Qn. 1(e)
Figure 3: Sample output for Qn. 1(b,c,d)
2. To demonstrate Harmonics of periodic waves and effect of N point FFT.
(a) Construct a sine wave x4 (t),square wave x5 (t) and a triangular wave x6 (t) of frequency f5
sampled at F s for 0.5 seconds. Construct another square wave x7 (t) of frequency f6 for 0.5 sec.
(b) Compute the 1024 point FFT of all the above and plot their magnitude spectrum.
(c) Compute 1024 point, 2048 point, 4096 point and 8192 point FFT of x7 (t) and plot the magnitude
spectrum of all 4 of them.
Find answers:
- Why there are four spikes in the magnitude spectrum of a square or triangular wave while only
two spikes for a sine wave with same frequency?
- Why there are many spikes in magnitude spectrum of square wave with 785Hz while there are
only few for square wave with frequency 1000Hz?. How many spikes do you expect for these
two?
- Why does the peak in the magnitude spectrum of square wave with frequency 785 Hz is not
exactly at 785 Hz in Figure (1024 point)? How does it vary for 2048,8192 point FFT?.
- Theoretically calculate the following in th magnitude spectrum of a square wave with frequency
1200 Hz (when the Fs=10000Hz):
- The frequency at which the magnitude attains its peak.
- An upper bound on the gap between the peak frequency and the actual frequency of the
wave when using N − pointF F T where N = 128, 256, 512, 1024.
See sample figures with f5 = 1000Hz, f6 = 785Hz can be seen in Fig. 4,5. ( x-labels are scaled
accordingly to plot frequency in Hz.)
Figure 4: Sample output for Qn. 2(a,b)
Figure 5: Sample output for Qn. 2(c)
3. To demonstrate FIR filtering:
(a) Construct an ideal FIR band pass filter with pass band between f7 Hz to f8 Hz, a length N ,
sampling frequency F s using Hamming window. Plot the magnitude, phase response and the
impulse response of the filter. What is the length of the filter?
(b) Generate signals x8 (t) = sin(2π200t) + sin(2π2000t) + sin(2π4000t) + sin(2π1250t) and pass this
signal to the filter designed above. Plot the input and output signals along with it magnitude
spectrum.
(c) Plot the magnitude response of FIR filter with N = 33,67,235 using rectangular and Hamming
window.
Find answers:
- Why does the output sinusoidal wave starts after a small time delay?. What is this delay?
- What is the relation between the phase response and this delay?. Can you calculate this delay
using the phase response figure obtained?.
- Why does the phase response looks like saw tooth wave while theoretically it should be linear?
- From the magnitude response of the filter, identify the scaling factor on various input frequencies
and verify the validity of the same.
- What is the effect of varying the length of filter?
- Find the difference between the filters using rectangular window and Hamming window.
Sample figures can be seen in Fig 6,7 for f7 = 1750Hz, f8 = 2750Hz, N = 67 ( x-labels are scaled
accordingly to plot time in seconds and frequency in Hz. The x label of FIR impulse response is
samples.)
Figure 6: Sample output for Qn. 3(a)
Figure 7: Sample output for Qn. 3(b)
4. Perform the following for an IIR filter given below:
1 − rz −1
H1 (z) =
1 − 2s cos(θ)z −1 + s2 z −2
(a) Plot the impulse responses of the above filter for the values r = 0, s = 1, 0.99, 1.01. Plot only
the first 100 samples.
(b) Plot the magnitude responses of the above filter for the values r = 0, s = 1, 0.9, 0.8, 0.7, 0.6, 0.5
and s = 0.5, r = 0, 0.4, 0.8, 1, 1/0.8, 1/0.4 (Assume F s = 10000Hz).
Sample figures can be seen in Fig 8,9,10 for θ = π4 − 16
π
. ( x-labels are scaled accordingly to plot
frequency in Hz and time is in samples. Impulse response are calculated only for first 10000 samples
and frequency response as FFT of this impulse response.)
Figure 8: Sample output for Qn. 4(a)
Figure 9: Sample output for Qn. 4(b) (Part 1)
Figure 10: Sample output for Qn. 4(b) (Part 2)
Find answers:
• Find out the poles and zeros of the all the above filters.
• Explain why the sinusoidal wave increases in amplitude when s = 1.01, decreases in amplitude
when s = 0.99 and oscillates at a specific frequency when s = 1. Identify the frequency of
oscillation theoretically.
• Explain what happens when we move the poles of the filter towards origin (See Fig: 9 for
reference).
• Explain the effect of zero in various points mentioned above. Especially, explain why the
magnitude response of the filter when r = 0.4 and r = 1/0.4 looks similar except a scaling
factor. What is this scaling factor. Same goes for r = 0.8 and r = 1/0.8 (See Fig: 10 for
reference).