You are on page 1of 19

EXPERIMENT 1

Date: 04/01/2024
AIM:
Implement and simulate the various modulation schemes and analyze their performance.
THEORY:
Digital modulation schemes are techniques used to encode digital data onto an analog carrier
signal for transmission over communication channels. These schemes are essential in modern
communication systems, enabling efficient utilization of bandwidth and robust transmission of
data. Various digital modulation schemes differ in how they encode digital information onto the
carrier signal, each with its own advantages and disadvantages in terms of bandwidth efficiency,
power efficiency, and susceptibility to noise and interference. Here, we'll discuss some
commonly used digital modulation schemes and analyze their performance characteristics:
Amplitude Modulation (AM) is a modulation technique where the amplitude of a carrier signal
is varied in accordance with the amplitude of a modulating signal (message signal).
Frequency Modulation (FM) is a modulation technique where the frequency of a carrier signal is
varied in accordance with the amplitude of a modulating signal (message signal).
Frequency Shift Keying (FSK) is a digital modulation technique where the frequency of the
carrier signal is varied to represent digital data. In FSK modulation, different frequencies
represent different symbols.
Phase Shift Keying (PSK) is a digital modulation technique where the phase of the carrier signal
is varied to represent digital data. In PSK modulation, different phase shifts represent different
symbols.
CODE:

 FSK Modulation and Demodulation

clc;
clear all;

bitStream=[0 1 0 1 0 0];%defining a bit stream


length_bitStream=length(bitStream);
if (bitStream(length_bitStream)==1)
bitStream(length_bitStream+1)=1;
else
bitStream(length_bitStream+1)=0;
end
Amplitude=5;
time=0:0.001:1;
frequency_carrier1=30;
1
frequency_carrier2=60;
carrier1=Amplitude*sin(2*pi*frequency_carrier1*time);
carrier2=Amplitude*sin(2*pi*frequency_carrier2*time);
%FSK Modulation Part
for i=1:length_bitStream
for j=(i-1)*100:(i*100)
if bitStream(i)==1
y(j+1)=carrier1(j+1);
else
y(j+1)=carrier2(j+1);
end
end
end

for i=1:length_bitStream
for j=(i-1)*100:i*100
if bitStream(i)==1
g(j+1)=carrier1(j+1)./carrier1(j+1);
else
g(j+1)=0;
end
end
end
%FSK Plotting
subplot(5,1,1)
stairs(bitStream)
axis([1 7 -1 1])
title('Given Sequence U21EC109');
subplot(5,1,2)
plot(time,carrier1)
title('Carrier Signal of Frequencey 30');
subplot(5,1,3)
plot(time,carrier2)
title('Carrier Signal of Frequencey 60');
subplot(5,1,4)
plot(y)
title('FSK Modulation U21EC109');
axis([0 600 -6 6])
subplot(5,1,5)
plot(g)
title('FSK Demodulation U21EC109')

2
AM Modulation and Demodulation

clc;
clear all;
close all;
f = 1;
Fc = 10;
Fs = 100;
t = 0:1/Fs:5;
s = sin(2*pi*f*t); % Original signal
c = sin(2*pi*Fc*t);

subplot(4,1,1)
plot(t,s);
xlabel('time')
ylabel('amplitude')
title('original signal');
subplot(4,1,2)
plot(t,c);
xlabel('time')
ylabel('amplitude')
title('carrier signal');
y1 = ammod(s,Fc,Fs); % Modulate.
d1 = amdemod(y1,Fc,Fs); % Demodulate.
subplot(4,1,3)
plot(t,y1);
xlabel('time')
ylabel('amplitude')
title('AM modulated U21EC109')
subplot(4,1,4)
plot(t,d1);
xlabel('time')
ylabel('amplitude')
title('AM demodulated U21EC109')
figure;

3
 Frequency Modulation and Demodulation

clc
close all;

Fs2 = 1000; % Sampling rate of signal


Fc2 = 100; % Carrier frequency
dev = 50; % Frequency deviation in modulated signal

% Define time vector


t = 0:1/Fs2:1; % Assuming duration of 1 second

% Generate original signal


s = sin(2*pi*5*t); % Example: 50 Hz sinusoidal signal

% Generate carrier signal


c = sin(2*pi*Fc2*t); % Example: 100 Hz carrier signal

y = fmmod(s, Fc2, Fs2, dev); % Modulate the signal


z = fmdemod(y, Fc2, Fs2, dev); % Demodulate the modulated signal

subplot(4,1,1)
plot(t, s);
xlabel('Time')
ylabel('Amplitude')
title('Original Signal U21EC109')

subplot(4,1,2)
plot(t, c);
xlabel('Time')
ylabel('Amplitude')
title('Carrier Signal U21EC109')

subplot(4,1,3)
plot(t, y)
xlabel('Time')
ylabel('Amplitude')
title('Modulated FM Signal U21EC109')

subplot(4,1,4);
plot(t, z)
xlabel('Time')
ylabel('Amplitude')
title('Demodulated FM Signal U21EC109')

4
 PSK Modulation and Demodulation

clc;
clear all;
close all;
x=[ 1 0 0 1 1 0 1]; % Binary Information
bp=.000001; % bit period
disp(' Binary information at Trans mitter :');
disp(x);

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');
xlabel(' time');
title('Original Signal U21EC109');

A=5; % Amplitude of carrier signal


br=1/bp; % bit rate
f=br*2; % carrier frequency
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*f*t2);
else
y=A*cos(2*pi*f*t2+pi);
end
m=[m y];
end
t3=bp/99:bp/99:bp*length(x);
subplot(3,1,2);
plot(t3,m);
xlabel('time');
ylabel('amplitude');
title('Modulated Signal U21EC109');
mn=[];
for n=ss:ss:length(m)
t=bp/99:bp/99:bp;
y=cos(2*pi*f*t);
mm=y.*m((n-(ss-1)):n);
t4=bp/99:bp/99:bp;
z=trapz(t4,mm)
zz=round((2*z/bp))
5
if(zz>0)

a=1;
else
a=0;
end
mn=[mn a];
end
disp(' Binary information at Reciver :');
disp(mn);

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');
xlabel(' time');
title('Demodulated Signal U21EC109');

CONCLUSION:

6
7
Date: 09/01/2024
AIM

8
EXPERIMENT 2
AIM: Implement and simulate the M-PSK modulation technique with OFDM on an AWGN
channel with the help of MATLAB where M=2,4,16.Plot BER vs SNR.
THEORY
M-PSK Modulation:

M-PSK (M-Phase Shift Keying) is a digital modulation scheme where the phase of the carrier
signal is varied to represent different symbols. In M-PSK modulation, the carrier signal is
divided into M equidistant phase states, each representing a unique symbol. For example, in 4-
PSK, there are four phase states (0°, 90°, 180°, and 270°) representing four symbols.

Orthogonal Frequency Division Multiplexing (OFDM):

OFDM is a modulation technique used in digital communication systems to transmit data over a
wide bandwidth efficiently. It divides the available spectrum into multiple orthogonal
subcarriers, each carrying a narrowband signal. By spacing the subcarriers at precise intervals,
OFDM can mitigate inter-symbol interference (ISI) and frequency-selective fading.

AWGN (Additive White Gaussian Noise):


AWGN is a type of noise commonly encountered in communication systems. It represents
background noise in the channel, which is assumed to be additive, white (uniform across all
frequencies), and Gaussian (following a normal distribution). AWGN is often used to simulate the
effects of thermal noise and other sources of interference in communication channels.
CODE:

clc;
close all;

E = -10:2:10;
N = 1;
SNRdb = E/N;
i = 1000;
subc = 256;
modulation_orders = [2,4,16]; % modualtion order
num_modulations = length(modulation_orders);
BER = zeros(num_modulations, length(SNRdb)); % BER matrix
% Plot colors for different M values

colors = {'b', 'g', 'r'};


figure;
for mod_index = 1:num_modulations
M = modulation_orders(mod_index);
for n = 1:i
B = randi([0 1], 1, subc * log2(M));
9
R = reshape(B, log2(M), subc);
T = R';
d = bi2de(T);
D = d';
Y = pskmod(D, M);
A = sqrt(N/2) * (randn(1, subc) + 1j * randn(1, subc));
for m = 1:length(SNRdb)
SNR = 10^(SNRdb(m)/10);
scl = Y * sqrt(SNR);
inverse = sqrt(subc) * ifft(scl);
signal = inverse + A;
reverse = sqrt(1/subc) * fft(signal);
demodulation = pskdemod(reverse, M);
D2 = demodulation';
d2 = de2bi(D2);
T2 = d2';
% Adjust the reshaping based on modulation order
if log2(M) == 1
R2 = T2;
else
R2 = reshape(T2, 1, []);
end
bit_errors = sum(B ~= R2);
BER(mod_index, m) = BER(mod_index, m) + bit_errors;
end
end
BER(mod_index, :) = BER(mod_index, :) / (i * subc * log2(M));
semilogy(SNRdb, BER(mod_index, :),'-o', 'Color', colors{mod_index}, 'DisplayName', sprintf('M=%d', M));
hold on;
end
hold off;
grid on;
xlabel('SNR (dB)');
ylabel('Bit Error Rate (BER)');
title('SNR vs BER for Different Modulation Orders U21EC109');
legend('show');

CONCLUSION:

10
EXPERIMENT 3
Date: 16/01/2024
AIM
Implement and simulate the M-PSK modulation technique with OFDM on a single-tap Rayleigh
fading channel with AWGN where M=2,4,16.Plot BER vs SNR.
THEORY

M-PSK Modulation:
M-PSK (M-Phase Shift Keying) is a digital modulation technique where the phase of the carrier
signal is modulated to represent digital symbols. In M-PSK, the carrier signal is divided into M
equidistant phase states, each representing a unique symbol. For example, in 4-PSK, there are
four phase states (0°, 90°, 180°, and 270°) representing four symbols.

Orthogonal Frequency Division Multiplexing (OFDM):


OFDM is a modulation technique used in digital communication systems to transmit data over a
wide bandwidth efficiently. It divides the available spectrum into multiple orthogonal
subcarriers, each carrying a narrowband signal. OFDM is particularly robust against frequency-
selective fading and can efficiently mitigate the effects of multipath propagation.

Single-Tap Rayleigh Fading Channel:


A single-tap Rayleigh fading channel is a commonly used model to simulate wireless
communication channels. It models the random variations in signal strength and phase caused
by multipath propagation, where the received signal experiences constructive and destructive
interference. In Rayleigh fading, the magnitude of the channel response follows a Rayleigh
distribution, and the phase is uniformly distributed.

AWGN (Additive White Gaussian Noise):


AWGN is a type of noise commonly encountered in communication systems. It represents
background noise in the channel, which is assumed to be additive, white (uniform across all
frequencies), and Gaussian (following a normal distribution). AWGN is often used to simulate
the effects of thermal noise and other sources of interference in communication channels.

11
CODE:

clc;
close all;

E = -10:2:10;
N = 1;
SNRdb = E/N;
i = 1000;
subc = 256;
no_taps = 1;

modulation_orders = [2, 4, 16];


num_modulations = length(modulation_orders);

BER = zeros(num_modulations, length(SNRdb));

% Plot colors for different M values


colors = {'b', 'g', 'r'};
figure;
tic;
for mod_index = 1:num_modulations %Loop for different values of M
M = modulation_orders(mod_index);%giving value of M one by one

for n = 1:i %no. of iterations


h = sqrt(1/2)*(randn(1,no_taps) + 1j*randn(1,no_taps));
B = randi([0 1], 1, subc * log2(M)); %Bit generation of size = subc*log2(M)
R = reshape(B, log2(M), subc); %Bit vector to matrix reshape
T = R'; % transpose
d = bi2de(T); %binary to decimal conversion of matrix
D = d'; %transpose
Y = pskmod(D, M); %PSK Modulation
A = sqrt(N/2) * (randn(1, subc) + 1j * randn(1, subc)); %AWGN Noise generation

for m = 1:length(SNRdb) %for all values of SNR


SNR = 10^(SNRdb(m)/10); %Converting SNR to radians from dB
scl = Y * sqrt(SNR); %Scaling the modulation values for SNR Values
inverse = sqrt(subc) * ifft(scl); %Inverse fourier transform to add noise to signals
signal = inverse.*h + A; %addition of noise
reverse = sqrt(1/subc) * fft(signal); %Fourier transform after adding noise
deno = abs(h)^2;
num = h;
term = num'/deno;
eq_output = reverse.*term;
demodulation = pskdemod(eq_output, M); %PSK Demodulation at receiver side
D2 = demodulation'; %transpose of demodulation signal
d2 = de2bi(D2); %converting decimal to binary for decoding
T2 = d2'; %Taking transpose

% Adjust the reshaping based on modulation order


if log2(M) == 1
R2 = T2;
else
R2 = reshape(T2, 1, []);
end

12
bit_errors = sum(B ~= R2); %calculating error in bits recieved
BER(mod_index, m) = BER(mod_index, m) + bit_errors; %updating number of bit errors
end
end
BER(mod_index, :) = BER(mod_index, :) / (i * subc * log2(M)); %Normalizing BER in all elements present in row

% Plot SNR vs BER for the current modulation order on the same figure
semilogy(SNRdb, BER(mod_index, :), '-o', 'Color', colors{mod_index}, 'DisplayName', sprintf('M=%d', M));
hold on;
end
toc
hold on;
grid on;
xlabel('SNR (dB)');
ylabel('Bit Error Rate (BER)');
title('SNR vs BER for M=2,4,16 U21EC109');
legend('show');

CONCLUSION:

13
EXPERIMENT 4
Date: 23/01/2024
AIM
Implement and simulate the M-PSK modulation technique with OFDM on a single-tap Rician
fading channel with AWGN where M=2,4,16 for different values of the Rician k factor.Plot BER
vs SNR.
THEORY
Combining efficient M-PSK modulation (e.g., QPSK) with OFDM, we can send data over a
single-tap Rician fading channel (combining line-of-sight and scattered paths) with AWGN.
The modulated data spreads across multiple subcarriers, mitigating Rician fading's impact, but
higher-order M-PSK trades noise tolerance for spectral efficiency. We simulate this by
generating data, modulating it, transmitting through the modeled channel with noise, then
demodulating and comparing recovered data to evaluate performance (e.g., BER/SER) under
different scenarios. Remember, this theoretical foundation needs adjustments for real-world
complexities like imperfect channel estimation and synchronization errors.

CODE:
1) For Different K values
clc;
clear all;

figure;

E = -10:2:10;
N = 1;
SNRdb = E/N;
i = 1000;
subc = 256;

modulation_orders = 2;
z = [1 2 4];
num_modulations = length(z);

BER = zeros(num_modulations,length(SNRdb));

colors = {'b','g','r'};

for mod_index = 1:num_modulations


M = 2;
k = z(mod_index);
for n = 1:i
B = randi([0 1],1,subc*log2(M));
R = reshape(B,log2(M),subc);
T = R';

14
d = bi2de(T);
D = d';
t = 1;
Y = pskmod(D,M);
noise = sqrt(N/2)*(randn(1,subc)+1j*randn(1,subc));
V = sqrt(2*k);
h_amp = (randn(1,t) + 1i*randn(1,t)) / sqrt(2) + V ;
h_mag = abs(h_amp);
theta = rand(1,t)*2*pi;
fadingChannel = h_mag.*(cos(theta) + 1i*sin(theta));
for m = 1:length(SNRdb)
SNR = 10^(SNRdb(m)/10);
scl = Y* sqrt(SNR);
inverse = sqrt(subc)*ifft(scl);
signal = inverse.*fadingChannel + noise;
reverse = sqrt(1/subc)*fft(signal);
for in = 1:t
reverse= reverse.*fadingChannel(in)*(1/(fadingChannel*fadingChannel));
end
demodulation = pskdemod(reverse,M);
D2 = demodulation;
d2 = de2bi(D2);
T2 = d2';

if log2(M) == 1
R2 = T2;
else
R2 = reshape(T2,1,[]);
end

bit_errors = sum(B~=R2);
BER(mod_index,m) = BER(mod_index,m) + bit_errors;
end
end
BER(mod_index, :) = BER(mod_index, :) /(i* subc*log2(M));

semilogy(SNRdb, BER(mod_index,:),'-o','Color',colors{mod_index},'DisplayName',sprintf('K=%d',k));
hold on;
end

hold off;
grid on;
xlabel('SNR(dB)');
ylabel('Bit Error Rate(BER)');
title('SNR vs BER for Different K U21EC109');
legend('show');

15
2) With Different modulation orders

clc;
clear all;
figure;
E = -10:2:10;
N = 1;
SNRdb = E/N;
i = 1000;
subc = 256;

modulation_orders = [2,4,16];
num_modulations = length(modulation_orders);

BER = zeros(num_modulations,length(SNRdb));

colors = {'b','g','r'};

for mod_index = 1:num_modulations


M = modulation_orders(mod_index);

for n = 1:i
B = randi([0 1],1,subc*log2(M));
R = reshape(B,log2(M),subc);
T = R';
d = bi2de(T);
D = d';
t = 1;
k = 4;
Y = pskmod(D,M);
noise = sqrt(N/2)*(randn(1,subc)+1j*randn(1,subc));
V = sqrt(2*k);
h_amp = (randn(1,t) + 1i*randn(1,t)) / sqrt(2) + V ;
h_mag = abs(h_amp);
theta = rand(1,t)*2*pi;
fadingChannel = h_mag.*(cos(theta) + 1i*sin(theta));
for m = 1:length(SNRdb)
SNR = 10^(SNRdb(m)/10);
scl = Y* sqrt(SNR);
inverse = sqrt(subc)*ifft(scl);
signal = inverse.*fadingChannel + noise;
reverse = sqrt(1/subc)*fft(signal);
for in = 1:t
reverse = reverse.*fadingChannel(in)*(1/(fadingChannel*fadingChannel));
end
demodulation = pskdemod(reverse,M);
D2 = demodulation;
d2 = de2bi(D2);
T2 = d2';

if log2(M) == 1
R2 = T2;
else
R2 = reshape(T2,1,[]);
end

bit_errors = sum(B~=R2);
16
BER(mod_index,m) = BER(mod_index,m) + bit_errors;
end
end
BER(mod_index, :) = BER(mod_index, :) /(i* subc*log2(M));

semilogy(SNRdb, BER(mod_index,:),'-o','Color',colors{mod_index},'DisplayName',sprintf('M=%d',M));
hold on;
end

hold off;
grid on;
xlabel('SNR(dB)');
ylabel('Bit Error Rate(BER)');
title('SNR vs BER for Different Modulation orders U21EC109');
legend('show');

3) Comparison of AWGN, Rayleigh and Riccian

clc;
close all;

E = -10:2:10;
N = 1;
SNRdb = E/N;
i = 1000;
subc = 256;

modulation_orders = [2];
num_modulations = length(modulation_orders);

BER = zeros(num_modulations,length(SNRdb));
BER_fadding = zeros(num_modulations,length(SNRdb));
BER_fadding1 = zeros(num_modulations,length(SNRdb));
colors = {'b','g','r'};

for mod_index = 1:num_modulations


M = modulation_orders(mod_index);

for n = 1:i
B = randi([0 1],1,subc*log2(M));
R = reshape(B,log2(M),subc);
T = R';
t = 1;
d = bi2de(T);
D = d';
Y = pskmod(D,M);
noise = sqrt(N/2)*(randn(1,subc)+1j*randn(1,subc));
fadingChannel = (randn(1,t)+ 1i * randn(1,t)) / sqrt(2);
k = 1;
V = sqrt(2*k);
h_amp = (randn(1,t) + 1i*randn(1,t)) / sqrt(2) + V ;
h_mag = abs(h_amp);
theta = rand(1,t)*2*pi;
fadingChannel1 = h_mag.*(cos(theta) + 1i*sin(theta));
for m = 1:length(SNRdb)
SNR = 10^(SNRdb(m)/10);
17
scl = Y* sqrt(SNR);
inverse = sqrt(subc)*ifft(scl);
signal2 = inverse.*fadingChannel1 + noise;
signal1 = inverse.*fadingChannel + noise;
signal = inverse + noise;
reverse2 = sqrt(1/subc)*fft(signal2);
reverse = sqrt(1/subc)*fft(signal);
reverse1 = sqrt(1/subc)*fft(signal1);
for in = 1:t
reverse1 = reverse1.*fadingChannel(in)*(1/(fadingChannel*fadingChannel));
reverse2 = reverse2.*fadingChannel1(in)*(1/(fadingChannel1*fadingChannel1));
end
demodulation = pskdemod(reverse,M);
demodulation1 = pskdemod(reverse1,M);
demodulation2 = pskdemod(reverse2,M);
D2 = demodulation;
d2 = de2bi(D2);
d3 = de2bi(demodulation1);
d4 = de2bi(demodulation2);
T2 = d2';
T3 = d3';
T4 = d4';
if log2(M) == 1
R2 = T2;
R3 = T3;
R4 = T4;
else
R2 = reshape(T2,1,[]);
R3 = reshape(T3,1,[]);
R4 = reshape(T4,1,[]);
end

bit_errors = sum(B~=R2);
bit_errors_fadding = sum(B~=R3);
bit_errors_fadding1 = sum(B~=R4);
BER(mod_index,m) = BER(mod_index,m) + bit_errors;
BER_fadding(mod_index,m) = BER_fadding(mod_index,m) + bit_errors_fadding;
BER_fadding1(mod_index,m) = BER_fadding1(mod_index,m) + bit_errors_fadding1;
end
end
BER(mod_index, :) = BER(mod_index, :) /(i* subc*log2(M));
BER_fadding(mod_index, :) = BER_fadding(mod_index, :) /(i* subc*log2(M));
BER_fadding1(mod_index, :) = BER_fadding1(mod_index, :) /(i* subc*log2(M));

semilogy(SNRdb, BER(mod_index,:),'-o','Color',colors{mod_index},'DisplayName',sprintf('With AWGN'));


hold on;
semilogy(SNRdb, BER_fadding(mod_index,:),'-o','Color',colors{mod_index+1},'DisplayName',sprintf('With AWGN
and raleigh fadding'));
hold on;
semilogy(SNRdb, BER_fadding1(mod_index,:),'-o','Color',colors{mod_index+2},'DisplayName',sprintf('With
AWGN and rician fadding'));

end

hold off;
grid on;
xlabel('SNR(dB)');
18
ylabel('Bit Error Rate(BER)');
title('SNR vs BER for Different type of channel');
legend('show');

CONCLUSION:

19

You might also like