Skip to content

Commit 9aa2449

Browse files
authored
Merge pull request #14 from JuliaTelecom/daniel-s-w/master
Add unitaryPower flag for QAM power selection
2 parents 9131347 + 3dd07ae commit 9aa2449

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

src/bitMapping.jl

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
Quadrature Amplitude Modulation (QAM) function
44
Apply symbol mapping to a input binary sequence (of size 1xL) with constellation size M.
55
Output is a vector (1xN) with N = L / log2(M)
6-
Conventional gray mapping is used. Output constellation is casted in float, with unitary average power
6+
Conventional gray mapping is used. Output constellation is casted in float, with unitary average power,
7+
except when `unitaryPower` is set to false.
78
Supported constellation
89
* QPSK
910
* 16-QAM
@@ -12,20 +13,25 @@ Quadrature Amplitude Modulation (QAM) function
1213
# --- Syntax
1314
bitMappingQAM!(qamMat,M,bitSeq)
1415
# --- Input parameters
15-
- qamMat : Complex Vector to populate of size length(bitSeq) / log2(M) [Array{Complex{Float64}}]
16-
- M : Modulation size (i.e from 4 to 256) such as bit per symbol is log2(M) [Int]
17-
- bitSeq : Binary sequence to be transformed into QPSK symbols [Array{UInt8}]
16+
- qamMat : Complex Vector to populate of size length(bitSeq) / log2(M) [Array{Complex{Float64}}]
17+
- M : Modulation size (i.e from 4 to 256) such as bit per symbol is log2(M) [Int]
18+
- bitSeq : Binary sequence to be transformed into QPSK symbols [Array{UInt8}]
19+
- unitaryPower : Normalize output power if set to true (default is true).
1820
# --- Output parameters
1921
- []
2022
"""
21-
function bitMappingQAM!(qamMat,M, bitSeq)
23+
function bitMappingQAM!(qamMat,M, bitSeq; unitaryPower=true)
2224
# ----------------------------------------------------
2325
# --- Overall parameters
2426
# ----------------------------------------------------
2527
# --- Defining scaling factor
26-
# Constellation output should have an unitary average power
28+
# Constellation output might have an unitary average power
2729
# σ^2 = ∑ p(a_i) ⃒ a_i ⃒ ^2 = 1
28-
scalingFactor = sqrt(2/3*(M-1));
30+
if unitaryPower
31+
scalingFactor = sqrt(2/3*(M-1));
32+
else
33+
scalingFactor = 1;
34+
end
2935
nbSymb = length(qamMat);
3036
# ----------------------------------------------------
3137
# --- Switch on modulation order
@@ -185,11 +191,11 @@ qamMat = bitMappingQAM(M,bitSeq)
185191
# --- Output parameters
186192
- qamMat : Complex Vector to populate of size length(bitSeq) / log2(M) [Array{Complex{Float64}}]
187193
"""
188-
function bitMappingQAM(M,bitSeq)
194+
function bitMappingQAM(M,bitSeq; unitaryPower=true)
189195
nbBits = length(bitSeq);
190196
nbSymb = Int( nbBits ÷ log2(M));
191197
buffer = zeros(Complex{Float64},nbSymb);
192-
bitMappingQAM!(buffer,M,bitSeq);
198+
bitMappingQAM!(buffer,M,bitSeq; unitaryPower);
193199
return buffer;
194200
end
195201

@@ -199,27 +205,27 @@ end
199205
# --- Multiple dispatch handling
200206
# ----------------------------------------------------
201207
# --- MD: String case for modulation order
202-
function bitMappingQAM!(qamMat,M::String, bitSeq)
208+
function bitMappingQAM!(qamMat,M::String, bitSeq; unitaryPower=true)
203209
# --- Casting modulation order to int8
204210
if M == "QPSK" || M == "4-QAM" || M == "QAM-4" || M=="4QAM" || M == "QAM4"
205-
bitMappingQAM!(qamMat,4,bitSeq);
211+
bitMappingQAM!(qamMat,4,bitSeq; unitaryPower);
206212
elseif M == "16-QAM" || M == "QAM-16" || M=="16QAM" || M == "QAM16"
207-
bitMappingQAM!(qamMat,16,bitSeq);
213+
bitMappingQAM!(qamMat,16,bitSeq; unitaryPower);
208214
elseif M == "64-QAM" || M == "QAM-64" || M=="64QAM" || M == "QAM64"
209-
bitMappingQAM!(qamMat,64,bitSeq);
215+
bitMappingQAM!(qamMat,64,bitSeq; unitaryPower);
210216
elseif M == "256-QAM" || M == "QAM-256" || M=="256QAM" || M == "QAM256"
211-
bitMappingQAM!(qamMat,256,bitSeq);
217+
bitMappingQAM!(qamMat,256,bitSeq; unitaryPower);
212218
end
213219
end
214-
function bitMappingQAM(M::String, bitSeq)
220+
function bitMappingQAM(M::String, bitSeq; unitaryPower=true)
215221
# --- Casting modulation order to int8
216222
if M == "QPSK" || M == "4-QAM" || M == "QAM-4" || M=="4QAM" || M == "QAM4"
217-
bitMappingQAM(4,bitSeq);
223+
bitMappingQAM(4,bitSeq; unitaryPower);
218224
elseif M == "16-QAM" || M == "QAM-16" || M=="16QAM" || M == "QAM16"
219-
bitMappingQAM(16,bitSeq);
225+
bitMappingQAM(16,bitSeq; unitaryPower);
220226
elseif M == "64-QAM" || M == "QAM-64" || M=="64QAM" || M == "QAM64"
221-
bitMappingQAM(64,bitSeq);
227+
bitMappingQAM(64,bitSeq; unitaryPower);
222228
elseif M == "256-QAM" || M == "QAM-256" || M=="256QAM" || M == "QAM256"
223-
bitMappingQAM(256,bitSeq);
229+
bitMappingQAM(256,bitSeq; unitaryPower);
224230
end
225231
end

test/test_bitMapping.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ println("Tests for symbol mapper with QAM sequences");
2626
buff = [0x01 0x00 0x00 0x00 0x00 0x01 0x01 0x01 ];
2727
@show bitMappingQAM(2,buff)
2828
@test all(bitMappingQAM(2,buff) .≈ [1; -1; -1; -1; -1; 1; 1; 1]);
29+
@test all(bitMappingQAM(2,buff;unitaryPower=false) .≈ [1; -1; -1; -1; -1; 1; 1; 1]);
2930
end
3031

3132
@testset "qpsk" begin
@@ -44,6 +45,7 @@ end
4445
# Some manual check due to gray coding
4546
buff = [0x01 0x00 0x00 0x00 0x00 0x01 0x01 0x01 ];
4647
@test all(bitMappingQAM(4,buff) .≈ 1/sqrt(2)*[1-1im; -1-1im; -1+1im; 1+1im]);
48+
@test all(bitMappingQAM(4,buff;unitaryPower=false) .== [1-1im; -1-1im; -1+1im; 1+1im]);
4749
end
4850

4951

@@ -62,6 +64,7 @@ end
6264
# Some manual check due to gray coding
6365
buff = [0x01 0x00 0x00 0x00 0x00 0x01 0x01 0x01 ];
6466
@test all(bitMappingQAM(mcs,buff) .≈ 1/sqrt(10)*[-3+3im;1-1im]);
67+
@test all(bitMappingQAM(mcs,buff;unitaryPower=false) .== [-3+3im;1-1im]);
6568
end
6669

6770

@@ -80,6 +83,7 @@ end
8083
# Some manual check due to gray coding
8184
buff = [0x01 0x00 0x00 0x00 0x00 0x01 0x01 0x01 0x01 0x00 0x01 0x00];
8285
@test all(bitMappingQAM(mcs,buff) .≈ 1/sqrt(42)*[-7+5im;-3-7im]);
86+
@test all(bitMappingQAM(mcs,buff;unitaryPower=false) .== [-7+5im;-3-7im]);
8387
end
8488

8589

@@ -100,4 +104,5 @@ end
100104
# Some manual check due to gray coding
101105
buff = [0x01 0x00 0x00 0x00 0x00 0x01 0x01 0x01 0x01 0x00 0x01 0x00 0x01 0x01 0x00 0x00];
102106
@test all(bitMappingQAM(mcs,buff) .≈ 1/sqrt(170)*[3-5im;9-7im]);
107+
@test all(bitMappingQAM(mcs,buff,unitaryPower=false) .== [3-5im;9-7im]);
103108
end

0 commit comments

Comments
 (0)