Cematlab
Cematlab
Aim:
To study the pulse amplitude modulation and demodulation.
Program:
clc; clear all; close all;
fc = 100; % Carrier frequency
fm = fc/10; % Modulating frequency
fs = 100*fc; % Sampling frequency
t = 0:1/fs:4/fm; % Time array
% Message signal
mt = cos(2*pi*fm*t);
% Carrier signal
ct = 0.5*square(2*pi*fc*t)+0.5;
% Modulated signal
st = mt.*ct;
% Single-sided PAM
tt = zeros(size(st));
for i = 1:length(st)
if st(i) < 0
tt(i) = 0;
else
tt(i) = st(i) + 2;
end
end
% Plotting
figure(1);
subplot(4,1,1);
plot(t, mt);
title('Message Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(4,1,2);
plot(t, ct);
title('Carrier Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(4,1,3);
plot(t, tt);
title('Pulse Amplitude Modulated Signal');
xlabel('Time (s)');
ylabel('Amplitude');
% Demodulation
dt = st.*ct;
dt_frequency = fftshift(abs(fft(dt)));
filter = fir1(200, fm/fs, 'low');
original_t_signal = conv(filter, dt);
t1 = 0:1/(length(original_t_signal)-1):1;
subplot(4,1,4);
plot(t1, original_t_signal);
title('Demodulated Signal');
xlabel('Time (s)');
ylabel('Amplitude');
Result:
Pulse amplitude modulation (PAM) and demodulation is studied.
PULSE WIDTH MODULATION AND DEMODULATION
Aim:
To study the pulse width modulation and demodulation.
Program:
clear all; clc; close all;
t = 0:0.001:1;
fc = 10;
fm = 1;
a = 5;
b = 4;
vc = a.*sawtooth(2*pi*fc*t);
vm = b.*sin(2*pi*fm*t);
n = length(vc);
pwm1 = zeros(n,1);
for i = 1:n
if (vm(i)>=vc(i))
pwm1(i) = 1;
else
pwm1(i) = 0;
end
end
figure;
subplot(3,1,1);
plot(t,vm);
xlabel('Time ----->');
ylabel('Amplitude ----->');
title('Message Signal');
grid on;
subplot(3,1,2);
plot(t,vc);
xlabel('Time ----->');
ylabel('Amplitude ----->');
title('Carrier Signal');
grid on;
subplot(3,1,3);
stairs(t,pwm1); % Use stairs instead of plot
xlabel('Time ----->');
ylabel('Amplitude ----->');
title('PWM Signal');
axis([0 1 0 2]);
grid on;
Model waveforms:
Result:
Pulse width modulation (PWM) and demodulation is studied.
AMPLITUDE SHIFT KEYING (ASK) GENERATION AND DETECTION
Aim:
To study the Modulation and demodulation techniques of Amplitude Shift Keying (ASK).
Hardware and software requirements:
Personal computer (PC)
MATLAB Software R2013a
Program:
clc; clear all; close all;
% Modulation process
s = zeros(size(t));
for i = 1:6
for j = (i-1)*100+1:i*100
if(n(i) == 1)
s(j) = y1(j);
else
s(j) = 0;
end
end
end
% Demodulation process
x = zeros(size(t));
for i = 1:6
for j = (i-1)*100+1:i*100
if(s(j) == y1(j))
x(j) = 1;
else
x(j) = 0;
end
end
end
Result:
Amplitude shift keying is studied.
FREQUENCY SHIFT KEYING (FSK) GENERATION AND DETECTION
Aim:
To study the Modulation and demodulation techniques of Frequency Shift Keying (FSK).
Hardware and software requirements:
Personal computer (PC)
MATLAB Software R2013a
Program:
clear all; clc; close all;
subplot(5,1,1);
plot(t,y1);
title('Carrier Signal 1');
xlabel('Time');
ylabel('Amplitude');
subplot(5,1,2);
plot(t,y2);
title('Carrier Signal 2');
xlabel('Time');
ylabel('Amplitude');
if n(l) == 1
n(l+1) = 1;
else
n(l+1) = 0;
end
l1 = length(n);
tn = 0:l1-1;
% Modulation process
s = zeros(size(t));
for i = 1:6
for j = (i-1)*100+1:i*100
if(n(i) == 1)
s(j) = y1(j);
else
s(j) = y2(j);
end
end
end
% Demodulation process
x = zeros(size(t));
for i = 1:6
for j = (i-1)*100+1:i*100
if(abs(s(j) - y1(j)) < abs(s(j) - y2(j)))
x(j) = 1;
else
x(j) = 0;
end
end
end
Result:
The Modulation and demodulation techniques of Frequency Shift Keying (FSK) are studied.