Skip to content

Instantly share code, notes, and snippets.

@MrWooJ
Created January 19, 2016 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrWooJ/861fcc2293a3a4d02ba1 to your computer and use it in GitHub Desktop.
Save MrWooJ/861fcc2293a3a4d02ba1 to your computer and use it in GitHub Desktop.
WJMatlab-PSK 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;
Amplitude = 5;
bitRate = 1/bitPeriod;
frequency = bitRate*2;
% 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 PSK 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*frequency*table2);
else
y = Amplitude * sin(2*pi*frequency*table2+pi);
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 PSK Modulation');
% Binary PSK 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 > 0
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) -.5 1.5]);
ylabel('A(volt)');
xlabel('T(sec)');
title('Binary PSK Demodulation');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment