Created
January 19, 2016 09:08
-
-
Save MrWooJ/7471c41adc38b2097967 to your computer and use it in GitHub Desktop.
WJMatlab-FSK Coding Scehma
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
clc; | |
clear all; | |
close all; | |
FigHandle = figure('Menu','none','Position', [350, 200, 700, 500]); | |
xSignal = [ 1 0 0 1 1 0 1 0 1 1 ]; | |
bitPeriod = 0.1; | |
Amplitude = 5; | |
bitRate = 1/bitPeriod; | |
frequency1 = bitRate*5; | |
frequency2 = bitRate*2.5; | |
% Binary Digital Signal Plot | |
bitArray = []; | |
for n = 1 : 1 : length(xSignal) | |
if xSignal(n) == 1; | |
signalElement = ones(1, 100); | |
else xSignal(n) == 0; | |
signalElement = zeros(1, 100); | |
end | |
bitArray = [bitArray signalElement]; | |
end | |
table1 = bitPeriod/100 : bitPeriod/100 : 100*length(xSignal)*(bitPeriod/100); | |
subplot(3, 1, 1); | |
plot(table1, bitArray, 'lineWidth', 2.5); grid on; | |
axis([ 0 bitPeriod*length(xSignal) -0.5 1.5]); | |
ylabel('A(volt)'); | |
xlabel('T(sec)'); | |
title('Transmitting Information: Digital Signal'); | |
% Binary FSK Modulation Plot | |
table2 = bitPeriod/99 : bitPeriod/99 : bitPeriod; | |
ss = length(table2); | |
waveArray = []; | |
for i = 1 : 1 : length(xSignal) | |
if xSignal(i) == 1 | |
y = Amplitude * sin(2*pi*frequency1*table2); | |
else | |
y = Amplitude * sin(2*pi*frequency2*table2); | |
end | |
waveArray = [waveArray y]; | |
end | |
table3 = bitPeriod/99 : bitPeriod/99 : bitPeriod*length(xSignal); | |
subplot(3, 1, 2); | |
plot(table3, waveArray); | |
xlabel('T(sec)'); | |
ylabel('A(volt)'); | |
title('Binary FSK Modulation'); | |
% Binary FSK Demodulation Plot | |
monoArray = []; | |
for n = ss : ss : length(waveArray) | |
table = bitPeriod/99 : bitPeriod/99 : bitPeriod; | |
y1 = sin(2*pi*frequency1*table); | |
y2 = sin(2*pi*frequency2*table); | |
mm = y1.*waveArray((n-(ss-1)):n); | |
mmm = y2.*waveArray((n-(ss-1)):n); | |
table4 = bitPeriod/99 : bitPeriod/99 : bitPeriod; | |
trapezoidal1 = trapz(table4, mm); | |
trapezoidal2 = trapz(table4, mmm); | |
roundal1 = round(2*trapezoidal1/bitPeriod); | |
roundal2 = round(2*trapezoidal2/bitPeriod); | |
if roundal1 > Amplitude/2; | |
value = 1; | |
else roundal2 > Amplitude/2; | |
value = 0; | |
end | |
monoArray = [monoArray value]; | |
end | |
bitArray = []; | |
for n = 1 : length(monoArray); | |
if monoArray(n) == 1; | |
signalElement = ones(1, 100); | |
else monoArray(n) == 0; | |
signalElement = zeros(1, 100); | |
end | |
bitArray = [bitArray signalElement]; | |
end | |
table4 = bitPeriod/100 : bitPeriod/100 : 100*length(monoArray)*(bitPeriod/100); | |
subplot(3, 1, 3) | |
plot(table4, bitArray, 'LineWidth', 2.5); grid on; | |
axis([ 0 bitPeriod*length(monoArray) -0.5 1.5]); | |
ylabel('A(volt)'); | |
xlabel('T(sec)'); | |
title('Binary FSK Demodulation'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment