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**bit_stream=round(rand(1,N));**%allocating the dynamic variables**time = [];**digital_signal = [];**PSK = [];**carrier_signal = [];*

*%GENERATING THE SIGNALS**for ii = 1:1:N** %the original digital signal is** if bit_stream(ii) == 0** bit = zeros(1,length(t));** else** bit = ones(1,length(t));** end**% 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);** else** bit = sin(2*pi*f*t+p2);** end** PSK = [PSK bit];*

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

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

*end*

*subplot(3,1,1);**plot(time,digital_signal,’r’);**grid on;**axis([0 time(end) -0.5 1.5]);*

*subplot(3,1,2);**plot(time,PSK);**grid on;**% axis([0 time(end) -2 2]);**axis tight;*

*subplot(3,1,3);**plot(time,carrier_signal);**grid on;**axis tight;*

The output should look something like this …

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)

Had a few problems with the italics, had to change the apostrophe (‘) in a few places. Other than that it worked.

Thats good. But I didnt find any apostrophes in the program except for one place where the letter r is quoted as ‘r’

What does the ‘r’ stands for ?

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.

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.

good job

thankyou so much 😀

welcome 🙂

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 = ‘);

Sorry, ive not been active.

I did not get your question. Where did you change it to 8.

Thank you for sharing such a helpful code. *thumbs up*