Created
October 28, 2018 12:00
-
-
Save Arsfiqball/9ef37e89d1bf85f40f4a81f176d198ee to your computer and use it in GitHub Desktop.
Amplitude and Frequency Shift Keying Modulation simulation using MatLab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% Variables Definition | |
fps = 400; | |
data = [1 0 0 1 1 0 1 0 1 1]; | |
A = 4; | |
f = 8; | |
f0 = 2; | |
%% Create the signal of "Information" | |
info_signal = gen_INFO(data, fps); | |
%% Create the time array of time | |
time = gen_TIME(fps, length(info_signal)/fps); | |
%% Create the signal of "Carrier" | |
carrier_signal = gen_CARRIER(f, A, fps, length(data)); | |
carrier_signal_0 = gen_CARRIER(f0, A, fps, length(data)); | |
%% Create ASK modulated signal | |
ask_signal = gen_ASK(info_signal, carrier_signal); | |
%% Create FSK modulated signal | |
fsk_signal = gen_FSK(info_signal, carrier_signal, carrier_signal_0); | |
%% Plotting to graph | |
subplot(5,1,1); plot(time, info_signal); title('Information'); | |
subplot(5,1,2); plot(time, carrier_signal); title('Carrier'); | |
subplot(5,1,3); plot(time, carrier_signal_0); title('Carrier 0 in FSK'); | |
subplot(5,1,4); plot(time, ask_signal); title('ASK modulation'); | |
subplot(5,1,5); plot(time, fsk_signal); title('FSK modulation'); | |
%% Function: create time | |
function time = gen_TIME(fps, max_time) | |
N = fps * max_time; | |
for i = 1:N | |
time(i) = i/fps; | |
end | |
end | |
%% Function: create information signal | |
function signal = gen_INFO(data, fps) | |
N = length(data); | |
for i = 1:N | |
for j = 1:fps | |
signal((i-1) * fps + j) = data(i); | |
end | |
end | |
end | |
%% Function: create carrier signal | |
function signal = gen_CARRIER(f, A, fps, time_max) | |
N = fps * time_max; | |
for i = 1:N | |
signal(i) = A * sin(2 * pi * f * i/fps); | |
end | |
end | |
%% Function: create ASK modulated signal | |
function signal = gen_ASK(info_signal, carrier_signal) | |
N = length(info_signal); | |
for i = 1:N | |
if info_signal(i) == 1 | |
signal(i) = info_signal(i) * carrier_signal(i); | |
else | |
signal(i) = 0; | |
end | |
end | |
end | |
%% Function: create FSK modulated signal | |
function signal = gen_FSK(info_signal, carrier_signal_1, carrier_signal_0) | |
N = length(info_signal); | |
for i = 1:N | |
if info_signal(i) == 1 | |
signal(i) = carrier_signal_1(i); | |
else | |
signal(i) = carrier_signal_0(i); | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment