1% gp_interleaver.m 2% 3% David Rowe May 2017 4% 5% Golden Prime Interleaver. My interprestation of "On the Analysis and 6% Design of Good Algebraic Interleavers", Xie et al,eq (5). 7 81; 9 10% Choose b for Golden Prime Interleaver. b is chosen to be the 11% closest integer, which is relatively prime to N, to the Golden 12% section of N. 13 14function b = choose_interleaver_b(Nbits) 15 16 p = primes(Nbits); 17 i = 1; 18 while(p(i) < Nbits/1.62) 19 i++; 20 end 21 b = p(i); 22 assert(gcd(b,Nbits) == 1, "b and Nbits must be co-prime"); 23end 24 25 26function interleaved_frame = gp_interleave(frame) 27 Nbits = length(frame); 28 b = choose_interleaver_b(Nbits); 29 interleaved_frame = zeros(1,Nbits); 30 for i=1:Nbits 31 j = mod((b*(i-1)), Nbits); 32 interleaved_frame(j+1) = frame(i); 33 end 34endfunction 35 36 37function frame = gp_deinterleave(interleaved_frame) 38 Nbits = length(interleaved_frame); 39 b = choose_interleaver_b(Nbits); 40 frame = zeros(1,Nbits); 41 for i=1:Nbits 42 j = mod((b*(i-1)), Nbits); 43 frame(i) = interleaved_frame(j+1); 44 end 45endfunction 46 47