sim_in.ff_phase = 1;
+ sim_in.ct_symb_ff_buf = zeros(Nsymbrowpilot + 2, Nc);
+
% Init LDPC --------------------------------------------------------------------
if ldpc_code
endfunction
+% fine freq correction
+
+function acohpsk = fine_freq_correct(acohpsk, sync, next_sync);
+ ct_symb_ff_buf = acohpsk.ct_symb_ff_buf;
+
+ % We can decode first frame that we achieve sync. Need to fine freq
+ % correct all of it's symbols, including pilots. From then on, just
+ % correct new symbols into frame. make copy, so if we lose sync we
+ % havent fine freq corrected ct_symb_buf if next_sync == 4 correct
+ % all 8 if sync == 2 correct latest 6
+
+ if (next_sync == 4) || (sync == 4)
+
+ if next_sync == 4
+
+ % first frame, we've just gotten sync so fine freq correct all Nsymbrowpilot+2 samples
+
+ ct_symb_ff_buf = acohpsk.ct_symb_buf(acohpsk.ct+1:acohpsk.ct+acohpsk.Nsymbrowpilot+2,:);
+ for r=1:acohpsk.Nsymbrowpilot+2
+ acohpsk.ff_phase *= acohpsk.ff_rect';
+ ct_symb_ff_buf(r,:) *= acohpsk.ff_phase;
+ end
+
+ else
+
+ % second and subsequent frames, just fine freq correct the latest Nsymbrowpilot
+
+ ct_symb_ff_buf(1:2,:) = ct_symb_ff_buf(Nsymbrowpilot+1:Nsymbrowpilot+2,:);
+ ct_symb_ff_buf(3:Nsymbrowpilot+2,:) = acohpsk.ct_symb_buf(acohpsk.ct+3:acohpsk.ct+acohpsk.Nsymbrowpilot+2,:);
+ for r=3:acohpsk.Nsymbrowpilot+2
+ afdmdv.ff_phase *= afdmdv.ff_rect';
+ ct_symb_ff_buf(r,:) *= afdmdv.ff_phase;
+ end
+
+ end
+
+ mag = abs(acohpsk.ff_phase);
+ acohpsk.ff_phase /= mag;
+
+ acohpsk.ct_symb_ff_buf = ct_symb_ff_buf;
+ end
+endfunction
+
+
+% misc sync state machine code, just wanted it in a function
+
+function sync = sync_state_machine(sync, next_sync)
+ if sync == 1
+ next_sync = 2;
+ end
+ sync = next_sync;
+endfunction
+
+
% Rate Rs BER tests ------------------------------------------------------------------------------
function sim_out = ber_test(sim_in)
[next_sync acohpsk] = frame_sync_fine_timing_est(acohpsk, ch_symb, sync, next_sync);
%acohpsk.ff_rect = exp(j*2*pi*(-1.0)/Rs);
- if sync == 1
- next_sync = 2;
- end
-
- %printf("i: %d sync: %d next_sync: %d\n", i, sync, next_sync);
- sync = next_sync;
-
if (i==1000)
xx
end
- % We can decode first that we get sync on. Need to fine freq correct all of it's symbols,
- % including pilots. From then on, just correct new symbols into frame.
- % make copy, so if we lose sync we havent fine freq corrected ct_symb_buf
- % if next_sync == 4 correct all 8
- % if sync == 2 correct latest 6
-
- if (next_sync == 4) || (sync == 4)
-
- if next_sync == 4
-
- % first frame, we've just gotten sync so fine freq correct all Nsymbrowpilot+2 samples
-
- ct_symb_ff_buf = acohpsk.ct_symb_buf(acohpsk.ct+1:acohpsk.ct+acohpsk.Nsymbrowpilot+2,:);
- for r=1:acohpsk.Nsymbrowpilot+2
- acohpsk.ff_phase *= acohpsk.ff_rect';
- ct_symb_ff_buf(r,:) *= acohpsk.ff_phase;
- end
+ acohpsk = fine_freq_correct(acohpsk, sync, next_sync);
- else
-
- % second and subsequent frames, just fine freq correct the latest Nsymbrowpilot
-
- ct_symb_ff_buf(1:2,:) = ct_symb_ff_buf(Nsymbrowpilot+1:Nsymbrowpilot+2,:);
- ct_symb_ff_buf(3:Nsymbrowpilot+2,:) = acohpsk.ct_symb_buf(acohpsk.ct+3:acohpsk.ct+acohpsk.Nsymbrowpilot+2,:);
- for r=3:acohpsk.Nsymbrowpilot+2
- afdmdv.ff_phase *= afdmdv.ff_rect';
- ct_symb_ff_buf(r,:) *= afdmdv.ff_phase;
- end
-
- end
-
- mag = abs(acohpsk.ff_phase);
- acohpsk.ff_phase /= mag;
-
- [rx_symb rx_bits amp_ phi_ EsNo_] = qpsk_symbols_to_bits(acohpsk, ct_symb_ff_buf);
+ if (sync == 4) || (next_sync == 4)
+ [rx_symb rx_bits amp_ phi_ EsNo_] = qpsk_symbols_to_bits(acohpsk, acohpsk.ct_symb_ff_buf);
rx_symb_log = [rx_symb_log; rx_symb];
rx_amp_log = [rx_amp_log; amp_];
rx_phi_log = [rx_phi_log; phi_];
end
end
+ sync = sync_state_machine(sync, next_sync);
+
prev_tx_bits2 = prev_tx_bits;
prev_tx_bits = tx_bits;