Академический Документы
Профессиональный Документы
Культура Документы
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.
ANTIALIASING
FILTER H (Z)
y[n]
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]
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:
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)');