Continue to Site

# Whats wrong with this PSK Matlab Code?

Status
Not open for further replies.

#### Girly_girl

##### Full Member level 2
Hey guys

Hope u r all well.

I have written a matlab code for PSK.. and it produces a graph... but i know that the graph is not what im looking for .. it doesnt produces a correct phase shift..

The code is :

% % Generating a input square wave
x1 = 0pi/100)20*pi);
y1 = square(x1);
A = plot(x1,y1);
figure(1),A,title( 'Square wave');xlabel('x'); ylabel('y');ylim([-2,2]);grid;

% Generating the PSK signal

y1(y1>0)=1;
y1(y1<0)=0;

N = y1.*pi;
f=1;
t = 0pi/100)20*pi);
PSK = sin(2*pi*f*(t+ N));
figure(2),plot(t,PSK),title('PSK Signal');xlabel('x'); ylabel('y');ylim([-2,2]); xlim([0,35]);grid;

The PSK signal it produces is :

#### Tom Duke

##### Member level 2
Found it. I will check it and will give you an answer. Some remarks:
a)I can not see the produced PSK signal that you put (my browser has a prolem probabbly.. )
b)What PSK do you want to simulate? BPSK,QPSK... what? From the PSK equation that you are using it seems that you are trying to get BPSK. Check it.
c)It seems to me, that in your PSK signal you only get the inphase signal which is only a part of the signal. In order to get the full BPSK you need both inphase

A general note : Read Proakis books. They are very good, introductory and with a lot of things to think on..

Girly_girl

### Girly_girl

Points: 2

#### Girly_girl

##### Full Member level 2
Found it. I will check it and will give you an answer. Some remarks:
a)I can not see the produced PSK signal that you put (my browser has a prolem probabbly.. )
b)What PSK do you want to simulate? BPSK,QPSK... what? From the PSK equation that you are using it seems that you are trying to get BPSK. Check it.
c)It seems to me, that in your PSK signal you only get the inphase signal which is only a part of the signal. In order to get the full BPSK you need both inphase

A general note : Read Proakis books. They are very good, introductory and with a lot of things to think on..

Many thaks
The psk is the bpsk.
Regarding the book, i have just found a book and im trying to get an electronic version of it..
Digital Communications by John G. Proakis is the name of the book.

I didnt understand what u mean by the highlited text.

Harish.m24

### Harish.m24

Points: 2

#### Tom Duke

##### Member level 2
b)Ok
c)The browser highlighted it. Check the book and you will understand. For a quick view check wikipedia in psk modulation

Girly_girl

### Girly_girl

Points: 2

#### Girly_girl

##### Full Member level 2
Hey Tom,

Hope you are good.

Do you have any idea on how to improve this code?

I'd really appriciate your kindness in responding to this problem...

Thanks

#### mr_byte31

##### Full Member level 5
there are built in functions u can use
just give it input and kind of modulation and take the output

Girly_girl

### Girly_girl

Points: 2

#### Girly_girl

##### Full Member level 2
THanks mr byte
But wat are these built in functions?

#### mr_byte31

##### Full Member level 5
hmmm what i can remember
pskmod

#### Girly_girl

##### Full Member level 2
The Matlab im using doesnt recognise such a thing as pskmod :-s

#### Tom Duke

##### Member level 2
Hello. I am giving the m file for bpsk modulation
The equations are from chapter 4 of proakis book. they are equations 4-3-11 to 4-3-16.

-------------------------------------------------

%% Generating input pulses
clear all;clc;close all;
baseband1=ones(1,2000); baseband0=-ones(1,2000);
bandpass=[ones(1,1000) -ones(1,1000)];

%% General Conditions
fc=1; t = 0pi/100)20*pi-pi/100);
M=2;

%% Bandpass PSK
%Bandpass PSK = N.*cos(2*pi*fc*t+(2*pi/M)*(m-1));
m=1; PSK_Bandpass_1 = bandpass.*cos(2*pi*fc*t+(2*pi/M)*(m-1));
m=2; PSK_Bandpass_2 = bandpass.*cos(2*pi*fc*t+(2*pi/M)*(m-1));
figure(2),plot(t,PSK_Bandpass_1),title('PS Bandpass 1');xlabel('time'); ylabel('data');grid on;
figure(3),plot(t,PSK_Bandpass_2),title('PS Bandpass 2');xlabel('time'); ylabel('data');grid on;

%% Baseband PSK
%Baseband PSK Sm1 = pulse.*cos((2*pi/M)*(m-1)) for pulse = baseband1
m=1; PSK_Baseband_1 = baseband1.*cos((2*pi/M)*(m-1));
figure(4),plot(t,PSK_Baseband_1),title('PS Baseband 1');xlabel('time'); ylabel('data');grid on;

%Baseband PSK Sm2 = pulse.*sin((2*pi/M)*(m-1)) for pulse = baseband0
m=2; PSK_Baseband_2 = baseband0.*sin((2*pi/M)*(m-1));
figure(5),plot(t,PSK_Baseband_1),title('PS Baseband 1');xlabel('time'); ylabel('data');grid on;

-------------------------------------------

Sorry for the delay, but better late than late.
Hope to help.

Girly_girl

### Girly_girl

Points: 2

#### Girly_girl

##### Full Member level 2
Thank you so much Tom, U r a star
Many thanks for your time and help

Appriciated

Status
Not open for further replies.