
108 CHAPTER 5. PERIODIC SIGNAL GENERATION
Listing 5.11: MATLAB implementation of circular and linear correlation for PN sequences.
N=length( seq1 );
2
% Convert to +/- 1
4 seqn1 =(2∗seq1 ) −1;
seqn2 =(2∗seq2) −1;
6
% Set up correlation with three periods of the PN sequence
8 tmp1 =[seqn1 seqn1 seqn1 ];
10 % Time domain method for circular correlation of seq1 and seq2.
% Could also use frequency domain method with no zero padding
12 for index =1:2∗N+1;
tmp2 =[zeros (1 ,index−1) seqn2 zeros(1,2∗N−index +1) ] ;
14 cor ( index )=sum( tmp1 . ∗ tmp2 )/N ;
end ;
16 n =0:2∗N ;
18 %% frequency domain method of circular correlation
%% uncomment and use this instead if ...