Ec-431 - Digitalcommunication: College of E&Me, Nust, Rawalpindi
Ec-431 - Digitalcommunication: College of E&Me, Nust, Rawalpindi
EC-431|DigitalCommunication
LAB N0# 06
Submitted By:
Saleha Bibi
CE 41 A
325226
LAB TASKS
Task 1:
a. Build a GUI in MATLAB as given above. Containing a string box for character, a string box
for respective ASCII code, a string box for binary value and a graph showing the modulated
pulse signal. You should write a character in the box and once you press the Transmit
button the binary of the GUI, ASCII value appears in the respective box, and its respective
binary value is displayed in the binary text box. Moreover, the pulse waveform graph plots
the pulse modulated signal. You may use a pulse width of 0.1 seconds.
b. After that the signal is received at the pulse demodulator. In the pulse waveform box
given below you should plot the received signal. After that the pulse is demodulated
(converted back to binary) and displayed in the binary text box. Finally, the received
character is displayed in the character box.
c. Next you should add some noise on the channel e.g., by flipping a signal pulse. After that
the signal is received at the pulse demodulator. In the pulse waveform box given below
you should plot the received signal with noise. After that the pulse is demodulated
(converted back to binary) and displayed in the binary text box. Finally, the received
character is displayed in the character box.
Code:
classdef trans < matlab.apps.AppBase
binary_input = app.binary_in.Value;
[ascii_input, letter_input] = binary_ascii(app, string(binary_input));
app.ascii_in.Value = string(ascii_input);
app.char_in.Value = letter_input;
reverse(binary_input);
end
end
% Create axes_in
app.axes_in = uiaxes(app.UIFigure); title(app.axes_in,
'Input Waveform') app.axes_in.FontName = 'DejaVu Serif
Condensed';app.axes_in.FontWeight = 'bold';
app.axes_in.XTick = [1 2 3 4 5 6 7 8.9];
app.axes_in.XTickLabel = {'1'; '2'; '3'; '4'; '5'; '6'; '7'; '8'; '9'};
app.axes_in.YTick = [0 0.5 1];
app.axes_in.FontSize = 14;
app.axes_in.Position = [211 221 309 206];
% Create axes_out
app.axes_out = uiaxes(app.UIFigure); title(app.axes_out,
'Transmitted Waveform') app.axes_out.FontName = 'DejaVu
Serif Condensed';app.axes_out.FontWeight = 'bold';
app.axes_out.XTick = [1 2 3 4 5 6 7 8 9];
app.axes_out.XTickLabel = {'1'; '2'; '3'; '4'; '5'; '6'; '7'; '8'; '9'};
app.axes_out.YTick = [0 0.5 1];
app.axes_out.FontSize = 14;
app.axes_out.Position = [211 16 309 206];
% Create char_in
app.char_in = uieditfield(app.UIFigure, 'text');
app.char_in.BackgroundColor = [0.7608 1 0.5686];
app.char_in.Position = [28 304 94 30];
% Create ascii_in
app.ascii_in = uieditfield(app.UIFigure, 'text');
app.ascii_in.BackgroundColor = [0.7608 1 0.5686];
app.ascii_in.Position = [28 241 94 30];
% Create binary_in
app.binary_in = uieditfield(app.UIFigure, 'text');
app.binary_in.BackgroundColor = [0.7569 1 0.5686];
app.binary_in.Position = [29 369 94 30];
% Create CharacterLabel
app.CharacterLabel = uilabel(app.UIFigure);
app.CharacterLabel.HorizontalAlignment = 'center';
app.CharacterLabel.FontName = 'DejaVu Serif Condensed';
app.CharacterLabel.FontSize = 14; app.CharacterLabel.FontWeight =
'bold'; app.CharacterLabel.Position = [38 335 77 22];
app.CharacterLabel.Text = 'Character';
% Create ASCIILabel
app.ASCIILabel = uilabel(app.UIFigure);
app.ASCIILabel.HorizontalAlignment = 'center';
app.ASCIILabel.FontName = 'DejaVu Serif Condensed';
app.ASCIILabel.FontSize = 14; app.ASCIILabel.FontWeight =
'bold'; app.ASCIILabel.Position = [52 272 46 22];
app.ASCIILabel.Text = 'ASCII';
% Create BinaryLabel
app.BinaryLabel = uilabel(app.UIFigure);
app.BinaryLabel.HorizontalAlignment = 'center';
app.BinaryLabel.FontName = 'DejaVu Serif Condensed';
app.BinaryLabel.FontSize = 14; app.BinaryLabel.FontWeight =
'bold'; app.BinaryLabel.Position = [51 400 52 22];
app.BinaryLabel.Text = 'Binary';
% Create char_out
app.char_out = uieditfield(app.UIFigure, 'text'); app.char_out.BackgroundColor =
[0.9882 0.9608 0.5686];
app.char_out.Position = [600 98 94 30];
% Create ascii_out
app.ascii_out = uieditfield(app.UIFigure, 'text'); app.ascii_out.BackgroundColor =
[0.9882 0.9608 0.5686];
app.ascii_out.Position = [600 36 94 32];
% Create binary_out
app.binary_out = uieditfield(app.UIFigure, 'text'); app.binary_out.BackgroundColor =
[0.9882 0.9569 0.5725];
app.binary_out.Position = [600 159 94 30];
% Create ASCIILabel_2
app.ASCIILabel_2 = uilabel(app.UIFigure);
app.ASCIILabel_2.HorizontalAlignment = 'center';
app.ASCIILabel_2.FontName = 'DejaVu Serif Condensed';
app.ASCIILabel_2.FontSize = 14; app.ASCIILabel_2.FontWeight =
'bold'; app.ASCIILabel_2.Position = [624 67 46 32];
app.ASCIILabel_2.Text = 'ASCII';
% Create BinaryLabel_2
app.BinaryLabel_2 = uilabel(app.UIFigure); app.BinaryLabel_2.HorizontalAlignment =
'center'; app.BinaryLabel_2.FontName = 'DejaVu Serif Condensed';
app.BinaryLabel_2.FontSize = 14; app.BinaryLabel_2.FontWeight =
'bold'; app.BinaryLabel_2.Position = [622 190 52 22];
app.BinaryLabel_2.Text = 'Binary';
% Create btn_transmit
app.btn_transmit = uibutton(app.UIFigure, 'push'); app.btn_transmit.ButtonPushedFcn
= createCallbackFcn(app,
@btn_transmitButtonPushed, true);
app.btn_transmit.BackgroundColor = [0.9686 0.6941 0.9804];
app.btn_transmit.FontName = 'DejaVu Serif Condensed';
app.btn_transmit.FontSize = 14; app.btn_transmit.FontWeight =
'bold'; app.btn_transmit.Position = [600 335 94 29];
app.btn_transmit.Text = 'Enter';
% Create InsertBinaryforInputWaveformOnlyLabel
app.InsertBinaryforInputWaveformOnlyLabel = uilabel(app.UIFigure);
app.InsertBinaryforInputWaveformOnlyLabel.FontName = 'DejaVu Serif
Condensed';
app.InsertBinaryforInputWaveformOnlyLabel.FontSize = 18;
app.InsertBinaryforInputWaveformOnlyLabel.Position = [211 439 369 23];
app.InsertBinaryforInputWaveformOnlyLabel.Text = 'Insert Binary for Input
Waveform Only ';
end
end
end
Output:
Task-02:
In the previous task, you have transmitted and received a single character using MATLAB
with additive Gaussian noise. Now, you would transmit numbers from 0000 to 9999 as
characters in the format “zzzz” where z represents a single character for a number. At the end
you will calculate the bit error rate for the received bit.
a. First perform the following steps without considering noise. Transmit the
binary stream for the number 0000. Here you would represent each 0 with its respective
binary representation. Receive the transmitted bits and recover the 0000 being
transmitted. Is here 0000 being correctly received if not find the number of wrong bits?
Save the number of erroneous bits in error count. Now write a loop to from 0000 to
9999 and repeat the procedure. Update the error count in each iteration. Moreover, the
pulse waveform graph plots the pulse modulated signal. You may use a pulse width of 0.1
seconds.
b. Now perform the above steps for noise with variances 0, 0.1, 0.2, 0.3, 0.4, …, 3.Calculate
the Bit error rate (BER) for each variance value by averaging the error _count over all the
numbers from 0000 to 9999. Finally plot the BER with variance on the x-axis and the BER
Code:
Bin = [];
%Converting to 16 bitsfor i=1:4
x = Num(i);
Binary = dec2bin(x);
z = str2double(Binary); len_of_Binary =
length(Binary);Out = [];
if len_of_Binary<4
ending = 4-len_of_Binary;for c =
1:ending
Out = [Out 0];end
if len_of_Binary==1Out = [Out
z];
else
for l = 1:len_of_Binaryo =
Binary(l);
o1 = str2double(o);
Out = [Out o1];
end
end
for l = 1:len_of_Binaryo =
Binary(l);
o1 = str2double(o);
Out = [Out o1];
end
end
Bin = [Bin Out];
end
Num = [];
Bin_new = Bin;
Bin_new = Bin_new + randn(size(Bin_new))*sqrt(var);Bin_new =
round(Bin_new);
for i=1:16
if Bin_new(i)~=Bin(i) error_count =
error_count + 1;end
end
end
Error = [Error error_count];Variance =
[Variance var];
end
disp('Error:')disp(Error)
disp('Varianc)disp(Variance)
BER = Error/10000;
axes(handles.axes1);
plot(Variance,BER); xlabel('Variance
--->');
ylabel('BER --->'); :
Output