PN sequences or Pseudo Noise sequence is a periodic binary code which is random in nature generated by the use of shift registers, but generated with taking into considerations some generator polynomials. For sequence to be a pseudo noise or pseudo random it should follow the following basic rules. The rules mentioned below are simply mentioned in brief:

- The relative frequency of 0’s and 1’s are each ½
- The run lengths of 0’s and 1’s are: ½ of all run lengths are of length 1; ¼ are of length 2; 1/8 are of length 3; and so on.
- If a PN sequence is shifted by any non zero number of elements, the resulting sequence will have an equal number of agreements and disagreements with respect to the original sequence.

These properties are known also known as balance property, run property, and correlation property respectively. This code is orthogonal in nature. PN sequence is also known as Maximal Length Sequences.

PN sequences are used in spread spectrum systems, like CDMA, WCDMA, and Radar etc. In CDMA IS 95, 64 ling PN sequence codes are used for the identification if the reverse link channels.

The matlab script for generating pn sequence is given below, and also can be downloaded from this link.

refer figure as a companion for the matlab file

function [op_seq] = pnseq (a, b, c)

% a : no of fliflops; b = tapp _ function starting frm highest order; c = initial stae

%tapp functions or genrator polynomial

%e.g. no of flip flops 4 ==> a = 4

%generator polynomial x4+x+1 ==> b = [1 0 0 1]

%initial state [1 0 0 0] ==> c = [1 0 0 0]

%refere figure to set a relation between tap function and initial state

%

%

%

%

% <

% ———–X____________________________________

% | ___ | _____ ____ _____ |

% |> | | | | | | | | | ^|

% —–| |——–| |—| |——-| |————->o/p

% —– —– —– —-

% x1 + x2 + x3 + x4

%initial state

% 1 0 0 1

%

%take care of the reverse order of genrator polynomial and intiial states

%

%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

close all;

clc;

x = a;

tap_ff =b;

int_stat= c;

for i = 1:1: length(int_stat)

old_stat(i) = int_stat(i);

gen_pol(i) = tap_ff(i);

end

len = (2 ^x)-1;

gen_pol(i+1)= 1;

gen_l = length(gen_pol);

old_l = length(old_stat);

for i1 = 1: 1:len

% feed back input genration

t = 1;

for i2 = 1:old_l

if gen_pol(i2)==1

stat_str(t) = old_stat(gen_l – i2);

i2 = i2+1;

t = t+1;

else

i2 = i2+1;

end

end

stat_l = length(stat_str);

feed_ip = stat_str(1);

for i3 = 1: stat_l-1

feed_ip = bitxor(feed_ip,stat_str(i3 + 1));

feed_ipmag(i1) = feed_ip;

i3 = i3+1;

end

% shifting elements

new_stat = feed_ip;

for i4 = 1:1:old_l

new_stat(i4+1) = old_stat(i4);

old_stat(i4)= new_stat(i4);

end

op_seq(i1) = new_stat(old_l +1);

end

%op_seq;

==============================

how to write the matlab code for ROM module…..can u plz give the code for it…

will you please elaborate this ROM module thing? I am not getting exactly what you are taking about infact i got confused with this ROM module. Explain it may be I willbe able to help you out with that.

hi ashwini…

I’ve a problem in running this code.

stat_str(t) = old_stat(gen_l – i2)

in this expression matlab gives an error.

Can you please re look at this code.

hi dinesh,

will please post the error message !

hi ashwini

(gen_l – i2)…in this matlab gives en error…

it says the input character is not valid in MATLAB expression(the minus sign)

hi dinesh,

I tested the code, and i found you are getting error because you are passing -ve value to some argument. for test, i used the standard example define in the beginning of the code i.e. pnseq(a,b,c)

a no of flipflops = 4

b generator polynomial x^4+x+1 = [1 0 0 1]

c initial state = [1 0 0 0]

i think you had pass some negative value in the initial state.

what are the inputs you had given ?

i needed this type of code so i just copy the whole code n paste in matlab…n i came up with this error…

hi dinesh,

it is better to download the .m file and then copy in your own code or modified accordingly. Also, i think you should first download the m file from this Matlab File Exchange or from this Resource CEnter Then run it once to see that you are getting the right out put or not, and then modify it accordingly.

Feel free to ask for help

thanks…..

now it works….

Hi dinesh,

Nice to hear that now it is working ! thanks for stopping by and leaving a comment !

what’s the function of if statement in this code….

in the argument given below

stat_str(t) = old_stat(gen_l – i2)

Hello Dinesh,

the function stat_str(t) = old_stat(gen_l -i2) is used for following reason:

old_stat(i) = int_stat(i);

gen_pol(i) = tap_ff(i);

In old_stat we are saving the states and in gen_pol is used to save the tap function. say you are having a tap function x4+x+1 which simply means you will xor 1 flip flops’s state and fourth flip flop states and then feed the result to input. The function you asked for is doing the same, we define the flip flops to xor by 1, by checking which flip flops out of 4 (in above example) is to be xored (in tap function it is denoted by 1) we will save its current state in a temp variable or array (for more than 1 flip flop eg x4+x2+x+1) and then we will xor them. stat_str is that temp array and the statement you asked for is doing the same thing of saving into temp array according to the value in tap function.

hallo Ashwini,

i m a beginner in matlab and need some help. would you plz make some comments to ur matlab-code so i can understand how it works.

thanks

Nidal

hello Ashwini,

i didnt understand how does ur matlab-code work?

would u plz make some more comments about it..

Thanks,

Nidal

Hello Nidal,

Soon will upgrade the code with comments and more readibility, meanwhile go through the earlier comments, in one I explained the code (little bit)

Regards

thank!

i need matlab codings for generating PN sequence… is this the right code for me??

Arumiga,

Yes this the right code for generating matlab code. Before running the code check the comments / tutorial note.

Regards,

WirelessCafe Team!

hi ashwini,

help me to generate a pn sequence using matlab coding

Subha,

The download link for the code is given in the post, check it and make me know.

WirelessCafe Team !

hi ashwini,

help me to generate pn sequence using matlab coding

Hi Ashwini

Do you know smth abt WIMAX. M doing a project on channel estimation of WIMAX. I dont know where to begin with. Can you help me with this.

thanks

Dear Deepak,

Drop me a mail at my email id with little more details.

I will try to help you.

Thanks and Regards,

Ashwini for WirelessCafe Team !

Hi Ashwani,

Do you have any code or can you help me related to mimo-ofdm. Ive done the siso case but facing some doubts related to mimo case. I can e-mail you a brief description if you will to help me.

thanks

Dear Deepak,

Due to work load now a days I am not getting time, still, send me the details. I will try to have a look.

All the best,

Ashwini for WirelessCafe !!

Help!!!!!!!!!!!!!!!!!!!!!!!!!!!Dear Mr.Patankar,

Help to first thank you for your willingness to help people.

I am a student and study for my work, I had a PN generator with 12 sequences ==> a = 12

and the initial state is [111111111111] ==> c = [111111111111]

Now how should be the generator polynomial? ==> B =?

I am very happy to be a quick answer and I thank you for the very forward to help.

Best regards

Mr. Camara

Dear Camara,

Go through the tut given in the code, for further detials, post the error messages or drop me a mail.

All the best,

Ashwini for WirelessCafe !!

hi Ashwini ..

when i want to run this code by putting a= 4 , b= x^4+x+1 and c=[1 0 0 0]

or any other combinations , i am getting the following error

Attempted to access tap_ff(2); index out of bounds because

numel(tap_ff)=1.

help me

Dear Aditya,

I will try and make you know.

All the best,

Ashwini for WirelessCafe !!

Hello Ashwini

I can your matlab code and check the results as well, but its not matching when i use inbuilt function (comm.pnsequence in matlab). Please can u help how to generate gold sequence with two polynomials