Pages

Wednesday, 17 October 2012

Analysis of M ary PSK (Matlab 2012a)

Program:

clc;
clear all;
%Create a random digital message
M = input('Enter alphabet size M = '); %Alphabet Size
k = log2(M);
x = randi([0 1],input('Number of binary bit stream = '),1); %Message Signal
nsample = 1;
%Bit to symbol Mapping
% Convert the bits in x to k bit symbols
xsym = bi2de(reshape(x,k,length(x)/k).','left-msb');
%Stem plot of symbols
% Plot first 10 symbols in a stem plot
subplot(3,2,1);
stem(xsym(1:10),'filled');
title('Input Message Random Symbols (Decimal)');
xlabel('Symbol Index ----->');
ylabel('Integer Value ----->');
grid on;
hold on;
y = modulate(modem.pskmod(M),xsym);%M ary PSK modulation
subplot(3,2,2);
stem(y(1:10),'filled');
title('Modulated Signal');
xlabel('n ---->');
ylabel('Amplitude ---->');
grid on;
hold on;
%Transmitting signal through an AWGN Channel
ynoisy = awgn(y,input('SNR in dB = '),'measured');
%Demodulate ynoisy to recover the message
zsym = demodulate(modem.pskdemod(M),ynoisy);
% Symbol-to-Bit Mapping
% Undo the bit-to-symbol mapping performed earlier
z = de2bi(zsym,'left-msb'); % Convert integers to bits
% Convert z from a matrix to a vector
z = reshape(z.',numel(z),1);
subplot(3,2,3);
stem(x(1:10),'filled');
title('Original Message Sequence (Binary)');
xlabel('n ---->');
ylabel('Amplitude ---->');
grid on;
hold on;
subplot(3,2,4);
stem(zsym(1:10),'filled');
title('Demodulated Message Sequence (Decimal)');
xlabel('n ---->');
ylabel('Amplitude ---->');
grid on;
hold on;
subplot(3,2,5);
stem(z(1:10),'filled');
title('Demodulated Message Sequence (Binary)');
xlabel('n ---->');
ylabel('Amplitude ---->');
grid on;
hold on;
[num,r] = symerr(xsym,zsym);%Calculating symbol error rate
disp('Number of Symbol Errors = ');
disp(num);
disp('Symbol Error Rate = ');
disp(r);
[numbr,ra] = biterr(x,z);%Calculating bit error rate
disp('Number of Bit Errors = ');
disp(numbr);
disp('Bit Error Rate = ');
disp(ra);
h = modem.pskmod(M);% Modulator object
mapping = h.SymbolMapping; % Symbol mapping vector
pt = h.Constellation; % Vector of all points in constellation
% Plot the constellation
scatterplot(pt);

title('Signal Constellation');
% Include text annotations that number the points
text(real(pt)+0.1,imag(pt),dec2bin(mapping));
axis([-2 2 -2 2]); %Change axis so all labels fit in plot


Output:

 
Enter alphabet size M = 16
Number of binary bit stream = 4000
SNR in dB = 10
Number of Symbol Errors =
   393

Symbol Error Rate =
    0.3930

Number of Bit Errors =
   753

Bit Error Rate =
    0.1883


Waveforms:

 

 

Thursday, 11 October 2012

Parity Check (Matlab 2012a)

Program:
clc;
clear all;
b = input('Enter the bit stream = ');
pr = input('Enter the error probability = ');
n = length(b);
c = 0;
for i = 1:n
        if(b(i)==1)
        c = c + 1;
        end
end
if(mod(c,2)~=0)
   b1 = [b ones(1,1)];
else
   b1 = [b zeros(1,1)];
end
l = length(b1);
disp('Input bit stream = ');
disp(b);
disp('Transmitting message sequence including parity bit = ');
disp(b1);
[ncode,err] = bsc(b1,pr);
disp('Received message sequence = ');
disp(ncode);
for i = 1:n
    if(ncode(l)~=b1(l))
        disp('Parity error');
        break;
    end
    if(ncode(i)~=b1(i))
        disp('Transmitted and received sequence does not match');
        break;
    else
        if(i==n)
       disp('Transmitted and received sequence match');
        end
    end
end


Output 1:


Enter the bit stream = [0 1 1 0 1 0]
Enter the error probability = 0.9
Input bit stream =
     0     1     1     0     1     0

Transmitting message sequence including parity bit =
     0     1     1     0     1     0     1

Received message sequence =
     1     0     0     1     1     1     1

Transmitted and received sequence does not match


Output 2:

Enter the bit stream = [0 1 1 0 1 0]
Enter the error probability = 0.7
Input bit stream =
     0     1     1     0     1     0

Transmitting message sequence including parity bit =
     0     1     1     0     1     0     1

Received message sequence =
     1     0     0     0     0     1     0


Parity error


Output 3:

 Enter the bit stream = [0 1 1 0 1 0]
Enter the error probability = 0.1
Input bit stream =
     0     1     1     0     1     0

Transmitting message sequence including parity bit =
     0     1     1     0     1     0     1

Received message sequence =
     0     1     1     0     1     0     1

Transmitted and received sequence match



High Pass Filter - First Order AR Process (Matlab 2012a)

Program:
clc;
clear all;
n = input('Enter the no. of values:');
colr = ['g','b','r','k'];
for i = 1:n
    r = input('Enter the value for r:');
    d0 = 1+(r*r)+ 2*r;
    w1 = 0:0.001:pi;
    d1 = 1+(r*r)-(2*r.*cos(w1));
    ps = d0./d1;
    hold on;
    semilogy(w1,ps,colr(i));
end
xlabel('Frequency(Units of pi)');
ylabel('Power Spectrum');
title('Response of High Pass Filter');
legend('r=.5','r=.75','r=.9');


Output:

 
Enter the no. of values: 3
Enter the value for r: -0.5
Enter the value for r: -0.75
Enter the value for r: -0.9


Output Graph:

 

Low Pass Filter - First Order AR Process (Matlab 2012a)

Program :
clc;
clear all;
n = input('Enter the no. of values:');
colr = ['g','b','r','k'];
for i = 1:n
    r = input('Enter the value for r:');
    d0 = 1+r*r-2*r;
    w1 = 0:0.001:1;
    d1 = 1+(r*r)-(2*r.*cos(w1));
    ps = d0./d1;
    hold on;
    semilogy(w1,ps,colr(i));
end
xlabel('Frequency(Units of pi)');
ylabel('Power Spectrum');
title('Response of Low Pass Filter');
legend('r=.5','r=.75','r=.9');


Output:

 
Enter the no. of values: 3
Enter the value for r: 0.5
Enter the value for r: 0.75
Enter the value for r: 0.9


Output Graph: