Roll Number:
Lab Session – 01
Name:
Digital Signal Processing
Effects of Sampling and Aliasing in Discrete Time Sinusoids PRE LAB OBJECTIVE:
The purpose of this lab is to study the relationship between discrete-time and continuous-time signals by examining sampling and aliasing. Computers equipped with sound cards can be used to explore some aspects of sampling and aliasing. In this lab, we will also generate signals and explore their effect as they are sampled and played back at various frequencies.
INTRODUCTION: Signals are physical quantities that carry information in their patterns of variation. Continuous-time signals are continuous functions of time, while discrete-time signals are sequences of numbers. If the values of a sequence are chosen from a finite set of numbers, the sequence is known as a digital signal. Continuous-time, continuousamplitude signals are also known as analog signals. Signal processing is concerned with the acquisition, representation, manipulation, transformation, and extraction of information from signals. In analog signal processing these operations are implemented using analog electronic circuits. Digital signal processing involves the conversion of analog signals into digital, processing the obtained sequence of finite precision numbers using a digital signal processor or general purpose computer, and, if necessary, converting the resulting sequence back into analog form. When stored in a digital computer, the numbers are held in memory locations, so they would be indexed by memory address. In order to bridge the gap between analog and digital domain, we have to perform two basic operations Sampling and Quantization (collectively known as Analog to Digital Conversion [ADC]). Sampling: is the process of acquiring data at discrete (finite) instants of time Sampling Theorem: A continuous time signal x(t) can be reconstructed exactly from its samples x(n)=x(nTs), if the samples are taken at a rate Fs=1/Ts that is greater than 2*Fmax. Aliasing: A common problem that arises when sampling a continuous signal is aliasing, where a sampled signal has replications of its sinusoidal components which can interfere with other components. It is an effect that causes two discrete time signals to become indistinct due to improper sampling (fd>1/2 cycles/sample). Aliasing also occurs on television whenever we see a car whose tires appear to be spinning in the wrong direction. A television broadcast can be thought of as a series of images, sampled at a regular rate, appearing on screen. If the wheels happen to rotate less than a full circle between frames (images), then they appear to be turning slowly in the opposite direction.
In this laboratory we will view a video of a wheel spinning and see several things that we know cannot be true. Parts of the wheel will appear to be still while other parts of the wheel are moving. Different parts of the wheel will appear to be rotating in opposite directions at the same time. These effects, which are called aliasing, occur because the sequence of still frames that make the movie are taken at a rate that is too slow relative to the rotating wheel.
Page 1 of 5
Roll Number:
Lab Session – 01
Name:
Digital Signal Processing
IN LAB 1. Simulate and plot two CT signals of 10 Hz and 110 Hz for 0 < t < 0.2 sec. 2. Sample at Fs = 100 Hz and plot them in discrete form. 3. Observe and note the aliasing effects. 4. Explore and learn.
PROCEDURE: 1. Make a folder at desktop and name it as your current directory within MATLAB. 2. Open M-file editor and type the following code: % Plotting the two CTCV sinusoids clear all; close all; clc; F1 = 10; F2 = 110; Fs = 100; Ts = 1/Fs; t = [0 : 0.0005 : 0.2]; x1t = cos (2 * pi * F1 * t); x2t = cos (2 * pi * F2 * t); figure; plot(t,x1t,t,x2t, 'LineWidth',2); xlabel('cont time (sec)'); ylabel('Amp'); xlim([0 0.1]); grid on; legend('10Hz','110Hz'); title('Two CTCV sinusoids Plotted');
3. Save the file as P011.m in your current directory and ‘run’ it, using F5 key. 4. Check for the correctness of the time periods of both sinusoids. 5. Now add the following bit of code at the bottom of your P011.m file and save. % Sampling the two CTCV sinusoids nTs = [0 : Ts :0.2]; n=[0: length(nTs)-1]; x1n = cos( 2 * pi * F1 * nTs); x2n = cos( 2 * pi * F2 * nTs); figure; subplot( 2 , 1 , 1 ); stem(nTs , x1n ,'filled', 'LineWidth' , 2); grid on; title('10Hz sampled'); xlabel('discrete time (sec)');
Page 2 of 5
Roll Number:
Lab Session – 01
Name:
Digital Signal Processing
ylabel('Amp'); xlim([0 0.1]); subplot( 2 , 1 , 2 ); stem(nTs , x2n , 'filled','LineWidth' , 2 ); grid on; title('110Hz sampled'); xlabel('discrete time (sec)'); ylabel('Amp'); xlim([0 0.1]);
6. Before hitting the ‘run’, just try to understand what the code is doing and try to link it with what we are going to study in classes regarding concepts of frequency for DT signals. 7. Now ‘run’ the file and observe both plots. 8. To see what is really happening, type the following code at the bottom of your existing P011.m file and run again. % Plotting the sinusoids along with sampled versions figure; plot(t,x1t,t,x2t); hold; grid on; stem(nTs,x1n,'r','filled','LineWidth',2); xlabel('time(sec)'); ylabel('Amp'); xlim([0 0.1]); legend('10Hz','110Hz');
9. Observe the plots. 10. Now, Explain (write) in your own words the cause and effects of what you just saw
Page 3 of 5
Roll Number:
Lab Session – 01
Name:
Digital Signal Processing
POST LAB EXERCISE/TASK: These tasks needs to be completed before your next practical and saved. Task-1: The following figure shows a periodic signal in the top plot, composed of three sinusoids. The other two plots show it after it has been filtered through a high-pass filter and a low-pass filter. Which filter (A or B) is the high- pass one and which is the low-pass one?
Task-2 Suppose the signal x(t) = 5 cos(2π5t) + 2 cos(2π50t), sampled with Fs= 1000 samples per second, as shown in Figure (a), is corrupted by a small amount of noise, forming the signal shown in Figure (b). i) Write a MATLAB code to plot these figures ii) Try to remove this random noise by applying some signal processing technique. Hint: MATLAB commands; randn() and filter()
Page 4 of 5
Roll Number:
Lab Session – 01
Name:
Digital Signal Processing
Task-3: Sampling and Aliasing in Sinusoids Consider the following CT signal: = sin2 pi F0 t. The sampled version will be: x(n) =sin (2 pi F0/Fs n), where n is a set of integers and sampling interval Ts=1/Fs. Plot the signal x(n) for n = 0 to 99 for Fs = 5 kHz and F1 = 0.5, 2, 3 and 4.5 kHz. Explain the similarities and differences among various plots. Also mention that whether aliasing occurs or not. Task-4 Consider the given CT signal: = cos2 pi F0 t. Suppose that F0 = 2 kHz and Fs = 50 kHz. i) Plot the signal x(n). What will be the discrete frequency fd of the signal x(n) ? ii) Plot the signal y(n) created by taking the even numbered samples of x(n). Is this a sinusoidal signal? Why? If so, what is the frequency?
Task-5: Sampling and Aliasing in Audio signals Generate a tone in MATLAB and listen to it with the sound command. The frequency of tone should be 1kHz at a sampling rate of 8kHz (oversampled; fd<1/2), and the duration should be 3 sec. Now observe the effect of critical Nyquist by changing the tone frequency to 4 kHz and make notes of your observation. Also explore the effects of aliasing at different tone frequencies by violating Nyquist criterion. You have to mention and discuss at least three aliased frequencies (which you observed) in your lab report. Task-6 Compute a vector x1 of samples of a sinusoidal signal with A = 100, ωo = 2π(1100) and φ = 0. Use a sampling rate of 8000 samples/sec, and compute a total number of samples equivalent to 2 seconds duration. Using sound(), play the resulting vector. Listen to the output. Now compute a vector x2 of samples (again with duration 2 secs) of the sinusoidal signal for the case A = 100, ωo = 2π (1650) and θ = π/3. Listen to the signal reconstructed from these samples. How does it compare to the signal x1. Put both signals together in a new vector defined with the following MATLAB statement (assuming that both x1 and x2 are row vectors): xx = [x1 zeros(1,24000) x2]. Listen to this signal. Explain what you heard. Task-7 Using Simulink record your voice (same utterance of speech) through microphone at different sampling rates (1000, 2000, 8000, 16000 and 44100Hz) and generate .wav files. Listen to these recorded signals and comment on the significance of sampling theorem by observing the quality of sound. Also mention size of generated files in each case and comment on the observed results.
Page 5 of 5