%MATLAB Script for a Binary PSK with two Phases
% Clear all variables and close all figures
clear all;
close all;
bit_stream = [1,0,1,0,1,0,1,0];
% Enter the two Phase shifts - in Radians
% Phase for 0 bit
P1 = 0;
% Phase for 1 bit
P2 = pi;
% Frequency of Modulating Signal
f = 2; %f --> time period
% Sampling rate of sine wave - This will define the resoultion
fs = 100;
% Time for one bit
t = 0: 1/fs : 1;
% This time variable is just for plot
time = [];
PSK_signal = [];
Digital_signal = [];
carrier_signal = [];
for ii = 1: 1: length(bit_stream)
% The Original Digital Signal
if bit_stream(ii)==0
bit0 = zeros(1,length(t));
Digital_signal = [Digital_signal bit0];
end
if bit_stream(ii)==1
bit1 = ones(1,length(t));
Digital_signal = [Digital_signal bit1];
end
% The FSK Signal
if bit_stream(ii)==0
PSK_signal = [PSK_signal cos(2*pi*f*t + P2)];
end
if bit_stream(ii)==1
PSK_signal = [PSK_signal cos(2*pi*f*t + P1)];
end
% Generating carrier wave
carrier_signal = [carrier_signal (cos(2*pi*f*t))];
time = [time t];
t = t + 1;
end
% Plot the Original Digital Signal
subplot(4,1,1);
plot(time,Digital_signal,'r','LineWidth',2);
xlabel('Time (bit period)');
ylabel('Amplitude');
title('Original Digital Signal');
axis([0 time(end) -0.5 1.5]);
grid on;
% Plot the carrier Signal
subplot(4,1,2);
plot(time,carrier_signal,'g','LineWidth',2);
xlabel('Time (bit period)');
ylabel('Amplitude');
title('carrier Signal');
axis([0 time(end) -1.5 1.5]);
grid on;
% Plot the PSK Signal
subplot(4,1,3);
plot(time,PSK_signal,'LineWidth',2);
xlabel('Time (bit period)');
ylabel('Amplitude');
title('PSK Signal with two Phase Shifts');
axis([0 time(end) -1.5 1.5]);
grid on;
% Plot the Demodulation BPSK Signal
de_PSK_signal=PSK_signal.*carrier_signal;
subplot(4,1,4);
plot(time,de_PSK_signal,'LineWidth',2);
xlabel('Time (bit period)');
ylabel('Amplitude');
title('Demodulation BPSK Signal');
axis([0 time(end) -1.5 1.5]);
grid on;