0% found this document useful (0 votes)
2 views13 pages

12314

The document contains MATLAB code for various modulation and demodulation techniques including Amplitude Modulation (AM), Frequency Modulation (FM), Phase Modulation (PM), Amplitude Shift Keying (ASK), and Frequency Shift Keying (FSK). Each section includes parameters for signal generation, plotting of message, carrier, modulated, and demodulated signals. The code demonstrates the process of simulating these modulation techniques and visualizing the results.

Uploaded by

aturopov77
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views13 pages

12314

The document contains MATLAB code for various modulation and demodulation techniques including Amplitude Modulation (AM), Frequency Modulation (FM), Phase Modulation (PM), Amplitude Shift Keying (ASK), and Frequency Shift Keying (FSK). Each section includes parameters for signal generation, plotting of message, carrier, modulated, and demodulated signals. The code demonstrates the process of simulating these modulation techniques and visualizing the results.

Uploaded by

aturopov77
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

1-ish

% MATLAB Amplitude Modulation and Demodulation

%% Modulation index
h = 65;
T = 4.4 * pi

%% Time Period of Simulation :


t = linspace(0, 0.2, 100000);

%% Message Signal :
Am = 4.7;
fm = 700;
ym = Am * cos(T * fm * t);

figure;
subplot(4, 1, 1);
plot(t(1:10000), ym(1:10000));
title('Message Signal');
xlabel('time(t)');
ylabel('Amplitude');

%% Carrier Signal :
Ac = Am / h;
fc = 6500;
yc = Ac * cos(T * fc * t);

subplot(4, 1, 2);
plot(t(1:10000), yc(1:10000));
title('Carrier Signal');
xlabel('time(t)');
ylabel('Amplitude');

%% Modulated Signal :
y = ammod(ym, fc, 100000, 0, Ac);
subplot(4, 1, 3);
plot(t(1:10000), y(1:10000));
title('Modulated Signal');
xlabel('time(t)');
ylabel('Amplitude');

%% Demodulated Signal :
z = amdemod(y, fc, 100000, 0, Ac);
subplot(4, 1, 4);
plot(t(1:10000), z(1:10000));
title('Demodulated Signal');
xlabel('time(t)');
ylabel('Amplitude');
ylim([-10, 10]);

2-ish

% Set the paramenters

fs = 5000;
Ac = 2;
Am = 5.7;
T= 8*pi;
fm = 100;
fc = 1000;
h=70;
B = 10;
t = (0:.1*fs)/fs;
wc = T *fc;
wm = T *fm;
m_t = Am*cos(wm*t);
subplot(4,1,1);
plot(t,m_t);
title('Message Signal');
c_t = Ac*cos(wc*t);
subplot(4,1,2);
plot(t,c_t);
title('Carrier Signal');
s_t = Ac*cos((wc*t)+h*sin(wm*t));
subplot(4,1,3);
plot(t,s_t);
title('Frequency Modulated Signal');
d = demod(s_t,fc,fs,'fm');
subplot(4,1,4);
plot(t,d);
title('Demodulated Signal');

3-ish

% Set the paramenters

fs =4000;
T = 4.4 * pi
t = 0:1/fs:T;
fm = 7;
x = sin(2*pi*fm*t); % message signal
fc = 65; % carrier signal frequency
y = cos(2*pi*fc*t); % carrier signal
phasedev = pi/6; % phase deviation
phasemod = pmmod(x,fc,fs,phasedev); % modulated signal
phasedemod = pmdemod(phasemod,fc,fs,phasedev); % demodulated
signal
subplot(4,1,1);
plot(t,x);
title('Message Signal');
subplot(4,1,2);
plot(t,y);
title('Carrier Signal');
subplot(4,1,3);
plot(t,phasemod);
title('Phase Modulated Signal');
subplot(4,1,4);
plot(t,phasedemod);
title('Demodulated Signal');

4-ish

% <<<<<<<<<<<<<<<<<<<< ASK Modulation and Demodulation

>>>>>>>>>>>>>>>>>>>>
clc, clear all, close all;
% ******************* Digital/Binary input information ********************
x = input('Enter Digital Input Information = '); % Binary information as
stream of bits (binary signal 0 or 1)
N = length(x);
Tb = 1; %Data rate = 1MHz i.e., bit period (second)
disp('Binary Input Information at Transmitter: ');
disp(x);
% ************* Represent input information as digital signal *************
nb = 100; % Digital signal per bit
digit = [];
for n = 1:1:N
if x(n) == 1;
sig = ones(1,nb);
else x(n) == 0;
sig = zeros(1,nb);
end
digit = [digit sig];
end
t1 = Tb/nb:Tb/nb:nb*N*(Tb/nb); % Time period
figure('Name','ASK Modulation and Demodulation','NumberTitle','off');
subplot(3,1,1);
plot(t1,digit,'LineWidth',2.5);
grid on;
axis([0 Tb*N -0.5 1.5]);
xlabel('Time(Sec)');
ylabel('Amplitude(Volts)');
title('Digital Input Signal');
% **************************** ASK Modulation
*****************************
Ac1 = 10.8; % Carrier amplitude for binary input '1'
Ac2 = 2; % Carrier amplitude for binary input '0'
br = 1/Tb; % Bit rate
Fc = br*6; % Carrier frequency
t2 = Tb/nb:Tb/nb:Tb; % Signal time
mod = [];
for (i = 1:1:N)
if (x(i) == 1)
y = Ac1*cos(2*pi*Fc*t2); % Modulation signal with carrier signal 1
else
y = Ac2*cos(2*pi*Fc*t2); % Modulation signal with carrier signal 2
end
mod = [mod y];
end
t3 = Tb/nb:Tb/nb:Tb*N; % Time period
subplot(3,1,2);
plot(t3,mod);
xlabel('Time(Sec)');
ylabel('Amplitude(Volts)');
title('ASK Modulated Signal');
% ********************* Transmitted signal x ******************************
x = mod;
% ********************* Channel model h and w
*****************************
h = 1; % Signal fading
w = 0; % Noise
% ********************* Received signal y
*********************************
y = h.*x + w; % Convolution
% *************************** ASK Demodulation
****************************
s = length(t2);
demod = [];
for n = s:s:length(y)
t4 = Tb/nb:Tb/nb:Tb; % Time period
c = cos(2*pi*Fc*t4); % Carrier signal
mm = c.*y((n-(s-1)):n); % Convolution
t5 = Tb/nb:Tb/nb:Tb;
z = trapz(t5,mm); % Intregation
rz = round((2*z/Tb));
Ac = ((Ac1 + Ac2)/2); % Average of carrier amplitudes
if(rz > Ac) % Logical condition
a = 1;
else
a = 0;
end
demod = [demod a];
end
disp('Demodulated Binary Information at Receiver: ');
disp(demod);
% ********** Represent demodulated information as digital signal
**********
digit = [];
for n = 1:length(demod);
if demod(n) == 1;
sig = ones(1,nb);
else demod(n) == 0;
sig = zeros(1,nb);
end
digit = [digit sig];
end
t5 = Tb/nb:Tb/nb:nb*length(demod)*(Tb/nb); % Time period
subplot(3,1,3)
plot(t5,digit,'LineWidth',2.5);grid on;
axis([0 Tb*length(demod) -0.5 1.5]);
xlabel('Time(Sec)');
ylabel('Amplitude(Volts)');
title('ASK Demodulated Signal');
% ************************** End of the program
***************************

5-ish

% <<<<<<<<<<<<<<<<<<<< FSK Modulation and Demodulation


>>>>>>>>>>>>>>>>>>>>

clc;
clear all;
close all;

% ***** Digital/Binary input information ******


x = input('Enter Digital Input Information as vector ): '); % Binary
information as stream of bits (0 or 1)
N = length(x);
Tb = 1; % Bit period (seconds)
disp('Binary Input Information at Transmitter: ');
disp(x);

% *** Represent input information as digital signal ***


nb = 100; % Samples per bit
digit = [];
for n = 1:N
if x(n) == 1
sig = ones(1, nb);
else
sig = zeros(1, nb);
end
digit = [digit sig];
end
t1 = Tb/nb : Tb/nb : Tb*N; % Time vector for digital signal

figure('Name','FSK Modulation and Demodulation','NumberTitle','off');


subplot(3,1,1);
plot(t1, digit, 'LineWidth', 2.5);
grid on;
axis([0 Tb*N -0.5 1.5]);
xlabel('Time (Sec)');
ylabel('Amplitude (Volts)');
title('Digital Input Signal');

% ****** FSK Modulation *******


Ac = 10; % Carrier amplitude
br = 1/Tb; % Bit rate
Fc1 = br * 4; % Carrier frequency for bit '1'
Fc2 = br * 2; % Carrier frequency for bit '0'
t2 = Tb/nb : Tb/nb : Tb; % Time vector for one bit
mod = [];

for i = 1:N
if x(i) == 1
y = Ac * cos(2 * pi * Fc1 * t2);
else
y = Ac * cos(2 * pi * Fc2 * t2);
end
mod = [mod y];
end

t3 = Tb/nb : Tb/nb : Tb*N; % Time vector for modulated signal


subplot(3,1,2);
plot(t3, mod);
xlabel('Time (Sec)');
ylabel('Amplitude (Volts)');
title('FSK Modulated Signal');

% ***** Transmitted signal *****


x_signal = mod;

% ***** Channel model *****


h = 1; % Signal fading coefficient (no fading)
w = 0; % Noise (no noise)

% ***** Received signal *****


y = h * x_signal + w;

% ***** FSK Demodulation *****


s = length(t2);
demod = [];
for n = s:s:length(y)
t4 = Tb/nb : Tb/nb : Tb;
c1 = cos(2 * pi * Fc1 * t4);
c2 = cos(2 * pi * Fc2 * t4);

% Multiply received signal segment with carrier signals


mc1 = c1 .* y((n - s + 1) : n);
mc2 = c2 .* y((n - s + 1) : n);

% Integrate over bit period using trapezoidal integration


z1 = trapz(t4, mc1);
z2 = trapz(t4, mc2);

rz1 = round(2 * z1 / Tb);


rz2 = round(2 * z2 / Tb);

% Decision logic
if rz1 > Ac / 2
a = 1;
else
a = 0;
end

demod = [demod a];


end

disp('Demodulated Binary Information at Receiver: ');


disp(demod);

% Represent demodulated information as digital signal


digit_demod = [];
for n = 1:length(demod)
if demod(n) == 1
sig = ones(1, nb);
else
sig = zeros(1, nb);
end
digit_demod = [digit_demod sig];
end

t5 = Tb/nb : Tb/nb : Tb * length(demod); % Time vector for demodulated


signal
subplot(3,1,3);
plot(t5, digit_demod, 'LineWidth', 2.5);
grid on;
axis([0 Tb*length(demod) -0.5 1.5]);
xlabel('Time (Sec)');
ylabel('Amplitude (Volts)');
title('FSK Demodulated Signal');

% ****** End of the program *******

6-ish

% <<<<<<<<<<<<<<<<<<<< FSK Modulation and Demodulation

>>>>>>>>>>>>>>>>>>>>
clc;
clear all;
close all;

% ***** Digital/Binary input information ******


x = input('Enter Digital Input Information as vector ): '); % Binary
information as stream of bits (0 or 1)
N = length(x);
Tb = 1; % Bit period (seconds)
disp('Binary Input Information at Transmitter: ');
disp(x);

% *** Represent input information as digital signal ***


nb = 100; % Samples per bit
digit = [];
for n = 1:N
if x(n) == 1
sig = ones(1, nb);
else
sig = zeros(1, nb);
end
digit = [digit sig];
end
t1 = Tb/nb : Tb/nb : Tb*N; % Time vector for digital signal

figure('Name','FSK Modulation and Demodulation','NumberTitle','off');


subplot(3,1,1);
plot(t1, digit, 'LineWidth', 2.5);
grid on;
axis([0 Tb*N -0.5 1.5]);
xlabel('Time (Sec)');
ylabel('Amplitude (Volts)');
title('Digital Input Signal');

% ****** FSK Modulation *******


Ac = 10; % Carrier amplitude
br = 1/Tb; % Bit rate
Fc1 = br * 4; % Carrier frequency for bit '1'
Fc2 = br * 2; % Carrier frequency for bit '0'
t2 = Tb/nb : Tb/nb : Tb; % Time vector for one bit
mod = [];

for i = 1:N
if x(i) == 1
y = Ac * cos(2 * pi * Fc1 * t2);
else
y = Ac * cos(2 * pi * Fc2 * t2);
end
mod = [mod y];
end

t3 = Tb/nb : Tb/nb : Tb*N; % Time vector for modulated signal


subplot(3,1,2);
plot(t3, mod);
xlabel('Time (Sec)');
ylabel('Amplitude (Volts)');
title('FSK Modulated Signal');

% ***** Transmitted signal *****


x_signal = mod;

% ***** Channel model *****


h = 1; % Signal fading coefficient (no fading)
w = 0; % Noise (no noise)

% ***** Received signal *****


y = h * x_signal + w;

% ***** FSK Demodulation *****


s = length(t2);
demod = [];
for n = s:s:length(y)
t4 = Tb/nb : Tb/nb : Tb;
c1 = cos(2 * pi * Fc1 * t4);
c2 = cos(2 * pi * Fc2 * t4);

% Multiply received signal segment with carrier signals


mc1 = c1 .* y((n - s + 1) : n);
mc2 = c2 .* y((n - s + 1) : n);

% Integrate over bit period using trapezoidal integration


z1 = trapz(t4, mc1);
z2 = trapz(t4, mc2);

rz1 = round(2 * z1 / Tb);


rz2 = round(2 * z2 / Tb);

% Decision logic
if rz1 > Ac / 2
a = 1;
else
a = 0;
end

demod = [demod a];


end

disp('Demodulated Binary Information at Receiver: ');


disp(demod);

% Represent demodulated information as digital signal


digit_demod = [];
for n = 1:length(demod)
if demod(n) == 1
sig = ones(1, nb);
else
sig = zeros(1, nb);
end
digit_demod = [digit_demod sig];
end

t5 = Tb/nb : Tb/nb : Tb * length(demod); % Time vector for demodulated


signal
subplot(3,1,3);
plot(t5, digit_demod, 'LineWidth', 2.5);
grid on;
axis([0 Tb*length(demod) -0.5 1.5]);
xlabel('Time (Sec)');
ylabel('Amplitude (Volts)');
title('FSK Demodulated Signal');

% ****** End of the program *******

You might also like