%matlab code for digital modulation(ask, fsk and psk)
close all
clear all
clc
no_bit=input('Enter Number of Data Input on range 1-30 bits =') %no_bit only
valid for 1-30
no_bit_input= randint(1,no_bit); %no_bit_input == g
t_sample=10; %Hz %t_sample==f %contoh: f=2
f0=5; %f0 and f1 must be integers
f1=t_sample; %f0 and f1 must be integers
[bit,ask,carrier]=ASK(no_bit_input,t_sample); %ASK([1 0 1 1 0],2)
[bit,fsk,carrier]=FSK(no_bit_input,f0,f1); %FSK([1 0 1 1 0],1,2)
[bit,psk,carrier]=PSK(no_bit_input,t_sample); %PSK([1 0 1 1 0],2)
%% figure_________________--- ASK ---- ___________________
figure()
subplot(3,1,1);
plot(bit,'k','LineWidth',1.5);grid on;
%axis([0 100*length(no_bit_input) -2.0 2.0]);
title('Binary Signal');
subplot(3,1,2)
plot(carrier, 'r', 'LineWidth',1.5);grid on;
%axis([0 100*length(no_bit_input) -2.0 2.0]);
title('Carrier Signal');
subplot(3,1,3);
plot(ask,'LineWidth',1.5);grid on;
%axis([0 100*length(no_bit_input) -2.0 2.0]);
title('ASK modulation');
%% figure_________________--- FSK ---- ___________________
figure()
subplot(3,1,1);
plot(bit,'k','LineWidth',1.5);grid on;
%axis([0 100*length(no_bit_input) -2.0 2.0]);
title('Binary Signal');
subplot(3,1,2)
plot(carrier, 'r', 'LineWidth',1.5);grid on;
%axis([0 100*length(no_bit_input) -2.0 2.0]);
title('Carrier Signal');
subplot(3,1,3);
plot(fsk,'LineWidth',1.5);grid on;
%axis([0 100*length(no_bit_input) -2.0 2.0]);
title('FSK modulation');
%% figure_________________--- PSK ---- ___________________
figure()
subplot(3,1,1);
plot(bit,'k','LineWidth',1.5);grid on;
%axis([0 100*length(no_bit_input) -2.0 2.0]);
title('Binary Signal');
subplot(3,1,2)
plot(carrier, 'r', 'LineWidth',1.5);grid on;
%axis([0 100*length(no_bit_input) -2.0 2.0]);
title('Carrier Signal');
subplot(3,1,3);
plot(psk,'LineWidth',1.5);grid on;
%axis([0 100*length(no_bit_input) -2.0 2.0]);
title('PSK modulation');
%% figure_________________--- all ---- ___________________
figure()
subplot(5,1,1);
plot(bit,'m','LineWidth',1.5);grid on;
%axis([0 100*length(no_bit_input) -2.0 2.0]);
title('Binary Signal');
subplot(5,1,2)
plot(carrier, 'r', 'LineWidth',1.5);grid on;
%axis([0 100*length(no_bit_input) -2.0 2.0]);
title('Carrier Signal');
subplot(5,1,3);
plot(ask,'LineWidth',1.5);grid on;
%axis([0 100*length(no_bit_input) -2.0 2.0]);
title('ASK modulation');
subplot(5,1,4);
plot(fsk,'LineWidth',1.5);grid on;
title('FSK modulation');
%axis([0 100*length(no_bit_input) -2.0 2.0]);
subplot(5,1,5);
plot(psk,'LineWidth',1.5);grid on;
title('PSK modulation');
%axis([0 100*length(no_bit_input) -2.0 2.0]);