Вы находитесь на странице: 1из 8

LAB # 06

SAMPLING
THEORY:
SAMPLING PROCESS:
It is a process by which a continuous time signal is converted into discrete
time signal. X[n] is the discrete time signal obtained by taking samples of the
analog signal x(t) every T seconds, where T is the sampling period. The sampling
frequency or sampling rate, fs, is the average number of samples obtained in one
second (samples per second), thus fs = 1/T.
SAMPLING THEOREM:
A continuous time signal x (t) with frequencies no higher than Fmax can be
reconstructed exactly from its samples x[n] = x (n Ts), if the samples are taken at a
rate Fs = 1 / Ts that is greater than 2Fmax
Fs 2Fmax
The minimum sampling rate of 2Fmax is called the Nyquist Rate .From Sampling
theorem it follows that the reconstruction of a sinusoid is possible if we have at
least 2 samples per period. If we dont sample at a rate that satisfies the sampling
theorem then aliasing occurs.
ALIASING
In signal processing and related disciplines, aliasing is an effect that causes
different signals to become indistinguishable (or aliases of one another)
when sampled. It also refers to the distortion or artifact that results when the signal
reconstructed from samples is different from the original continuous signal.

SAMPLING RATE CONVERSION:


Sampling rate conversion is employed to generate a new sequence with a
sampling rate higher or lower than that of a given sequence. If x[n] is a sequence
with a sampling rate of F Hz and it is used to generate another sequence y[n] with
desired sampling rate F Hz, then the sampling rate alteration is given by,
F/F = R
If R > 1, the process is called interpolation and results in a sequence with
higher sampling rate. If R< 1, the process is called decimation and results in a
sequence with lower sampling rate.
DOWNSAMPLE AND DECIMATION:
Down sampling operation by an integer factor M (M>1) on a sequence x[n]
consists of keeping every Mth sample of x[n] and removing M-1 in between
samples, generating an output sequence y[n] according to the relation
y [n] = x[nM]
y [n] sampling rate is 1/M that of x[n]
If we reduce the sampling rate, the resulting signal will be an aliased version of
x[n]. To avoid aliasing, the bandwidth of x[n] must be reduced to F max=Fx/2 or
max = /M. The input sequence is passed through LPF or an antialiasing filter
before down sampling.
x [n]

ANTIALIASING
FILTER H (Z)

y[n]

UPSAMPLE AND INTERPOLATION:


Upsampling by an integer factor L (L > 1) on a sequence x[n] will insert (L1)
equidistant samples between an output sequence y[n] according to the relation

x[n/L],
y[n] =

0,

n = 0, 1, 2 .
otherwise

The sampling rate of y[n] is L times that of x[n]. The unwanted images in the
spectra of sampled signal must be removed by a LPF called anti-imaging filter.
The input sequence is passed through an anti-imaging filter after up sampling.

x[n]

ANTI IMAGING FILTER H (Z)

y[n]

LIBRARY FUNCTIONS:
resample: Changes sampling rate by any rational factor.
y = resample (x,p,q) resamples the sequence in vector x at p/q times the original
sampling rate, using a polyphase filter implementation. p and q must be positive
integers. The length of y is equal to ceil (length(x)*p/q).
interp:

Increases sampling rate by an integer factor (interpolation)

y = interp (x,r) increases the sampling rate of x by a factor of r. The interpolated


vector y is r times longer than the original input x. interp performs low pass
interpolation by inserting zeros into the original sequence and then applying a
special low pass filter.

upsample: Increases the sampling rate of the input signal


y = upsample(x,n) increases the sampling rate of x by inserting n-1 zeros between
samples. The upsampled y has length(x)*n samples
decimate: Decreases the sampling rate for a sequence (decimation).
y = decimate (x, r) reduces the sample rate of x by a factor r. The decimated vector
y is r times shorter in length than the input vector x. By default, decimate employs
an eighth-order low pass Chebyshev Type I filter. It filters the input sequence in

both the forward and reverse directions to remove all phase distortion, effectively
doubling the filter order.
downsample: Decreases the sampling rate of the input signal
y = downsample(x,n) decreases the sampling rate of x by keeping every n th sample
starting with the first sample. The downsampled y has length(x)/n samples
Verification of Sampling theorem:
clc;
T=0.04; % Time period of 50 Hz signal
t=0:0.0005:0.02;
f = 1/T;
n1=0:40;
size(n1)
xa_t=sin(2*pi*2*t/T);
subplot(2,2,1);
plot(200*t,xa_t);
title( 'Verification of sampling theorem' );
title( 'Continuous signal' );
xlabel( 't' );
ylabel( 'x(t)' );
ts1=0.002; %>niq rate
ts2=0.01; %=niq rate
ts3=0.1; %<niq rate
n=0:20;
x_ts1=2*sin(2*pi*n*ts1/T);
subplot(2,2,2);
stem(n,x_ts1);
title( 'greater than Nq' );
xlabel( 'n' );
ylabel( 'x(n)' );
n=0:4;
x_ts2=2*sin(2*sym( 'pi' )*n*ts2/T);
subplot(2,2,3);
stem(n,x_ts2);
title( 'Equal to Nq' );
xlabel( 'n' );
ylabel( 'x(n)' );
n=0:10;
x_ts3=2*sin(2*pi*n*ts3/T);
subplot(2,2,4);
stem(n,x_ts3);
title( 'less than Nq' );
xlabel( 'n' );

ylabel( 'x(n)' )

Output:

Continuous signal

x(n)

x(t)

0.5

-0.5

-1

greater than Nq

-1

0.5

1.5

2
t

2.5

3.5

-2

Equal to Nq

x 10

-14

10
n

12

14

16

18

20

10

less than Nq

x(n)

x(n)

0
0

-1
-1

-2

-2

0.5

1.5

2
n

2.5

3.5

-3

5
n

TASK:
1. Run code 1 and generate the output waveform
Sinusoidal signal/zohaib/13EE018

-1

Amplitude

-1

-2
-10

-5

5
time

10

15

-2

20

Resampled signal/zohaib/13EE018

-1

10
time

15

-2

20

Downsampled signal/zohaib/13EE018

Interpolated signal/zohaib/13EE018

Amplitude

Amplitude

Decimated signal/zohaib/13EE018

40
time

60

80

Upsampled signal/zohaib/13EE018

20

-1

-1

-2
-3

Amplitude

Amplitude

Amplitude

10

20

time

30

40

50

-2

-1

10
time

15

20

-2

20

40

time

60

80

100

Source code 1:
clc;
clearall;
closeall;
%continuous sinusoidal signal
a=input('Enter the amplitude:');
f=input('Enter the Timeperiod:');
t=-10:1:20;
x=a*sin(2*pi*f*t);
subplot(2,3,1);
plot(t,x);
xlabel('time');
ylabel('Amplitude');
title('Sinusoidal signal/Zohaib/13EE018');
%decimating the signal
d=input('Enter the value by which the signal is to be decimated:');
y1=decimate(x,d);
subplot(2,3,2);
stem(y1);
xlabel('time');
ylabel('Amplitude');
title('Decimated signal/Zohaib/13EE018');
%interpolating the signal
i=input('Enter the value by which the signal is to be interpolated:');
y2=interp(x,i);
subplot(2,3,3);
stem(y2);
xlabel('time');
ylabel('Amplitude');
title('Interpolated signal/Zohaib/13EE018');
%resampling the signal
y3=resample(x,3,2);
subplot(2,3,4);
stem(y3);
xlabel('time');

ylabel('Amplitude');
title('Resampled signal/Zohaib/13EE018');
%downsampling the signal
y4=downsample(x,2);
subplot(2,3,5);
stem(y4);
xlabel('time');
ylabel('Amplitude');
title('Downsampled signal/Zohaib/13EE018');
%upsampling the signal
y5=upsample(x,3);
subplot(2,3,6);
stem(y5);
xlabel('time');
ylabel('Amplitude');
title('Upsampled signal/Zohaib/13EE018'

2. Sample the signal xt = 5*sin (150 t) to get sampled signal xn = 5*sin (150
n Ts) such that there is no aliasing . Choose an appropriate value of
sampling frequency fs and choose tsuch that the graph contains 4 cycles
of the signal and each cycle has 22 samples.Plot both signals xt and xn in the
same window.
clc;
T=0.04;
t=0:0.0005:0.034;
f = 1/T;
n1=0:40;
size(n1)
x_ts=5*sin(150*pi*t/T);
subplot(2,2,1);
plot(200*t,x_ts);
title( 'Continuous signal' );
xlabel( 't' );
ylabel( 'x(t)' );
ts1=0.002;
n=0:39;
x_ts1=5*sin(150*pi*n*ts1/T)
subplot(2,1,2);
stem(n,x_ts1);
title('xn=5*sin(150*pi*n*Ts)ZOHAIB KHAN/ 081');
xlable('n');
ylable('x(n)');

Вам также может понравиться