Vous êtes sur la page 1sur 6

............................................................

%Sampling
clc;
clear all;
close all;
fs=50;
t=-pi:1/fs:pi;
len=length(t);
f=input('Input frequency:');
A=10;
message=A*sin(2*f*t);
subplot(3,3,1);
plot(t,message);
title('Message signal');
delta=zeros(1,len);
delta1=zeros(1,len);
delta2=zeros(1,len);

for i=1:4:len
delta(i)=1;
end

undersampled=delta.*message;
subplot(3,3,2);
stem(t,undersampled);
title('Undersampled signal');

for i=1:2:len
delta(i)=1;
end

normalsampled=delta1.*message;
subplot(3,3,5);
stem(t,normalsampled);
title('Normal Sampled');

for i=1:len
delta2(i)=1;
end

oversampled=delta2.*message;
subplot(3,3,4);
stem(t,oversampled);
title('Oversampled');
undersampledf=filter(f,1,undersampled);
normalsampledf=filter(f,1,normalsampled);
oversampledf=filter(f,1,oversampled);

...............................................................
%PCM
clc;
clear all;
close all;

f=1;
fs=2;
t=0:1/100*f:1;

message =8*sin(2*pi*f*t)+5;
subplot(4,1,1);
plot(t,message);
xlabel('message signal');
ylabel('amplitude');

sampled =8*sin(2*pi*fs*t)+5;
subplot(4,1,2);
stem(sampled);
xlabel('sampled signal');
ylabel('amplitude');

q =floor(sampled)-5;
subplot(4,1,3);
stem(2*q);
xlabel('quantized signal');
ylabel('amplitude');

d =2*filter(f,1,q);
subplot(4,1,4);
plot(t,d);
xlabel('reconstruct signal');
ylabel('amplitude');
................................................................

%line coding
clc;
clear all;
close all;

data=[0,1,1,0,0,0,1,0,1,1];
y=[0,0,0,0,0,0,0,0,0,0];
for n=1:10
if x(t)==1
if data(n)==1
y(n)=1;
else
y(n)=0;
end
end

subplot(7,1,1);
stem(y);
title('DATA');

y2=[0,0,0,0,0,0,0,0,0,0];
p=0;
for n=2:10
if data(n)==1
if y2(n-1)==0
y2(n)=1;
else
y2(n)=0;
end
else
y2(n)=0;
end
end
subplot(7,1,2);
stem(y2);
title('NRZ(M)');

y3=zeros(1,20);
for n=1:10
if data(n)==1
y3(2*n)==0
y3(2*n-1)=1;
else
y3(2*n-1)=0;
y3(2*n)=0;
end
end
subplot(7,1,3);
stem(y3);
title('RZ');

y4=zeros(1,20);
for n=1:10
if data(n)==1
y4(2*n)==0
y4(2*n-1)=1;
else
y4(2*n-1)=0;
y4(2*n)=1;
end
end
subplot(7,1,4);
stem(y4);
title('Biphase(Manchester)');

y5=zeros(1,20);
for n=1:10
if data(n)==1
y5(2*n)==0
y5(2*n-1)=1;
else
y5(2*n-1)=-1;
y5(2*n)=0;
end
end
subplot(7,1,5);
stem(y5);
title('RB');

y6=zeros(1,20);
p=-1;
for n=1:10
if data(n)==1
if p==-1
y6(2*n)==0
y6(2*n-1)=1;
p=1;
else
y6(2*n-1)=-1;
y6(2*n)=0;
p=-1;
end
end
subplot(7,1,6);
stem(y6);
title('AMI');

.................................................................
%Delta modulation
clc;
clear all;
close all;
a=5;
f=5;
t=0:2*pi/50:2*pi;
x=a*sin(2*pi*f*t);
subplot(3,1,1);
plot(t,x);
l=length(x);

delta=1;
hold on
x1=0;
for i=1:1
if x(i)>x1(i)
x1(i+1)=x(i)+delta;
else
x(i+1)=x(i)-delta;
end
end

stairs(x1);
hold on
title('delta modultaion with delta=1');
subplot(3,1,2);
plot(x,'c');

delta=0.2;
hold on
x1=0;
for i=1:1
if x(i)>x1(i)
x1(i+1)=x(i)+delta;
else
x(i+1)=x(i)-delta;
end
end

stairs(x1);
hold on
title('delta modultaion with delta=0.2');
subplot(3,1,3);
plot(x,'r');

delta=2;
hold on
x1=0;
for i=1:1
if x(i)>x1(i)
x1(i+1)=x(i)+delta;
else
x(i+1)=x(i)-delta;
end
end

stairs(x1);
hold on
title('delta modultaion with delta=2');

.....................................................................
%Adaptive delta modulation
clc
clear all;

t =0:1/29:1;
f=1;
x=4*sin(2*pi*f*t);
x=[x ones(1,10) x];
y = zeros(1,length(x));
d = zeros(1,length(x));
e= zeros(1,length(x));
s=0.1;
for i=5:length(x)
if(x(i)-y(i-1))>=0
y(i) = x(i)-s;
d(i)=-1;
elseif(x(i)-y(i-1))<0
y(i)=x(i)-1;
d(i)=-1;
end

if(sum(d(i-4:i)))>3
s=s+0.01;
elseif(sum(d(i-4:i)))<-3
s=s+0.01;
elseif(sum(d(i-4:i)))==0
s=s-0.01;
else
s=s;
end
pause;
subplot 211; plot(x); hold on;
stem(y,'m');e=x-y;plot(e,'r');
title('Input,tracking and error graph');
subplot 212; stem (d,'k'); title('output data signal')
end

...............................................................................
%ask, fsk and psk digital modulation techniques
f=5;
f2=10;
x=[1 1 0 0 1 0 1 0] % input signal ;
nx=size(x,2);

i=1;
while i<nx+1
t = i:0.001:i+1;
if x(i)==1
ask=sin(2*pi*f*t);
fsk=sin(2*pi*f*t);
psk=sin(2*pi*f*t);
else
ask=0;
fsk=sin(2*pi*f2*t);
psk=sin(2*pi*f*t+pi);
end
subplot(3,1,1);
plot(t,ask);
hold on;
grid on;
axis([1 10 -1 1]);
title('Amplitude Shift Key')
subplot(3,1,2);
plot(t,fsk);
hold on;
grid on;
axis([1 10 -1 1]);
title('Frequency Shift Key')

subplot(3,1,3);
plot(t,psk);
hold on;
grid on;
axis([1 10 -1 1]);
title('Phase Shift Key')

i=i+1;
end

Vous aimerez peut-être aussi