Assignment No. 2
Assignment No. 2
2
Communication Systems
Submitted to:
Sir Dr. Engr. Muhammad Saleem
Submitted by:
Name: Muhammad Yaqoob
Reg No: ELEN-201101019
Assignment No.2 (CLO-2)
Question No.1: Analyze the audio file using MATLAB Tool as?
Task 1: Read audio file
Task 2: Quantize audio signal
Task 3: Compute SNR
Private Functions
Answer. Following is the MATLAB Code:
% Private Functions
function quantized_signal = quantize(signal, bits)
% Normalize the signal to the range [-1, 1]
max_value = max(abs(signal));
normalized_signal = signal / max_value;
In this code, replace 'audio.wav' with the actual path to your audio file. Make sure the audio file
is in a format supported by MATLAB (e.g., WAV, MP3).
The code reads the audio file using the audioread function and stores the audio samples in the
audio variable. The sample rate is stored in the fs variable.
Next, the quantize function quantizes the audio signal using a specified number of bits. The
quantization is done by normalizing the signal to the range [-1, 1], quantizing it to the desired
number of levels, and then scaling it back to the original range.
Finally, the code computes the signal-to-noise ratio (SNR) by calculating the power of the
original audio signal and the power of the quantization noise. The SNR is expressed in decibels
(dB) using the formula SNR = 10 * log10(signal_power / noise_power).
Question No.2: Analyze the following topics in term of wireless communication systems:
1. Block chain-based Communication
2. SD Radio for 5G
3. Broadband Communication
Answer.
Wireless Communication Systems Analysis
Blockchain-based Communication
Broadband Communication
Question No.3: A simulation of a complete digital communication system with different modulation
schemes in MATLAB for transmitting and receiving text messages.
Answer. Code:
clc;
clear all;
close all;
x=[0 1 1 0 0 0 1 0]; % Binary Information
bp=.000001; % bit period
disp('Transmitted bit stream :');
disp(x);
% Binary data in digital form
bit=[];
for n=1:1:length(x)
if x(n)==1;
se=ones(1,100);
else x(n)==0;
se=zeros(1,100);
end
bit=[bit se];
end
t1=bp/100:bp/100:100*length(x)*(bp/100);
subplot(3,1,1);
plot(t1,bit,'lineWidth',2.5);grid on;
axis([ 0 bp*length(x) -.5 1.5]);
ylabel('amplitude(volt)');
xlabel(' time(sec)');
title('message in digital');
% Binary-FSK modulation %
A=5; % Amplitude of carrier signal
rb=1/bp; % bit rate
f1=rb*8; % carrier frequency for information as 1
f2=rb*2; % carrier frequency for information as 0
t2=bp/99:bp/99:bp;
ss=length(t2);
m=[];
for (i=1:1:length(x))
if (x(i)==1)
y=A*cos(2*pi*f1*t2);
else
y=A*cos(2*pi*f2*t2);
end
m=[m y];
end
t3=bp/99:bp/99:bp*length(x);
subplot(3,1,2);
plot(t3,m);
xlabel('time(sec)');
ylabel('amplitude(volt)');
title('Binary FSK modulation signal');
% Binary FSK demodulation
mn=[];
for n=ss:ss:length(m)
t=bp/99:bp/99:bp;
y1=cos(2*pi*f1*t); % carrier siignal for information 1
y2=cos(2*pi*f2*t); % carrier siignal for information 0
mm=y1.*m((n-(ss-1)):n);
mmm=y2.*m((n-(ss-1)):n);
t4=bp/99:bp/99:bp;
z1=trapz(t4,mm) % intregation
z2=trapz(t4,mmm) % intregation
zz1=round(2*z1/bp)
zz2= round(2*z2/bp)
if(zz1>A/2) % logic lavel= (0+A)/2 or (A+0)/2 or 2.5 ( in this case)
a=1;
else(zz2>A/2)
a=0;
end
mn=[mn a];
end
disp(' Demodulated data :');
disp(mn);
%XXXXX Representation of binary information as digital signal which achived
%after demodulation
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
bit=[];
for n=1:length(mn);
if mn(n)==1;
se=ones(1,100);
else mn(n)==0;
se=zeros(1,100);
end
bit=[bit se];
end
t4=bp/100:bp/100:100*length(mn)*(bp/100);
subplot(3,1,3)
plot(t4,bit,'LineWidth',2.5);grid on;
axis([ 0 bp*length(mn) -.5 1.5]);
ylabel('amplitude(volt)');
xlabel(' time(sec)');
title('Demod data in digital form');
Output:
Transmitted bit stream : ans = logical 1
0 1 1 0 0 0 1 0
z1 = -4.7142e-08
z1 = -4.7142e-08 z2 = 2.4499e-06
z2 = 2.4499e-06 zz1 = 0
zz1= 0 zz2 = 5
zz2 = 5
ans = logical 1
ans = logical 1
z1 = 2.4555e-06
z2 = -4.7142e-08
zz1 = 5 z1 = 2.4555e-06
zz2 = 0 z2 = -4.7142e-08
z1 = 2.4555e-06 zz1 = 5
z2 = -4.7142e-08 zz2 = 0
zz1 = 5 z1 = -4.7142e-08
zz2 = 0 z2 = 2.4499e-06
z1 = -4.7142e-08 zz1 = 0
z2 = 2.4499e-06 zz2 = 5
zz1 = 0
zz2 = 5 ans = logical 1
Demodulated data :
ans = logical 1 0 1 1 0 0 0 1 0
z1 = -4.7142e-08
z2 = 2.4499e-06
zz1 = 0
zz2 = 5
The File of Matalb is also attached with the Assignment.