File: gp_interleaver.m

package info (click to toggle)
codec2 1.2.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 76,376 kB
  • sloc: ansic: 436,819; cpp: 2,091; objc: 1,736; sh: 1,510; python: 1,405; asm: 683; makefile: 605
file content (46 lines) | stat: -rw-r--r-- 1,029 bytes parent folder | download | duplicates (5)
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
% gp_interleaver.m
%
% David Rowe May 2017
%
% Golden Prime Interleaver. My interprestation of "On the Analysis and
% Design of Good Algebraic Interleavers", Xie et al,eq (5).

1;

% Choose b for Golden Prime Interleaver.  b is chosen to be the
% closest integer, which is relatively prime to N, to the Golden
% section of N.

function b = choose_interleaver_b(Nbits)

  p = primes(Nbits);
  i = 1;
  while(p(i) < Nbits/1.62)
    i++;
  end
  b = p(i);
  assert(gcd(b,Nbits) == 1, "b and Nbits must be co-prime");
end


function interleaved_frame = gp_interleave(frame)
  Nbits = length(frame);
  b = choose_interleaver_b(Nbits);
  interleaved_frame = zeros(1,Nbits);
  for i=1:Nbits
    j = mod((b*(i-1)), Nbits);
    interleaved_frame(j+1) = frame(i);
  end
endfunction


function frame = gp_deinterleave(interleaved_frame)
  Nbits = length(interleaved_frame);
  b = choose_interleaver_b(Nbits);
  frame = zeros(1,Nbits);
  for i=1:Nbits
    j = mod((b*(i-1)), Nbits);
    frame(i) = interleaved_frame(j+1);
  end
endfunction