Pages

Sunday 18 November 2012

Error Probability Curve of M-ary PSK (Matlab 2012a)

Program:

clc;
clear all;
n = input('Enter the number of values to be compared = ');
colour = ['k','r','g','b','y'];
nsample = 1;
m = 4;
for i = 1:n
    eb_db = 0:0.0001:25;
    k = log2(m);
    es_db = eb_db + 10*log(k) + 10*log(nsample);
    es = db2mag(es_db);
    p = 2*qfunc(sqrt(2*es).*sin(pi/m));
    semilogy(eb_db,p,colour(k));
    hold on;
    m = m*2;
end
xlabel('SNR ----->');
ylabel('Probability of Error ----->');
title('Error Probability Curve of M ary PSK');
grid on;
legend('m = 4','m = 8','m = 16','m = 32');


Output:

Enter the number of values to be compared = 4

Output Graph:


Error Probability Curve of M-ary QAM (Matlab 2012a)

Program:

clc;
clear all;
n = input('Enter the number of values to be compared = ');
colour = ['k','r','g','b','y'];
nsample = 1;
m = 4;
for i = 1:n
    eb_db = 0:0.0001:25;
    k = log2(m);
    es_db = eb_db + 10*log(k) + 10*log(nsample);
    es = db2mag(es_db);
    p = 4*qfunc(sqrt(3*es/(m-1)));
    semilogy(eb_db,p,colour(k));
    hold on;
    m = m*2;
end
xlabel('SNR ----->');
ylabel('Probability of Error ----->');
title('Error Probability Curve of M ary QAM');
grid on;
legend('m = 4','m = 8','m = 16','m = 32');


Output:

Enter the number of values to be compared = 4

Output Graph:


Friday 16 November 2012

Pulse Code Modulation (Matlab 2012a)

Program:

clc;
clear all;
t = 0:0.0005:20;
partition = -1:0.1:1;
codebook = -1:0.1:1.1;
x = sin(t);
[index,quants] = quantiz(x,partition,codebook);
subplot(3,1,1);
plot(t,x);
title('Message Signal');
xlabel('Time(s) ---->')
ylabel('Amplitude(V) ---->')
subplot(3,1,2);
plot(t,quants);
title('Quantized Signal');
xlabel('Time(s) ---->')
ylabel('Amplitude(V) ---->')
y = uencode(quants,3);
subplot(3,1,3);
plot(t,y);
title('PCM Signal');
xlabel('Time(s) ---->');
ylabel('Amplitude(V) ---->')




Output Waveforms: 

Wednesday 14 November 2012

Pulse Width Modulation (Matlab 2012a)

Program:

clc;
clear all;
t = 0:0.001:1;
fc = input('Enter the frequency of carrier signal (sawtooth) = ');
fm = input('Enter the frequency of message signal (sine) = ');
a = input('Enter the amplitude of carrier signal = ');
b = input('Enter the amplitude of message signal(should be < Carrier) = ');
vc = a.*sawtooth(2*pi*fc*t);
vm = b.*sin(2*pi*fm*t);

n = length(vc);
for i = 1:n
    if (vm(i)>=vc(i))
        pwm(i) = 1;
    else
        pwm(i) = 0;
    end
end
subplot(3,1,1);
plot(t,vm);
xlabel('Time ----->');
ylabel('Amplitude ----->');
title('Message Signal');
grid on;
subplot(3,1,2);
plot(t,vc);
xlabel('Time ----->');
ylabel('Amplitude ----->');
title('Carrier Signal');
grid on;
subplot(3,1,3);
plot(t,pwm);
xlabel('Time ----->');
ylabel('Amplitude ----->');
title('PWM Signal');
axis([0 1 0 2]);
grid on;


Output:

Enter the frequency of carrier signal (sawtooth) = 10
Enter the frequency of message signal (sine) = 1
Enter the amplitude of carrier signal = 5
Enter the amplitude of message signal(should be < Carrier) = 4 


Output Waveforms:

Tuesday 13 November 2012

Comparison of M-ary PSK and M-ary QAM (Matlab 2012a)

Program:

 clc;

clear all;
n = input('Enter the number of values to be compared = ');
for i = 1:n;
    m = 2^i;
    r = (3/(m-1))/(2*(sin(pi/m))^2);
    rm = 10*log10(r);
    if(m==4)
        disp('QAM & PSK have comparable performance by = ');
    else
        disp('SNR of QAM is better than PSK by = ');
    end
    disp(rm);
end

Output:


Enter the number of values to be compared = 5

SNR of QAM is better than PSK by =
    1.7609

QAM & PSK have comparable performance by =

   9.6433e-16

SNR of QAM is better than PSK by =

    1.6531

SNR of QAM is better than PSK by =

    4.1953

SNR of QAM is better than PSK by =

    7.0213

Sampling Theorem Proof (Matlab 2012a)

Program:

clc;

clear all;
t = 0:0.001:1;
fm = input('Enter the modulating signal frequency = ');
x = sin(2*pi*fm*t);
subplot(4,2,1);
plot(t,x);
xlabel('Time ----->');
ylabel('Amplitude ----->');
title('Message Signal');
fs1 = input('Enter Sampling Frequency < Modulating Signal Frequency = ');
fs2 = input('Enter Sampling Frequency = Modulating Signal Frequency = ');
fs3 = input('Enter Sampling Frequency > Modulating Signal Frequency = ');
%Sampling at fs<<2fm
n = 0:1/fs1:1;
x1 = sin(2*pi*fm*n);
subplot(4,2,2);
stem(n,x1);
xlabel('Time ----->');
ylabel('Amplitude ----->');
title('Undersampled fs<<2fm Signal');
subplot(4,2,3);
plot(n,x1);
xlabel('Time ----->');
ylabel('Amplitude ----->');
title('Reconstructed Undersampled fs<<2fm Signal');
%Sampling at fs=2fm
n = 0:1/fs2:1;
x2 = sin(2*pi*fm*n);
subplot(4,2,4);
stem(n,x2);
xlabel('Time ----->');
ylabel('Amplitude ----->');
title('Sampled at Nyquist Rate fs=2fm Signal');
subplot(4,2,5);
plot(n,x2);
xlabel('Time ----->');
ylabel('Amplitude ----->');
title('Reconstructed Nyquist Rate fs=2fm Signal');
%Sampling at fs>>2fm
n = 0:1/fs3:1;
x3 = sin(2*pi*fm*n);
subplot(4,2,6);
stem(n,x3);
xlabel('Time ----->');
ylabel('Amplitude ----->');
title('Oversampled fs>>2fm Signal');
subplot(4,2,7);
plot(n,x3);
xlabel('Time ----->');
ylabel('Amplitude ----->');
title('Reconstructed Oversampled fs>>2fm Signal');

Output:


Enter the modulating signal frequency = 15

Enter Sampling Frequency < Modulating Signal Frequency = 10
Enter Sampling Frequency = Modulating Signal Frequency = 30
Enter Sampling Frequency > Modulating Signal Frequency = 500

Output Waveforms:


Friday 9 November 2012

QPSK (Matlab 2012a)

Program:

clear;
clc;
b = input('Enter the bit stream = ');
n = length(b);
t = 0:0.01:n;
x = 1:1:(n+2)*100;
for i = 1:n
if (b(i) == 0)
u(i) = -1;
else
u(i) = 1;
end
for j = i:0.1:i+1
bw(x(i*100:(i+1)*100)) = u(i);
if (mod(i,2) == 0)
bw_e(x(i*100:(i+1)*100)) = u(i);
bw_e(x((i+1)*100:(i+2)*100)) = u(i);
else
bw_o(x(i*100:(i+1)*100)) = u(i);
bw_o(x((i+1)*100:(i+2)*100)) = u(i);
end
if (mod(n,2)~= 0)
bw_e(x(n*100:(n+1)*100)) = -1;
bw_e(x((n+1)*100:(n+2)*100)) = -1;
end
end
end
bw = bw(100:end);
bw_o = bw_o(100:(n+1)*100);
bw_e = bw_e(200:(n+2)*100);
cost = cos(2*pi*t);
sint = sin(2*pi*t);
x = bw_o.*cost;
y = bw_e.*sint;
z = x+y;
subplot(3,2,1);
plot(t,bw);
xlabel('n ---->');
ylabel('Amplitude ---->');
title('Input Bit Stream');
grid on ;
axis([0 n -2 +2]);
subplot(3,2,5);
plot(t,bw_o);
xlabel('n ---->');
ylabel('Amplitude ---->');
title('Odd Sequence');
grid on ;
axis([0 n -2 +2]);
subplot(3,2,3);
plot(t,bw_e);
xlabel('n ---->');
ylabel('Amplitude ---->');
title('Even Sequence');
grid on ;
axis([0 n -2 +2]);
subplot(3,2,4);
plot(t,x);
xlabel('Time ---->');
ylabel('Amplitude ---->');
title('Odd Sequence BPSK Modulated Wave');
grid on ;
axis([0 n -2 +2]);
subplot(3,2,2);
plot(t,y);
xlabel('Time ---->');
ylabel('Amplitude ---->');
title('Even Sequence BPSK Modulated Wave');
grid on ;
axis([0 n -2 +2]);
subplot(3,2,6);
plot(t,z);
xlabel('Time ---->');
ylabel('Amplitude ---->');
title('QPSK Modulated Wave');
grid on ;
axis([0 n -2 +2]);



Output:

Enter the bit stream = [0 1 1 0 1 0 0 0]


Output Waveforms:

BFSK (Matlab 2012a)

Program:

clc;
clear all;
b = input('Enter the bit stream = ');
n = length(b);
t = 0:0.01:n;
x = 1:1:(n+1)*100;
for i = 1:n
if (b(i) == 0)
u(i) = -1;
else
u(i) = 1;
end
for j = i:0.1:i+1
bw(x(i*100:(i+1)*100)) = u(i);
end
end
bw = bw(100:end);
wo = 2*(2*pi*t);
W = 1*(2*pi*t);
sinHt = sin(wo+W);
sinLt = sin(wo-W);
st = sin(wo+(bw).*W);
subplot(4,1,1);
plot(t,bw);
xlabel('n ---->');
ylabel('Amplitude ---->');
title('Input Bit Stream');
grid on ;
axis([0 n -2 +2]);
subplot(4,1,2);
plot(t,sinHt);
xlabel('Time ---->');
ylabel('Amplitude ---->');
title('Carrier Wave 1');
grid on ;
axis([0 n -2 +2]);
subplot(4,1,3);
plot(t,sinLt);
xlabel('Time ---->');
ylabel('Amplitude ---->');
title('Carrier Wave 2');
grid on ;
axis([0 n -2 +2]);
subplot(4,1,4);
plot(t,st);
xlabel('Time ---->');
ylabel('Amplitude ---->');
title('BFSK Wave');
grid on ;
axis([0 n -2 +2]);


Output:

Enter the bit stream = [0 1 1 0 1 0 0 0]

Output Waveform:

 

BPSK (Matlab 2012a)

Program:

clc;
clear all;
b = input('Enter the bit stream = ');
n = length(b);
t = 0:0.01:n;
x = 1:1:(n+1)*100;
for i = 1:n
if (b(i)== 0)
u(i)= -1;
else
u(i)=1;
end
for j = i:0.1:i+1
bw(x(i*100:(i+1)*100)) = u(i);
end
end
bw = bw(100:end);
sint = sin(2*pi*t);
st = bw.*sint;
subplot(3,1,1);
plot(t,bw);
xlabel('n ---->');
ylabel('Amplitude ---->');
title('Input Bit Stream');
grid on ;
axis([0 n -2 +2]);
subplot(3,1,2);
plot(t,sint);
xlabel('Time ---->');
ylabel('Amplitude ---->');
title('Carrier Wave');
grid on ;
axis([0 n -2 +2]);
subplot(3,1,3);
plot(t,st);
xlabel('Time ---->');
ylabel('Amplitude ---->');
title('BPSK Wave');
grid on ;
axis([0 n -2 +2]);


Output:

Enter the bit stream = [0 1 1 0 1 0 0 0] 

Output Waveforms:

 

ASK (Matlab 2012a)

Program:

clc;
clear all;
b = input('Enter the Bit stream = ');
n = length(b);
t = 0:0.01:n;
x = 1:1:(n+1)*100;
for i = 1:n
for j = i:0.1:i+1
bw(x(i*100:(i+1)*100)) = b(i);
end
end
bw = bw(100:end);
sint = sin(2*pi*t);
st = bw.*sint;
subplot(3,1,1);
plot(t,bw);
xlabel('n ---->');
ylabel('Amplitude ---->');
title('Input Bit Stream');
grid on ;
axis([0 n -2 +2]);
subplot(3,1,2);
plot(t,sint);
xlabel('Time ---->');
ylabel('Amplitude ---->');
title('Carrier Wave');
grid on ;
axis([0 n -2 +2]);
subplot(3,1,3);
plot(t,st);
xlabel('Time ---->');
ylabel('Amplitude ---->');
title('ASK Wave');
grid on ;
axis([0 n -2 +2]);


Output:

Enter the Bit stream = [0 1 1 0 1 0 0 0]

Output Waveforms:

 

DSBSC (Matlab 2012a)

Program:

clc;
clear all;
vm = input('Enter the message signal amplitude = ');
vc = input('Enter the carrier signal amplitude = ');
fm = input('Enter the message frequency = ');
fc = input('Enter the carrier frequency = ');
m = vm/vc;
t = 0:0.001:1;
sm = vm*sin(2*pi*fm*t);
subplot(3,1,1);
plot(t,sm);
xlabel('Time ---->');
ylabel('Amplitude ---->');
title('Message Signal ---->');
grid on;
sc = sin(2*pi*fc*t);
subplot(3,1,2);
plot(t,sc);
xlabel('Time ---->');
ylabel('Amplitude ---->');
title('Carrier Signal ---->');
grid on;
y = vc*m.*sin(2*pi*fm*t).*sin(2*pi*fc*t);
subplot(3,1,3);
plot(t,y);
xlabel('Time ---->');
ylabel('Amplitude ---->');
title('DSBSC Wave ---->');
grid on;


Output:

Enter the message signal amplitude = 5
Enter the carrier signal amplitude = 10
Enter the message frequency = 10
Enter the carrier frequency = 100


Output Waveform:




Phase Modulation (Matlab 2012a)

Program:

clc;

clear all;
t = 0:0.001:1;
vm = input('Enter the amplitude of message signal = ');
vc = input('Enter the amplitude of carrier signal = ');
fm = input('Enter the message frequency = ');
fc = input('Enter the carrier frequency = ');
m = input('Enter modulation index = ');
sm = vm*sin(2*pi*fm*t);
subplot(3,1,1);
plot(t,sm);
xlabel('Time ---->');
ylabel('Amplitude ---->');
title('Message Signal');
grid on;
sc = vc*sin(2*pi*fc*t);
subplot(3,1,2);
plot(t,sc);
xlabel('Time ---->');
ylabel('Amplitude ---->');
title('Carrier Signal');
grid on;
y = vc*sin(2*pi*fc*t+m.*sin(2*pi*fm*t));
subplot(3,1,3);
plot(t,y);
xlabel('Time ---->');
ylabel('Amplitude ---->');
title('PM Wave');
grid on;

Output:


Enter the amplitude of message signal = 5

Enter the amplitude of carrier signal = 5
Enter the message frequency = 10
Enter the carrier frequency = 100
Enter modulation index = 4

Output Waveforms:



Frequency Modulation (Matlab 2012a)

Program:

clc;
clear all;
t = 0:0.001:1;
vm = input('Enter the amplitude of message signal = ');
vc = input('Enter the amplitude of carrier signal = ');
fm = input('Enter the message frequency = ');
fc = input('Enter the carrier frequency = ');
m = input('Enter modulation index = ');
sm = vm*sin(2*pi*fm*t);
subplot(3,1,1);
plot(t,sm);
xlabel('Time ---->');
ylabel('Amplitude ---->');
title('Message Signal');
grid on;
sc = vc*sin(2*pi*fc*t);
subplot(3,1,2);
plot(t,sc);
xlabel('Time ---->');
ylabel('Amplitude ---->');
title('Carrier Signal');
grid on;
y = vc*sin(2*pi*fc*t+m.*cos(2*pi*fm*t));
subplot(3,1,3);
plot(t,y);
xlabel('Time ---->');
ylabel('Amplitude ---->');
title('FM Signal');
grid on;


Output:

Enter the amplitude of message signal = 5
Enter the amplitude of carrier signal = 5
Enter the message frequency = 10
Enter the carrier frequency = 100
Enter modulation index = 4


Output Waveform:

 

Amplitude Modulation (Matlab 2012a)

Program:

clc;
clear all;
t = 0:0.001:1;
vm = input('Enter the amplitude of message signal = ');
vc = input('Enter the amplitude of carrier signal = ');
fm = input('Enter the message frequency = ');
fc = input('Enter the carrier frequency = ');
m = vm/vc;
sm = vm.*sin(2*pi*fm*t);
subplot(3,1,1);
plot(t,sm);
xlabel('Time ---->');
ylabel('Amplitude ---->');
title('Message Signal');
grid on;
sc = vc.*sin(2*pi*fc*t);
subplot(3,1,2);
plot(t,sc);
xlabel('Time ---->');
ylabel('Amplitude ---->');
title('Carrier Signal');
grid on;
y = (vm+m*vm.*sin(2*pi*fm*t)).*sin(2*pi*fc*t);
subplot(3,1,3);
plot(t,y);
xlabel('Time ---->');
ylabel('Amplitude ---->');
title('AM Signal');
grid on;


Output:

Enter the amplitude of message signal = 5
Enter the amplitude of carrier signal = 10
Enter the message frequency = 10
Enter the carrier frequency = 100

Output Waveforms:


Error Probability Curve of M-ary PAM (Matlab 2012a)

Program:

clc;
clear all;
n = input('Enter the number of values to be compared = ');
colour = ['k', 'g', 'r', 'b', 'y'];
nsample = 1;
m = 4;
for i = 1:n
    eb_db = 0:0.0001:25;
    k = log2(m);
    es_db = eb_db + 10*log(k) + 10*log(nsample);
    es = db2mag(es_db);
    z = sqrt(6*es/(m*(m-1)));
    p = 2*((m-1)/m)*qfunc(z);
    semilogy(eb_db,p,colour(k));
    hold on;
    m = m*2;
end
xlabel('SNR ----->');
ylabel('Probability of Error ----->');
title('Error Probability Curve of M ary PAM');
grid on;
legend('m = 4','m = 8', 'm = 16', 'm = 32');


Output:

Enter the number of values to be compared = 3

Output Graph:


Comparison of Error Probability Curve of M-ary PSK & M-ary PAM (Matlab 2012a)

Program
clc;
clear all;
m = input('Enter the value of m = ');
eb_no = 0:0.001:25;
k = log2(m);
nsample = 1;
es_db = eb_no + 10*log(k) + 10*log(nsample);
es = db2mag(es_db);
z = sqrt(6*es/(m*(m-1)));
p_pam = 2*((m-1)/m)*qfunc(z);
semilogy(eb_no,p_pam,'g');
hold on;
p_mpsk = 2*qfunc(sqrt(2*es)).*sin(pi/m);
semilogy(eb_no,p_mpsk,'r');
xlabel('SNR ----->');
ylabel('Probability of Error ----->');
title('Comparison of Probability of error of MPAM & MPSK');
grid on;
legend('MPSK','MPAM');


Output:

Enter the value of m = 4

OutputGraph: