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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
program test_jtty_tbcc_decoder
use, intrinsic :: iso_fortran_env, only: int32, int64, real32
use jtty_tbcc_code_profiles, only: JTTY_TBCC_PROFILE_1167_1545_80F
use jtty_tbcc_decoder, only: jtty_tbcc_decode, jtty_tbcc_decode_result
use tbcc, only: PAYLOAD_BITS, TOTAL_K, tbcc_encode
implicit none
complex(real32) :: correlations(0:3, TOTAL_K), halves(0:3, TOTAL_K)
integer(int32) :: payload(PAYLOAD_BITS), decoded(PAYLOAD_BITS), tones(TOTAL_K)
type(jtty_tbcc_decode_result) :: result
logical :: success
integer(int32) :: bit_index
do bit_index = 1, PAYLOAD_BITS
payload(bit_index) = modulo(bit_index + bit_index/3, 2)
end do
payload(33) = 0_int32
halves = cmplx(0.0_real32, 0.0_real32, real32)
call tbcc_encode(payload, tones, JTTY_TBCC_PROFILE_1167_1545_80F)
call make_noiseless_correlations(tones, correlations)
call jtty_tbcc_decode(correlations, halves, decoded, success, result)
call require(success, 'coherence ladder rejected a noiseless payload')
call require(all(decoded == payload), 'coherence ladder changed the payload')
call require(result%accepted_hypothesis_rank == 1_int32, &
'noiseless payload was not the first hypothesis')
call require(result%coherent_block_length == 1_int32, &
'noiseless payload did not stop at one-symbol coherence')
call require(result%evaluated_rung_count == 1_int32, &
'noiseless payload evaluated unnecessary coherence rungs')
call require(.not.result%used_half_symbol_observation, &
'rank-one payload unexpectedly evaluated half-symbol fallback')
call require(result%exported_candidate_count <= 4_int32, &
'coherence ladder exposed more than four hypotheses per rung')
payload(33) = 1_int32
call tbcc_encode(payload, tones, JTTY_TBCC_PROFILE_1167_1545_80F)
call make_noiseless_correlations(tones, correlations)
decoded = huge(0_int32)
call jtty_tbcc_decode(correlations, halves, decoded, success, result)
call require(.not.success, 'coherence ladder accepted reserved bit one')
call require(all(decoded == 0_int32), &
'reserved-bit rejection left a stale payload')
halves = correlations
correlations = cmplx(0.0_real32, 0.0_real32, real32)
decoded = huge(0_int32)
call jtty_tbcc_decode(correlations, halves, decoded, success, result)
call require(.not.success, 'half-symbol fallback accepted reserved bit one')
call require(all(decoded == 0_int32), &
'half-symbol reserved-bit rejection left a stale payload')
payload(33) = 0_int32
call tbcc_encode(payload, tones, JTTY_TBCC_PROFILE_1167_1545_80F)
call make_noiseless_correlations(tones, halves)
decoded = huge(0_int32)
call jtty_tbcc_decode(correlations, halves, decoded, success, result)
call require(success .and. all(decoded == payload), 'half-symbol fallback failed to rescue payload')
call require(result%used_half_symbol_observation .and. result%coherent_block_length == 1, &
'half-symbol fallback used the wrong observation or coherence')
call require(result%evaluated_rung_count == 4, 'fallback skipped an M1 rung')
halves = cmplx(0.0_real32, 0.0_real32, real32)
payload = 0_int32
call tbcc_encode(payload, tones, JTTY_TBCC_PROFILE_1167_1545_80F)
call make_noiseless_correlations(tones, correlations)
decoded = huge(0_int32)
call jtty_tbcc_decode(correlations, halves, decoded, success, result)
call require(.not.success, 'coherence ladder accepted the all-zero payload')
call require(all(decoded == 0_int32), 'failed ladder decode left stale payload')
call require(result%evaluated_rung_count == 4_int32, &
'failed decode did not report all evaluated rungs')
correlations = cmplx(0.0_real32, 0.0_real32, real32)
decoded = huge(0_int32)
call jtty_tbcc_decode(correlations, halves, decoded, success, result)
call require(.not.success, 'coherence ladder accepted flat correlations')
call require(all(decoded == 0_int32), 'flat-correlation decode left stale payload')
call require(result%evaluated_rung_count == 4_int32, &
'flat-correlation decode did not report all evaluated rungs')
call expect_coherent_decodes()
print *, 'test_jtty_tbcc_decoder: all checks passed'
contains
subroutine expect_coherent_decodes()
! Seed 6 verifies that reserved-bit pruning retains the valid L1 path.
integer(int32), parameter :: seeds(2) = [2,6], lengths(2) = [2,1], &
ranks(2) = [2,1], evaluated_rungs(2) = [2,1]
integer(int64) :: state
integer :: fixture, symbol, tone, bit
real(real32) :: in_phase, quadrature
do bit = 1, PAYLOAD_BITS
payload(bit) = modulo(bit + bit/3,2)
end do
payload(33) = 0
call tbcc_encode(payload,tones,JTTY_TBCC_PROFILE_1167_1545_80F)
halves = cmplx(0.0_real32,0.0_real32,real32)
do fixture = 1, size(seeds)
state = seeds(fixture)
do symbol = 1, TOTAL_K
do tone = 0, 3
state = modulo(48271_int64*state,2147483647_int64)
in_phase = real(state,real32)/2147483647.0_real32 - 0.5_real32
state = modulo(48271_int64*state,2147483647_int64)
quadrature = real(state,real32)/2147483647.0_real32 - 0.5_real32
correlations(tone,symbol) = cmplx(in_phase,quadrature,real32)
end do
correlations(tones(symbol),symbol) = correlations(tones(symbol),symbol) + &
cmplx(0.55_real32,0.0_real32,real32)
end do
call jtty_tbcc_decode(correlations,halves,decoded,success,result)
call require(success .and. all(decoded == payload),'coherent rung failed to decode fixed payload')
call require(result%coherent_block_length == lengths(fixture), 'coherent decode used wrong rung')
call require(result%accepted_hypothesis_rank == ranks(fixture), 'coherent decode candidate rank changed')
call require(result%evaluated_rung_count == evaluated_rungs(fixture), &
'accepted candidate triggered unnecessary confirmation or fallback')
call require(.not.result%used_half_symbol_observation, 'coherent decode fell through to M2')
end do
end subroutine expect_coherent_decodes
subroutine make_noiseless_correlations(symbols, values)
integer(int32), intent(in) :: symbols(TOTAL_K)
complex(real32), intent(out) :: values(0:3, TOTAL_K)
integer(int32) :: symbol
values = cmplx(0.0_real32, 0.0_real32, real32)
do symbol = 1, TOTAL_K
values(symbols(symbol), symbol) = cmplx(100.0_real32, 0.0_real32, real32)
end do
end subroutine make_noiseless_correlations
subroutine require(condition, message)
logical, intent(in) :: condition
character(len=*), intent(in) :: message
if (.not.condition) error stop message
end subroutine require
end program test_jtty_tbcc_decoder
|