BPSK Simulation in MATLAB

Actually flicked the program from somewhere in a forum.

Took some time to understand it first. Few months back.

Now i’ve coded it better with some tweaks. So that you understand it sooner than me. 🙂


Here’s the code, I’ve copied and changed it to Italics, copy, paste, save and run.
Post your doubts in the comments 

clear all;
close all;

f = 2; %frequency of sine wave
fs = 100; %sampling period of the sine wave
t = 0:1/fs:1; %splitting time into segments of 1/fs
%setting the phase shifts for the different BPSK signals
p1 = 0;
p2 = pi;
%getting the number bits to be modulated
N = input(‘enter the number of bits to be modulated: N = ‘);
%generating the random signal
%allocating the dynamic variables
time = [];
digital_signal = [];
PSK = [];
carrier_signal = [];

for ii = 1:1:N
%the original digital signal is
if bit_stream(ii) == 0
bit = zeros(1,length(t));
bit = ones(1,length(t));
% bit0 = (bit_stream(ii)==0)*zeros(1,length(t));
% bit1 = (bit_stream(ii)==1)*ones(1,length(t));
digital_signal = [digital_signal bit];

%Generating the BPSK signal
if bit_stream(ii) == 0
bit = sin(2*pi*f*t+p1);
bit = sin(2*pi*f*t+p2);
PSK = [PSK bit];

%Generating the carrier wave
carrier = sin(2*f*t*pi);
carrier_signal = [carrier_signal carrier];

time = [time t];
t = t + 1;


grid on;
axis([0 time(end) -0.5 1.5]);

grid on;
% axis([0 time(end) -2 2]);
axis tight;

grid on;
axis tight;



The output should look something like this … 



12 thoughts on “BPSK Simulation in MATLAB

  1. sorry in my hurry i did not erase some of the commands which i ‘commented’
    Please ignore those…
    (the lines starting with % can be ignored totally, theyre just comments, theyre either to make u understand better or to confuse u.. IGNORE)

    • Hello wafik… It stands for “red” … It plots that particular variable in Red.. See the digital signal plot. Just to show some difference. Nothing technical about it.

  2. the program is working but the it is not giving the expected out. input bitstream is not showing any up down, its coming a straightline whether i change how many times 1 to 0.

  3. I’m soo new to matlab. this section below is giving me syntax error. I change to (8).
    %getting the number bits to be modulated
    N = input(‘enter the number of bits to be modulated: N = ‘);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s