-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneratePN3phase.m
More file actions
61 lines (55 loc) · 2.17 KB
/
generatePN3phase.m
File metadata and controls
61 lines (55 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function [txA, txB, txC, txChipA, Fs, samplesPerChip] = generatePN3phase(pnLength, samplesPerChip, chipRate, mode)
% generatePN3phase
% ----------------------------------------------------
% Generates three PN sequences (A,B,C) for 3-phase STDR.
% Output waveforms are upsampled by samplesPerChip.
%
% INPUTS:
% pnLength Length of PN sequence (e.g., 511, 1023)
% samplesPerChip Upsampling factor (e.g., 20)
% chipRate Chip rate in Hz (e.g., 500 kHz)
% mode 'orthogonal' or 'same'
%
% OUTPUTS:
% txA, txB, txC Upsampled bipolar PN waveforms (-1, +1)
% txChipA Base chip-level PN sequence (before upsampling)
% Fs Sample frequency = chipRate * samplesPerChip
%
% MATLAB R2024b compatible
% Requires: Communications Toolbox
%% Compute sampling frequency
Fs = chipRate * samplesPerChip;
%% Create PN generators using different polynomials for orthogonality
switch lower(mode)
case 'orthogonal'
% Use 3 independent maximal-length sequences
pnA = comm.PNSequence('Polynomial','x^10 + x^3 + 1', ...
'SamplesPerFrame', pnLength, ...
'InitialConditions',[1 zeros(1,9)]);
pnB = comm.PNSequence('Polynomial','x^10 + x^5 + 1', ...
'SamplesPerFrame', pnLength, ...
'InitialConditions',[1 zeros(1,9)]);
pnC = comm.PNSequence('Polynomial','x^10 + x^7 + 1', ...
'SamplesPerFrame', pnLength, ...
'InitialConditions',[1 zeros(1,9)]);
otherwise
% All phases use the same PN → not recommended but allowed
pnA = comm.PNSequence('Polynomial','x^10 + x^3 + 1', ...
'SamplesPerFrame', pnLength, ...
'InitialConditions',[1 zeros(1,9)]);
pnB = pnA;
pnC = pnA;
end
%% Generate sequences
seqA = pnA();
seqB = pnB();
seqC = pnC();
%% Convert to bipolar (-1, +1)
txChipA = 2*seqA - 1;
txChipB = 2*seqB - 1;
txChipC = 2*seqC - 1;
%% Upsample
txA = upsample(txChipA, samplesPerChip);
txB = upsample(txChipB, samplesPerChip);
txC = upsample(txChipC, samplesPerChip);
end