1% fsk_lib_ldpc_tx.m
2%
3% LDPC coded 4FSK modem tx, generates a 8 kHz 16 bit short real valued sample file
4
5function fsk_lib_ldpc_tx(filename, num_frames=10, Rs=100, coderate=0.5, EbNodB=100)
6  fsk_lib_ldpc;
7
8  % set up LDPC code
9  init_cml();
10  if coderate == 0.5
11    load H_256_512_4.mat;
12  elseif coderate == 0.75
13    load HRAa_1536_512.mat; H=HRA;
14  else
15    disp("unknown code rate");
16  end
17  [states code_param] = fsk_lib_ldpc_init (H, Rs, Fs=8000);
18  n = code_param.coded_bits_per_frame; k = code_param.data_bits_per_frame;
19
20  rand('seed',1);
21  data_bits = round(rand(1,code_param.data_bits_per_frame)); tx_bits = [];
22  for f=1:num_frames
23    codeword_bits = LdpcEncode(data_bits, code_param.H_rows, code_param.P_matrix);
24    tx_bits = [tx_bits codeword_bits];
25  end
26
27  tx = fsk_mod(states, tx_bits);
28
29  % set up (optional) AWGN noise
30  EcNodB = EbNodB + 10*log10(states.rate);
31  EcNo = 10^(EcNodB/10);
32  variance = states.Fs/(states.Rs*EcNo*states.bitspersymbol);
33
34  % note real noise
35  noise = sqrt(variance/2)*randn(length(tx),1);
36  rx = tx + noise;
37
38  frx=fopen(filename,"wb"); fwrite(frx, states.amp_scale*rx, "short"); fclose(frx);
39  printf("Fs: %d Rs: %d rate %4.2f (%d,%d) EbNodB: %3.1f  EcNodB: %3.1f frames transmitted: %3d\n",
40  Fs, Rs, coderate, n, k, EbNodB, EcNodB, num_frames);
41end
42
43
44
45