Acom SW Lab Xpts
Acom SW Lab Xpts
>>
Unit Step
1
0.8
0.8
0.6
0.6
Amplitude
Amplitude
Unit Impulse
1
0.4
0.2
0.4
0.2
0
-2
-1.5
-1
-0.5
0
Time
0.5
1.5
0
-5
-4
-3
-2
-1
Unit Ramp
14
3.5
12
3.5
4.5
10
2.5
Amplitude
Amplitude
Exponential
2
1.5
8
6
4
0.5
0
0
Time
0.5
1.5
2
Time
2.5
3.5
0.5
1.5
2.5
Time
Sine Wave
Amplitude
2
1
0
-1
-2
0.1
0.2
0.3
0.4
0.5
0.6
Time
square wave
100
200
300
400
0.7
0.8
0.9
700
800
900
1000
Amplitude
2
1
0
-1
-2
500
Time
600
3.GENERATION OF AM
%AM wave
clc;
clear all;
close all;
fc=input('Enter the frequency of the carrier signal fc=');
fm=input('Enter the frequency of the modulating signal fm=');
m=input('Modulation index m=');
t=0:0.001:1;
c=sin(2*pi*fc*t);
subplot(221);
plot(t,c);
ylabel('Amplitude');
xlabel('Time');
title('Carrier signal');
M=sin(2*pi*fm*t);
subplot(222);
plot(t,M);
ylabel('Amplitude');
xlabel('Time');
title('Modulating signal');
y=(1+m*M).*c;
subplot(223);
plot(t,y);
grid on;
ylabel('Amplitude');
xlabel('Time');
title('Modulated signal');
%AM with suppressed carrier
t=0:0.001:1;
c=sin(2*pi*fc*t);
M=sin(2*pi*fm*t);
y=M.*c;
subplot(224);
plot(t,y);
grid on;
axis([0 1 -2 2]);
ylabel('Amplitude');
xlabel('Time');
title('Suppressed carrier');
>>
Modulating signal
1
0.5
0.5
Amplitude
Amplitude
Carrier signal
1
-0.5
-1
-0.5
0.1
0.2
0.3
0.4
0.5
Time
0.6
0.7
0.8
0.9
-1
0.1
0.2
0.3
1.5
1.5
0.5
0.5
0
-0.5
-1.5
-1.5
0.1
0.2
0.3
0.4
0.5
Time
0.6
0.7
0.8
0.9
0.7
0.8
0.9
-0.5
-1
0.6
-1
-2
0.5
Time
Suppressed carrier
Amplitude
Amplitude
Modulated signal
0.4
0.7
0.8
0.9
-2
0.1
0.2
0.3
0.4
0.5
Time
0.6
4.GENERATION OF PM
%PM generation
clc;
clear all;
close all;
fm=input('Message frequency=');
fc=input('Carrier frquency=');
m=input('Modulation index=');
t=0:0.0001:0.1;
c=sin(2*pi*fc*t);
M=sin(2*pi*fm*t);
subplot(311);
plot(t,c);
grid on;
ylabel('Amplitude');
xlabel('Time');
title('Carrier signal');
subplot(312);
plot(t,M);
grid on;
ylabel('Amplitude');
xlabel('Time');
title('Modulating signal');
y=cos((2*pi*fc*t)+(m.*sin(2*pi*fm*t)));
subplot(313);
plot(t,y);
grid on;
ylabel('Amplitude');
xlabel('Time');
title('PM signal');
Message frequency=20
Carrier frquency=400
Modulation index=10
>>
Carrier signal
1
Amplitude
0.5
0
-0.5
-1
0.01
0.02
0.03
0.04
0.05
Time
0.06
0.07
0.08
0.09
0.1
0.06
0.07
0.08
0.09
0.1
0.06
0.07
0.08
0.09
0.1
Modulating signal
1
Amplitude
0.5
0
-0.5
-1
0.01
0.02
0.03
0.04
0.05
Time
PM signal
Amplitude
0.5
0
-0.5
-1
0.01
0.02
clc;
clear all;
close all;
fs=1000;
t=0:1/fs:1;
f=1;
A=1;
x=A*sin(2*pi*f*t);
subplot(2,1,1);
plot(t,x);
ylabel('x(t)');
xlabel('t(sec)');
title('Original signal');
axis([min(t) max(t) -A A]);
grid on;
M=8;
xq=quantise(x,M);
subplot(2,1,2);
plot(t,xq);
ylabel('xq(t)');
0.03
0.04
0.05
Time
xlabel('t(sec)');
title('Quantised signal');
axis([min(t) max(t) -A A]);
grid on;
sig_energy=0;
sqr_error=0;
for i=1:length(x)
sqr_error=sqr_error+((x(i)-xq(i))^2);
sig_energy=sig_energy+(x(i)^2);
end
mean=sqr_error/length(x)
SNRdB=10*log10(sig_energy/sqr_error)
%function quantize
function y=quantise(x,M)
minx=min(x);
maxx=max(x);
delta=(maxx-minx)/M;
y=zeros(size(x));
for i=1:length(x)
for j=1:M
if(x(i)<=(minx+(j*delta)))
y(i)=minx+((2*j-1)/2)*delta;
break;
end
end
end
end
mean =
0.0062
SNRdB =
19.0821
Original signal
1
x(t)
0.5
0
-0.5
-1
0.1
0.2
0.3
0.4
0.5
0.6
t(sec)
Quantised signal
0.7
0.8
0.9
0.1
0.2
0.3
0.4
0.7
0.8
0.9
xq(t)
0.5
0
-0.5
-1
0.5
t(sec)
0.6
title('Delayed signal');
axis([min(t) max(t)+T -A A]);
grid on;
corr=zeros(1,length(t1));
for i=1:length(y)
for j=1:length(x)
if i+j-1<=length(y)
corr(i)=corr(i)+y(i+j-1)*x(j);
else
break
end
end
end
subplot(3,1,3);
plot(t1,corr);
ylabel('corr');
xlabel('t(sec)');
title('Correlation function');
grid on;
delay=(find(corr==max(corr))-1)/fs
delay =
1.9920
Original signal
x(t)
1
0
-1
0.5
1.5
t(sec)
Delayed signal
2.5
0.5
1.5
t(sec)
Correlation function
2.5
0.5
1.5
t(sec)
2.5
y(t)
1
0
-1
corr
500
0
-500
7.BASK
clc; clear all; close all;
flag = 0;
%variable to check whether carrier frequencies are integer
multiples of bitrate
while ~flag
fc = input('Enter the Carrier Frequency: ');
bitRate = input('Enter the Bit Rate: ');
if mod(fc,bitRate)~=0
disp('Carrier frequency should be an integer multiple of
Rate!!!');
continue
end
flag = 1;
Bit
t = 0:1/(10*fc):1/bitRate-1/(10*fc);
flag1 = 0; %variable to check whether input data has any non-binary
value
sig0 = zeros(size(t));
sig1 = cos(2*pi*fc*t);
while ~flag1
x = input('Enter the binary Data: ');
y = [];
data = [];
taxis = [];
for i = 1:length(x)
if x(i)~=0 && x(i)~=1
disp('please enter only binary values');
flag1 = 0;
break;
else
taxis = [taxis (i-1)*max(t)+t];
flag1 = 1;
if x(i) == 0
y = [y sig0];
data = [data zeros(size(t))];
else
y = [y sig1];
data = [data ones(size(t))];
end
end
end
end
subplot(311)
plot(taxis,data);
title('Binary Data');
xlabel('t(sec)-->');
axis([0 max(taxis) -0.5 1.5]);
subplot(312)
plot(taxis,y);
title('BASK Modulated Signal');
xlabel('t(sec)-->');
axis([0 max(taxis) -1.5 1.5]);
end
xcap = [];
datacap = [];
for i = 1:length(x)
st_ind = (i-1)*length(t) + 1;
en_ind = i*length(t);
sig = y(st_ind:en_ind);
d = sig*sig1';
if d<length(t)/4
xcap = [xcap 0];
datacap = [datacap zeros(size(t))];
else
xcap = [xcap 1];
datacap = [datacap ones(size(t))];
end
end
subplot(313)
plot(taxis,datacap);
title('Demodulated Data');
xlabel('t(sec)-->');
axis([0 max(taxis) -0.5 1.5]);
disp('The demodulated data = ');
disp(xcap);
>>
Binary Data
1.5
1
0.5
0
-0.5
0.005
0.01
0.015
0.02
t(sec)-->
BASK Modulated Signal
0.025
0.03
0.035
0.005
0.01
0.015
0.02
t(sec)-->
Demodulated Data
0.025
0.03
0.035
0.005
0.01
0.015
0.02
t(sec)-->
0.025
0.03
0.035
-1
1.5
1
0.5
0
-0.5
8.BFSK
Bit
t = 0:1/(100*fc1):1/bitRate-1/(100*fc1);
flag1 = 0; %variable to check whether input data has any non-binary
value
sig0 = cos(2*pi*fc1*t);
sig1 = cos(2*pi*fc2*t);
while ~flag1
x = input('Enter the binary Data: ');
y = [];
data = [];
taxis = [];
for i = 1:length(x)
if x(i)~=0 && x(i)~=1
disp('please enter only binary values');
flag1 = 0;
break;
else
taxis = [taxis (i-1)*max(t)+t];
flag1 = 1;
if x(i) == 0
y = [y sig0];
data = [data zeros(size(t))];
else
y = [y sig1];
data = [data ones(size(t))];
end
end
end
end
subplot(311)
plot(taxis,data);
title('Binary Data');
xlabel('t(sec)-->');
axis([0 max(taxis) -0.5 1.5]);
subplot(312)
plot(taxis,y);
title('BFSK Modulated Signal');
xlabel('t(sec)-->');
axis([0 max(taxis) -1.5 1.5]);
end
xcap = [];
datacap = [];
for i = 1:length(x)
st_ind = (i-1)*length(t) + 1;
en_ind = i*length(t);
sig = y(st_ind:en_ind);
d1 = sig*sig0';
d2 = sig*sig1';
if d1>d2
xcap = [xcap 0];
datacap = [datacap zeros(size(t))];
else
xcap = [xcap 1];
datacap = [datacap ones(size(t))];
end
end
subplot(313)
plot(taxis,datacap);
title('Demodulated Data');
xlabel('t(sec)-->');
axis([0 max(taxis) -0.5 1.5]);
disp('The demodulated data = ');
disp(xcap);
>>
Binary Data
1.5
1
0.5
0
-0.5
0.005
0.01
0.015
0.02
t(sec)-->
BFSK Modulated Signal
0.025
0.03
0.035
0.005
0.01
0.015
0.02
t(sec)-->
Demodulated Data
0.025
0.03
0.035
0.005
0.01
0.015
0.02
t(sec)-->
0.025
0.03
0.035
-1
1.5
1
0.5
0
-0.5
9.BPSK
clc; clear all; close all;
flag = 0;
%variable to check whether carrier frequencies are integer
multiples of bitrate
while ~flag
fc = input('Enter the Carrier Frequency: ');
bitRate = input('Enter the Bit Rate: ');
if mod(fc,bitRate)~=0
disp('Carrier frequency should be an integer multiple of
Rate!!!');
continue
end
flag = 1;
Bit
t = 0:1/(10*fc):1/bitRate-1/(10*fc);
flag1 = 0; %variable to check whether input data has any non-binary
value
sig0 = -cos(2*pi*fc*t);
sig1 = cos(2*pi*fc*t);
while ~flag1
x = input('Enter the binary Data: ');
y = [];
data = [];
taxis = [];
for i = 1:length(x)
if x(i)~=0 && x(i)~=1
disp('please enter only binary values');
flag1 = 0;
break;
else
taxis = [taxis (i-1)*max(t)+t];
flag1 = 1;
if x(i) == 0
y = [y sig0];
data = [data zeros(size(t))];
else
y = [y sig1];
data = [data ones(size(t))];
end
end
end
end
subplot(311)
plot(taxis,data);
title('Binary Data');
xlabel('t(sec)-->');
axis([0 max(taxis) -0.5 1.5]);
subplot(312)
plot(taxis,y);
title('BPSK Modulated Signal');
xlabel('t(sec)-->');
axis([0 max(taxis) -1.5 1.5]);
end
xcap = [];
datacap = [];
for i = 1:length(x)
st_ind = (i-1)*length(t) + 1;
en_ind = i*length(t);
sig = y(st_ind:en_ind);
d = sig*sig0';
if d>0
xcap = [xcap 0];
datacap = [datacap zeros(size(t))];
else
xcap = [xcap 1];
datacap = [datacap ones(size(t))];
end
end
subplot(313)
plot(taxis,datacap);
title('Demodulated Data');
xlabel('t(sec)-->');
axis([0 max(taxis) -0.5 1.5]);
disp('The demodulated data = ');
disp(xcap);
>>
Binary Data
1.5
1
0.5
0
-0.5
0.005
0.01
0.015
0.02
t(sec)-->
BPSK Modulated Signal
0.025
0.03
0.035
0.005
0.01
0.015
0.02
t(sec)-->
Demodulated Data
0.025
0.03
0.035
0.005
0.01
0.015
0.02
t(sec)-->
0.025
0.03
0.035
-1
1.5
1
0.5
0
-0.5
10.HUFFMAN ENCODING
clc;
clear all;
close all;
symbols=[1:6];
p=[.5 .125 .125 .125 .0625 .0625];
[dict,avglen] = huffmandict(symbols,p);
temp = dict;
for i = 1:length(temp)
temp{i,2} = num2str(temp{i,2});
end
[1] '0'
[2] '1 0 0'
[3] '1 1 1'
[4] '1 1 0'
[5] '1 0 1 1'
[6] '1 0 1 0'
>>