Experiment No.
Understand the behavior of Sampling and Aliasing Theorems
(Rubrics)
Name: Roll No. :
A. PSYCHOMOTOR
Sr. Criteria Allocated Unacceptable Poor Fair Good Excellent Total
No. Marks Obtained
0% 25% 50% 75% 100%
1 Program 2 0 0.5 1 1.5 2
Coding Skills
2 Software Use 2 0 0.5 1 1.5 2
3 Accuracy in 2 0 0.5 1 1.5 2
Output(s)
Sub Total 6 Sub Total marks Obtained in Psychomotor(P)
B. AFFECTIVE
Sr. Criteria Allocated Unacceptable Poor Fair Good Excellent Total
No. Marks Obtained
0% 25% 50% 75% 100%
1 Respond to 2 0 0.5 1 1.5 2
Questions
2 Lab Report 2 0 0.5 1 1.5 2
Sub Total 4 Sub Total marks Obtained in Affective (A)
Instructor Name: Total Marks (P+A):
Instructor Signature: Obtained Marks (P+A):
Biomedical Signal Processing Lab 4
EXPERIMENT NAME:
Understanding the behavior of Sampling and Aliasing Theorems
APPARATUS / COMPONENTS REQUIRED:
1. Operating System- Windows 7
2. Software – MATLAB
THEORY DESCRIPTION:
Periodic Signals:
A sequence X [n] is said to be periodic when it satisfies the following relation
X [n] = X [n + N ]
The fundamental period of the signal is defined as the smallest positive value of N for which
above equation holds true.
Now consider a signal Y[n] which is formed by the addition of the two signals X 1[n] and
X 2 [n].
Y[n] = X 1[n] + X 2[n]
If the signal X 1[n] is periodic with the fundamental period N1 and X 2 [n] is periodic with the
fundamental period N 2 , then the signal Y[n] will be periodic with the period N given by the
following relation:
N1 N 2
N=
GCD(N1 , N 2 )
Sampling Theorem:
“A continuous time signal X [t] with frequencies no higher than Fmax can be reconstructed
1
exactly from its samples X [n] = X (nT s ) , if the samples are taken at a rate F s = that is
Ts
greater than 2Fmax”
The minimum sampling rate of 2Fmax is called the Nyquist Rate. From Sampling theorem it
follows that the reconstruction of a signal is possible if we have at least 2 samples per period.
If we do not sample at a rate that satisfies the sampling theorem then aliasing occurs.
25
Biomedical Signal Processing Lab 4
Sampling a Continuous Time Signal:
For example we want to sample continuous time signal X (t) = Cos(100t) . The frequency of
this signal is 50 Hz and according to sampling theorem the minimum sampling frequency
should be 100 samples/sec. But we sample it at a rate much higher than the Nyquist rate so
that it has many samples over one cycle giving an accurate representation of the sampled
discrete time signal.
In the figure below the continuous time signal X (t) = Cos(100t) is sampled at Fs=1000
F 1000
samples/second).Therefore it will have s = = 20 samples per cycle.
f 50
-0
0 5 10 15 20 25 30 35
x=c os(100*pi*t) sampled with Fs=1000 (samples / sec )
Concept of Aliasing:
T=0.03;
N=1024;
fs=1000;
n=[0:1/fs:T];
F=[-N/2+1:N/2]*fs/N;
f=125; x1=cos(2*pi*f*n);
X1=abs(fftshift(fft(x1,N)));
f=500;
x2=cos(2*pi*f*n);
X2=abs(fftshift(fft(x2,N)));
f=625; x3=cos(2*pi*f*n);
X3=abs(fftshift(fft(x3,N)));
f=875;
x4=cos(2*pi*f*n);
X4=abs(fftshift(fft(x4,N)));
26
Biomedical Signal Processing Lab 4
subplot(421);stem(n,x1);grid on;title('sinusoidal signal of f=125 Hz');
subplot(422);plot(F,X1);grid on;title('fft of sinusoidal signal of f=125
Hz');
subplot(423);stem(n,x2);grid on;title('sinusoidal signal of f=500 Hz');
subplot(424);plot(F,X2);grid on;title('fft of sinusoidal signal of f=500
Hz');
subplot(425);stem(n,x3);grid on;title('sinusoidal signal of f=625 Hz');
subplot(426);plot(F,X3);grid on;title('fft of sinusoidal signal of f=625
Hz');
subplot(427);stem(n,x4);grid on;title('sinusoidal signal of f=825 Hz');
subplot(428);plot(F,X4);grid on;title('fft of sinusoidal signal of f=825
Hz');
27
Biomedical Signal Processing Lab 4
Handling Media Files:
wavread reads Microsoft WAVE (".wav") sound file.
Y=wavread(FILE) reads a WAVE file specified by the string FILE, returning the sampled
data in Y. The ".wav" extension is appended if no extension is given. Amplitude values are in
the range [-1,+1].
[Y,FS,NBITS]=wavread(FILE) returns the sample rate (FS) in Hertz and the number of bits
per sample (NBITS) used to encode the in the file.
wavplay plays sound using Windows audio output device.
wavplay(Y,FS) sends the signal in vector Y with sample frequency of FS Hertz to the
Windows WAVE audio device. Standard audio are 8000, 11025, 22050, and 44100 Hz.
wavplay(Y) automatically sets the sample rate to 11025 Hz. For stereo playback, Y should
be an N-by-2 matrix.
Following is a sample program that will enable us to understand the concept of sampling and
aliasing.
close all
clear all
clc
[x,fs,nbits]=wavread('chimes.wav');
ts=1/fs;
N=length(x);
t=[0:N-1]*ts;
s=2*cos(2*pi*50*t);
xs=x+s';
load filter.mat
y=filter(Num,Den,xs);
wavplay(x,fs)
wavplay(xs,fs)
wavplay(y,fs)
[x,fs,nbits]=wavread('chimes.wav');
ts=1/fs;
N=length(x);
t=[0:N-1]*ts;
tind=find(t>=2.4 & t<=3.7);
xpart=x(tind);
tpart=t(tind);
subplot(211),plot(t,x);grid on;title('Time Plot of Chimes.wav');
subplot(212),plot(tpart,xpart,'r');grid on;title('extracted signal');
axis([0 8 -1 1]);
28
Biomedical Signal Processing Lab 4
LAB ASSESSMENT
PROBLEM 1:
Consider a continuous time signal x(t) = ACos(t + ) . We can sample a continuous time
signal at equally spaced time instants T = nTs and get a discrete time signal x[n] = x(nTs) .
The individual values of x[n] are called samples of continuous time signal. The fixed time
interval between samples, Ts, can also be expressed as a fixed sampling rate, Fs, in samples
per second.
1
Fs = ; samples / second
Ts
If we sample x(t) = ACos(t + ) using this approach, then by using t = nTs ; we get
^
x(n) = x(nTs) = ACos(nTs + ) = ACos( n + ) .
^
Here we have defined = Ts = .
Fs
^
The signal x[n] is a discrete time cosine signal, and is its discrete time frequency. We use
hat over to denote that this is a new frequency variable. It is a normalized version of the
continuous time radian frequency with respect to the sampling frequency.
a. Generate and plot the signal x(t) = ACos(t + ) with the following values A=3,
Frequency=100 Hz, t = - 0.01: 0.00001: 0.02 and = 0.
b. Generate and plot the Discrete time signal x[n] from the Continuous time signal x(t)
using values in part (A) .Use the sampling frequency Fs=2000.
c. Repeat part (B) for Fs=500.
NOTE: All the plots should be in the same window (use subplot command for this purpose)
29
Biomedical Signal Processing Lab 4
PROBLEM 2:
Consider the signal
Y[n] = X 1[n] + X 2[n]
Where,
a. Determine the value of N1 and plot the signal X 1[n] over the range n=0:(2*N1).
Verify from graph that there are 2 complete cycles of the signal X 1[n] .
b. Determine the value of N2 and plot the signal X 2 [n] over the range n=0:(2*N2).
Verify from graph that there are 2 complete cycles of the signal X 2 [n].
c. Determine the value of N and plot the signal y over the range n=0:(3*N). Verify
from graph that there are 3 complete cycles of the signal Y[n] .
Examine graphically that X 1[n] repeats itself after N1, X 2 [n] repeats itself after N2 and
Y[n] repeats itself after N samples.
30
Signal Processing Lab 4
CONCLUSION
31