Friday 3 January 2014

MATLAB SAMPLING THEOREM EXAMPLE

Here is a matlab code to demonstrate the sampling theorem.

CODE:

 fig_size=[232 84 774 624];

Ts1=0.05;

Ts2=0.1;

Ts3=0.2;

ws1=2*pi/Ts1;

ws2=2*pi/Ts2;

ws3=2*pi/Ts3;

w1=7;

w2=23;

t=[0:0.005:2];

x=cos(w1*t)+cos(w2*t);

disp(‘X’);

disp(x);

subplot(2,3,1),plot(t,x),grid,xlabel(‘time(s)’),ylabel(‘amplitude’),….

title(‘continuous‐time signal; x(t)=cos(7t)+cos(23t)’),….

set(gcf,’position’,fig_size)

t1=[0:Ts1:2];

xs1=cos(w1*t1)+cos(w2*t1);

disp(‘xs1′);

disp(xs1);

subplot(2,3,2);

stem(t1,xs1);

grid,hold on,plot(t,x,’r'),hold off,….

xlabel(‘time(s)’),ylabel(‘amplitude’),….

title(‘sampled version of x(t) with Ts=0.05s’),….

set(gcf,’position’,fig_size)

t2=[0:Ts2:2];

xs2=cos(w1*t2)+cos(w2*t2);

subplot(2,3,3);

stem(t2,xs2);

grid,hold on,plot(t,x,’r'),hold off,….

xlabel(‘time(s)’),ylabel(‘amplitude’),….

title(‘sampled version of x(t) with Ts=0.1s’),….

set(gcf,’position’,fig_size)

t3=[0:Ts3:2];

xs3=cos(w1*t3)+cos(w2*t3);

subplot(2,3,4);

stem(t3,xs3);

grid,hold on,plot(t,x,’r'),hold off,….

xlabel(‘time(s)’),ylabel(‘amplitude’),….

title(‘sampled version of x(t) with Ts=0.2s’),….

set(gcf,’position’,fig_size)

w2s3=w2‐ws3;

x1=cos(w1*t)+cos(w2s3*t);

subplot(2,3,5);

stem(t3,xs3);

grid,hold on,plot(t,x,’k:’,t,x1,’r:’),hold off,….

xlabel(‘time(s)’),ylabel(‘amplitude’),….

title(‘sampled version of x(t) & x1(t) with Ts=0.2s’),….

set(gcf,’position’,fig_size)

text(1.13,1.2,’x(t)’),text(0.1,1.6,’x1(t)’)

n=[‐1 0 1];

wx=[‐w2 ‐w1 w1 w2];

wx1=[];

wx2=[];

wx3=[];

for i=1:length(n)

wx1=[wx1 (wx+n(i)*ws1)];

wx2=[wx2 (wx+n(i)*ws2)];

wx3=[wx3 (wx+n(i)*ws3)];

end

wx1=sort(wx1);

wx2=sort(wx2);

wx3=sort(wx3);

clear i

disp(wx1)

OUTPUT:

ED Matlab sampling theorem
ED Matlab sampling theorem

ED Matlab sampling theorem

CLICK HERE TO READ MORE...



1 comments:

Search Here...