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:
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: