Skip to content

Instantly share code, notes, and snippets.

@MrWooJ
Created January 19, 2016 09:03
Show Gist options
  • Select an option

  • Save MrWooJ/ab5d8a53e67c38b00627 to your computer and use it in GitHub Desktop.

Select an option

Save MrWooJ/ab5d8a53e67c38b00627 to your computer and use it in GitHub Desktop.
WJMatlab-ASK Coding Scehma
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;
Amplitude1 = 5;
Amplitude2 = 2.5;
bitRate = 1/bitPeriod;
frequency = bitRate*10;
% 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 ASK Modulation Plot
table2 = bitPeriod/99 : bitPeriod/99 : bitPeriod;
ss = length(table2);
waveArray = [];
for i = 1 : 1 : length(xSignal)
if xSignal(i) == 1
y = Amplitude1 * sin(2*pi*frequency*table2);
else
y = Amplitude2 * sin(2*pi*frequency*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 ASK Modulation');
% Binary ASK Demodulation Plot
monoArray = [];
for n = ss : ss : length(waveArray)
table = bitPeriod/99 : bitPeriod/99 : bitPeriod;
y = sin(2*pi*frequency*table);
mm = y.*waveArray((n-(ss-1)) : n);
table4 = bitPeriod/99 : bitPeriod/99 : bitPeriod;
trapezoidal = trapz(table4,mm);
roundal = round((2*trapezoidal / bitPeriod));
if roundal > 3.75
value = 1;
else
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 ASK Demodulation');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment