signal n

advertisement
P3.18. An analog signal xa(t) = sin (100πt) is sampled using the following sampling intervals. In
each case plot the spectrum of the resulting discrete-time signal.
Ts= 0.1 ms, Ts= 1 ms, Ts = 0.01 Sec
MATLAB CODE:
clear all;clc;
Ts1=0.1/1000;
n1=1:3:200;
t1=n1*Ts1;
Time1=t1;
xt1 = sin (100*pi*t1);
j=j+1;
%n1=1:1:100;
subplot(3,1,1);
stem(Time1,xt1)
xlabel('Time Plot (t)>>');
ylabel('x(n)');
title('Discrete signal for Ts=0.1ms')
Ts2=1/1000;
k=1;
n2=1:3:200;
t2=n2*Ts2;
Time2=t2;
xt2 = sin (100*pi*t2);
k=k+1;
subplot(3,1,2);
%n2=1:1:100;
stem(Time2,xt2)
xlabel('t');
ylabel('x(n)');
title('Discrete signal for Ts=1ms')
Ts3=0.01;
l=1;
n3=1:3:200;
t3=n3*Ts3;
Time3=t3;
xt3 = sin (100*pi*t3);
subplot(3,1,3);
%n3=1:1:100;
stem(Time3,xt3)
xlabel('t');
ylabel('x(n)');
title('Discrete signal for Ts=0.1s')
OUTPUT
P3.20. Consider an analog signal xa (t) = sin (2πt), 0 ≤t≤ 1. It is sampled at Ts = 0.01, 0.05,
and 0.1 sec intervals to obtain x(n).
MATLAB CODE:
a)
For each Ts plot x (n).
clear all;clc;
Ts1=0.01;n=1:3:1/Ts1;
t=n*Ts1;
Time=t;
xn1 = sin (2*pi*t);
subplot(3,1,1)
stem(n,xn1)
title('Discrete Signal for Ts=0.01 Sec');
xlabel('n Plot');
ylabel('x(n)');
Ts2=0.05;n=1:1:1/Ts2;
t=n*Ts2;
Time1=t;
xn2 = sin (2*pi*t);
subplot(3,1,2)
stem(n,xn2)
title('Discrete Signal for Ts=0.05 Sec');
xlabel('n Plot');
ylabel('x(n)');
Ts3=0.1;n=1:1:1/Ts3;
t=n*Ts3;
Time2=t;
xn3 = sin (2*pi*t);
subplot(3,1,3)
stem(n,xn3)
title('Discrete Signal for Ts=0.1 Sec');
xlabel('n Plot');
ylabel('x(n)');
OUTPUT
b) Reconstruct the analog signal ya (t) from the samples x(n) using the sinc interpolation
(use ∆t = 0.001) and determine the frequency in ya (t) from your plot. (Ignore the end
effects.)
MATLAB CODE:
clear all;clc;
Ts1=0.01;Fs=1/Ts1;
n=0:1:100;
nTs1=n*Ts1;
x=sin(2*pi*nTs1);
Dt=0.001;t=0:Dt:1;
xa=x*sinc(Fs*(ones(length(n),1)*t-nTs1'*ones(1,length(t))));
subplot(3,1,1)
plot(t,xa)
title('Reconstruct Signal using `sinc` interpolation, Ts=0.01 Sec');
xlabel('Time (t)');
ylabel('y(t)');
Ts2=0.05;Fs=1/Ts2;
n=0:1:20;
nTs2=n*Ts2;
x=sin(2*pi*nTs2);
Dt=0.001;t=0:Dt:1;
xa=x*sinc(Fs*(ones(length(n),1)*t-nTs2'*ones(1,length(t))));
subplot(3,1,2)
plot(t,xa)
title('Reconstruct Signal using `sinc` interpolation, Ts=0.05 Sec');
xlabel('Time (t)');
ylabel('y(t)');
Ts3=0.1;Fs=1/Ts3;
n=0:1:10;
nTs3=n*Ts3;
x=sin(2*pi*nTs3);
Dt=0.001;t=0:Dt:1;
xa=x*sinc(Fs*(ones(length(n),1)*t-nTs3'*ones(1,length(t))));
subplot(3,1,3)
plot(t,xa)
title('Reconstruct Signal using `sinc` interpolation, Ts=0.1 Sec');
xlabel('Time (t)');
ylabel('y(t)');
OUTPUT
C) Reconstruct the analog signal ya (t) from the samples x (n) using the cubic spline
interpolation and determine the frequency in ya (t) from your plot. (Ignore the end effects.)
MATLAB CODE:
clear all;clc;
Ts1=0.01;Fs=1/Ts1;
n=0:1:100;
nTs1=n*Ts1;
x=sin(2*pi*nTs1);
Dt=0.001;
t=0:Dt:1;
xa=spline(nTs1,x,t);
subplot(3,1,1)
plot(t,xa)
title('Reconstruct Signal using `spline` interpolation, Ts=0.01 Sec');
xlabel('Time (t)');
ylabel('y(t)');
Ts2=0.05;Fs=1/Ts2;
n=0:1:20;
nTs2=n*Ts2;
x=sin(2*pi*nTs2);
Dt=0.001;
t=0:Dt:1;
xa=spline(nTs2,x,t);
subplot(3,1,2)
plot(t,xa)
title('Reconstruct Signal using `spline` interpolation, Ts=0.05 Sec');
xlabel('Time (t)');
ylabel('y(t)');
Ts3=0.1;Fs=1/Ts3;
n=0:1:10;
nTs3=n*Ts3;
x=sin(2*pi*nTs3);
Dt=0.001;
t=0:Dt:1;
xa=spline(nTs3,x,t);
subplot(3,1,3)
plot(t,xa)
title('Reconstruct Signal using `spline` interpolation, Ts=0.1 Sec');
xlabel('Time (t)');
ylabel('y(t)');
OUTPUT
π
P3.21. Consider the analog signal Xa (t) = sin (20π t + 4 ) , 0 < t < 1. It is sampled at Ts = 0.05sec
intervals to obtain x(n).
a) Plot xa (t) and superimpose x(n) on it using the plot(n,x, ' o ' ) function.
MATLAB CODE:
clear all; clc;
t=0:0.005:1;
n=t/0.05;
nT=n*0.05;
%xt = sin((20*pi*t)+(pi/4)); %analog
xt=sin(20*pi*t+pi/4);
xn = sin(20*pi*nT+pi/4); %discrete
%xt=sin(20*pi*t+pi/4);
%subplot(3,1,1)
plot (t,xt)
title('Analog signal and discrete signal superimposed on it');
xlabel('Time (t)');
ylabel('xa(t)');
hold
%subplot(3,1,2)
plot(n/20,xn,'o')
OUTPUT
b. Reconstruct the analog signal y (t) from the samples X(n) using the sinc interpolation
(use ∆t = 0.001) and superimpose X(n) on it.
MATLAB CODE:
clc;clear all;
Ts=0.05;
Fs=1/Ts;
n=0:1:1/Ts;
nTs=n*Ts;
xn=sin(20*pi*nTs+pi/4);
Dt=0.001;t=0:Dt:1;
xt=xn*sinc(Fs*(ones(length(n),1)*t-nTs'*ones(1,length(t))));
plot(t,xt)
title('Reconstructed analog signal y(t) using the sinc interpolation and the
discrete signal');
xlabel('Time (t)');
ylabel('y(t)');
hold on
n=0:1:20;
nT=n*0.05;
xn = sin(20*pi*nT+pi/4); %discrete signal
plot (n/20,xn,'o-')
OUTPUT
c. Reconstruct the analog signal ya (t) from the samples x(n) using the cubic spline interpolation
and superimpose x(n) on it.
MATLAB CODE:
clear all;clc;
Ts1=0.05;
Fs=1/Ts1;
n=0:1:20;
nTs=n*Ts1;
x=sin(20*pi*nTs+pi/4);
Dt=0.001;
t=0:Dt:1;
ya=spline(nTs,x,t);
%subplot(3,1,1)
plot(t,ya)
title('Reconstracted Signal using `spline` interpolation')
ylabel('Analog signal - ya(t)')
xlabel('Time (t)')
hold on
nT=n*0.05;
xn = sin(20*pi*nT+pi/4); %discrete signal
plot (n/20,xn,'o-')
OUTPUT
Download