Tuesday, January 29, 2019

SAMPLING THEORM WITH MATLAB CODING


DIGITAL SIGNAL PROCESSING
SAMPLING THEORM WITH MATLAB CODING
THEORY:
In the field of digital signal processing, the sampling theorem is a fundamental bridge between continuous signals (analog domain) and discrete signals (digital domain).
The Nyquist sampling theorem provides a prescription for the nominal sampling interval required to avoid aliasing. It may be stated simply as follows
“The sampling frequency should be at least twice the highest frequency contained in the signal”
Or in mathematical terms:
fs ≥ 2f max
Where fs is the sampling frequency and fmax is the highest frequency contained in the signal.
MATLAB CODE:
clear
fmax=3;             %maximum frequency of signal
t=0:0.0001:1;
x=cos(2*pi*fmax*t);
subplot(221)
plot(t,x)
xlabel('time in seconds');
ylabel('x(t)');
title('original signal');
fs1=fmax;           %samplinf frequency = fmax
fs2=2*fmax;         %samplinf frequency = two time fmax
fs3=8*fmax;         %samplinf frequency = eight times fmax

%%% under sampled %%%%
t1=0:1/fs1:1
x1=cos(2*pi*fmax*t1);
subplot(222)
plot(t1,x1)
hold on
stem(t1,x1)
xlabel('time in seconds');
ylabel('x1');
title('under sampled');

%%% two times fmax %%%%
t2=0:1/fs2:1
x2=cos(2*pi*fmax*t2);
subplot(223)
plot(t2,x2)
hold on
stem (t2,x2)
xlabel('time in seconds');
ylabel('x2');
title('two time fmax');

%%% over sampled %%%%
t3=0:1/fs3:1
x3=cos(2*pi*fmax*t3);
subplot(224)
plot(t3,x3)
hold on
stem(t3,x3)
xlabel('time in seconds');
ylabel('x3');
title('over sampled');
RESULTS:
See picture NAMED RESULT 1
EXERCISE:
1. Generate the following signals and plot the signal by taking the samples below the Nyquist rate, exactly equal to Nyquist rate and six times the Nyquist rate.
(a)   X(t) = 5 cos 15 π t + 10 sin 25 π t
MATLAB CODE:
close
clear
fmax=7;         %maximum frequency of signal
t=0:0.0001:1;
x1=5*cos(15*pi*t);
x2=10*sin(25*pi*t);
x=x1+x2;
subplot(221)
plot(t,x)
xlabel('time in seconds');
ylabel('x(t)');
title('original signal');
fs1=fmax/2;           %sampling frequency = fmax/2 (below)
fs2=fmax;         %sampling frequency = fmax (exactly equal)
fs3=6*fmax;         %sampling frequency = six times fmax (6*times)
%%% under sampled %%%%
t1=0:1/fs1:1
x11=5*cos(15*pi*t1)+10*sin(25*pi*t1);
subplot(222)
plot(t1,x11)
hold on
stem(t1,x11)
xlabel('time in seconds');
ylabel('x11');
title('under sampled');

%%% equal to fmax %%%%
t2=0:1/fs2:1
x22=5*cos(15*pi*t2)+10*sin(25*pi*t2);
subplot(223)
plot(t2,x22)
hold on
stem (t2,x22)
xlabel('time in seconds');
ylabel('x22');
title('equals to fmax');

%%% 6 times sampled %%%%
t3=0:1/fs3:1
x33=5*cos(15*pi*t3)+10*sin(25*pi*t3);
subplot(224)
plot(t3,x33)
hold on
stem(t3,x33)
xlabel('time in seconds');
ylabel('x33');
title('6 times sampled');

RESULTS
 See picture NAMED RESULT 2
(b)   Y(t )= 25 sin 20 π t + 50 sin 16 π t + 30 cos 28π t
MATLAB CODE:
close
clear
fmax=7;         %maximum frequency of signal
t=0:0.0001:1;
y1=25*sin(20*pi*t);
y2=50*sin(16*pi*t);
y3=30*cos(28*pi*t);
y=y1+y2+y3;
subplot(221)
plot(t,y)
xlabel('time in seconds');
ylabel('y(t)');
title('original signal');
fs1=fmax/2;           %sampling frequency = fmax/2 (below)
fs2=fmax;         %sampling frequency = fmax (exactly equal)
fs3=6*fmax;         %sampling frequency = six times fmax (6*times)
%%% under sampled %%%%
t1=0:1/fs1:1
y11=25*sin(20*pi*t1)+50*sin(16*pi*t1)+30*cos(28*pi*t1);
subplot(222)
plot(t1,y11)
hold on
stem(t1,y11)
xlabel('time in seconds');
ylabel('y11');
title('under sampled');

%%% equal to fmax %%%%
t2=0:1/fs2:1
y22=25*sin(20*pi*t2)+50*sin(16*pi*t2)+30*cos(28*pi*t2);
subplot(223)
plot(t2,y22)
hold on
stem (t2,y22)
xlabel('time in seconds');
ylabel('y22');
title('equals to fmax');

%%% 6 times sampled %%%%
t3=0:1/fs3:1
y33=25*sin(20*pi*t3)+50*sin(16*pi*t3)+30*cos(28*pi*t3);
subplot(224)
plot(t3,y33)
hold on
stem(t3,y33)
xlabel('time in seconds');
ylabel('y33');
title('6 times sampled');
RESULTS:
See picture NAMED RESULT 3

No comments:

Post a Comment