function [tx_symb tx_bits] = bits_to_qpsk_symbols(sim_in, tx_bits, code_param)
+ ldpc_code = sim_in.ldpc_code;
+ rate = sim_in.ldpc_code_rate;
framesize = sim_in.framesize;
Nsymbrow = sim_in.Nsymbrow;
Nsymbrowpilot = sim_in.Nsymbrowpilot;
pilot = sim_in.pilot;
Nd = sim_in.Nd;
+ if ldpc_code
+ [tx_bits, tmp] = ldpc_enc(tx_bits, code_param);
+ end
+
% modulate --------------------------------------------
% organise symbols into a Nsymbrow rows by Nc cols
sampling_points = [1 2 cohpsk.Nsymbrow+3 cohpsk.Nsymbrow+4];
pilot2 = [cohpsk.pilot(1,:); cohpsk.pilot(2,:); cohpsk.pilot(1,:); cohpsk.pilot(2,:);];
- phi_ = zeros(Nsymbrowpilot, Nc*Nd);
+ phi_ = zeros(Nsymbrow, Nc*Nd);
amp_ = zeros(Nsymbrow, Nc*Nd);
for c=1:Nc*Nd
y = ct_symb_buf(sampling_points,c) .* pilot2(:,c-Nc*floor((c-1)/Nc));
[m b] = linreg(sampling_points, y, length(sampling_points));
- yfit = m*[1 2 3 4 5 6] + b;
+ yfit = m*[3 4 5 6] + b;
phi_(:, c) = angle(yfit);
%for r=1:Nsymbrow
% printf(" %f", phi_(r,c));
rx_symb_linear = zeros(1, Nsymbrow*Nc*Nd);
rx_bits = zeros(1, framesize);
for c=1:Nc*Nd
- for r=1:Nsymbrowpilot
+ for r=1:Nsymbrow
if coh_en == 1
- rx_symb(r,c) = ct_symb_buf(r,c)*exp(-j*phi_(r,c));
+ rx_symb(r,c) = ct_symb_buf(2+r,c)*exp(-j*phi_(r,c));
else
- rx_symb(r,c) = ct_symb_buf(r,c);
- end
- i = (c-1)*Nsymbrow + r - Npilotsframe;
- if r > Npilotsframe
- rx_symb_linear(i) = rx_symb(r,c);
+ rx_symb(r,c) = ct_symb_buf(2+r,c);
end
+ i = (c-1)*Nsymbrow + r;
+ rx_symb_linear(i) = rx_symb(r,c);
%printf("phi_ %d %d %f %f\n", r,c,real(exp(-j*phi_(r,c))), imag(exp(-j*phi_(r,c))));
end
end
- % and finally optional diversity combination and make decn on data and pilot bits
+ % and finally optional diversity combination and make decn on bits
- tx_pilot_bits = rx_pilot_bits = zeros(Npilotsframe*Nc,1);
for c=1:Nc
- for r=1:Nsymbrowpilot
+ for r=1:Nsymbrow
+ i = (c-1)*Nsymbrow + r;
div_symb = rx_symb(r,c);
for d=1:Nd-1
div_symb += rx_symb(r,c + Nc*d);
end
- if r > Npilotsframe
- % data symbols, ouput of demod
- i = (c-1)*Nsymbrow + r - Npilotsframe;
- rx_bits((2*(i-1)+1):(2*i)) = qpsk_demod(div_symb);
- else
- % demodulated pilot symbols, which we can use to estimate BER
- %printf("%d %d (%f %f) (%f %f)\n", r, c, real(div_symb), imag(div_symb), real(cohpsk.pilot(r,c)), imag(cohpsk.pilot(r,c)));
- i = (c-1)*Npilotsframe + r;
- tx_pilot_bits((2*(i-1)+1):(2*i)) = qpsk_demod(cohpsk.pilot(r,c));
- rx_pilot_bits((2*(i-1)+1):(2*i)) = qpsk_demod(div_symb);
- end
+ rx_bits((2*(i-1)+1):(2*i)) = qpsk_demod(div_symb);
end
end
- % estimate BER from pilot bits
-
- cohpsk.npilotbits += Npilotsframe*Nc;
- nerr = sum(xor(tx_pilot_bits, rx_pilot_bits));
- cohpsk.npilotbiterrors += nerr;
-
% Estimate noise power from demodulated symbols. One method is to
% calculate the distance of each symbol from the average symbol
% position. However this is complicated by fading, which means the
ct_symb_buf = zeros(2*Nsymbrowpilot, Nc*Nd);
prev_tx_symb = prev_rx_symb = ones(1, Nc*Nd);
-
+
% simulation starts here-----------------------------------
for nn = 1:Ntrials+2
- printf("%d %d\n", nn, sim_in.framesize);
-
+
if ldpc_code
tx_bits = round(rand(1,framesize*rate));
else
tx_bits = round(rand(1,framesize));
end
-
+
if strcmp(modulation,'qpsk')
[tx_symb tx_bits] = bits_to_qpsk_symbols(sim_in, tx_bits, code_param);
tx_bits_buf(1:framesize) = tx_bits;
end
- printf("b\n");
s_ch = tx_symb;
% HF channel simulation ------------------------------------
end
end
- printf("c\n");
-
% keep a record of each tx symbol so we can check average power
for r=1:Nsymbrow
ct_symb_buf(Nsymbrowpilot+1:2*Nsymbrowpilot,:) = s_ch;
if strcmp(modulation,'qpsk')
- [rx_symb rx_bits rx_symb_linear amp_ phi_] = qpsk_symbols_to_bits(sim_in, ct_symb_buf(1:Nsymbrowpilot+Npilotsframe,:));
+ [rx_symb rx_bits rx_symb_linear amp_ phi_ EsNo_ sim_in] = qpsk_symbols_to_bits(sim_in, ct_symb_buf(1:Nsymbrowpilot+Npilotsframe,:));
phi_log = [phi_log; phi_];
amp_log = [amp_log; amp_];
end
[rx_symb rx_bits rx_symb_linear prev_rx_symb] = dqpsk_symbols_to_bits(sim_in, s_ch, prev_rx_symb);
end
- printf("d\n");
% Wait until we have enough frames to do pilot assisted phase estimation
if nn > 1
Tbitsldpc += framesize*rate;
end
end
-
- printf("e\n");
- end % 1:Ntrials
-
- printf("f\n");
+ end
+
TERvec(ne) = Terrs;
BERvec(ne) = Terrs/Tbits;
- if verbose
+ if verbose
av_tx_pwr = (s_ch_tx_log * s_ch_tx_log')/length(s_ch_tx_log);
printf("EsNo (dB): %3.1f Terrs: %d Tbits: %d BER %5.3f QPSK BER theory %5.3f av_tx_pwr: %3.2f",
end
printf("\n");
end
-
end
Ebvec = Esvec - 10*log10(bps);
% tcohpsk.m
% David Rowe Oct 2014
%
-% Octave coherent PSK modem script that has two modes:
+% Octave coherent PSK modem script that hs two modes:
%
% i) tests the C port of the coherent PSK modem. This script loads
% the output of unittest/tcohpsk.c and compares it to the output of
% select which test ----------------------------------------------------------
-%test = 'compare to c';
-test = 'awgn';
+test = 'compare to c';
+%test = 'awgn';
%test = 'fading';
% some parameters that can be over ridden, e.g. to disable parts of modem
afdmdv.Fsep = afdmdv.Rs*(1+excess_bw);
afdmdv.phase_tx = ones(afdmdv.Nc+1,1);
% non linear carrier spacing, combined with clip, helps PAPR a lot!
-%freq_hz = afdmdv.Fsep*( -Nc*Nd/2 - 0.5 + (1:Nc*Nd).^0.98 )
+freq_hz = afdmdv.Fsep*( -Nc*Nd/2 - 0.5 + (1:Nc*Nd).^0.98 )
afdmdv.freq_pol = 2*pi*freq_hz/Fs;
afdmdv.freq = exp(j*afdmdv.freq_pol);
afdmdv.Fcentre = 1500;
acohpsk = symbol_rate_init(acohpsk);
acohpsk.Ndft = 1024;
acohpsk.f_est = afdmdv.Fcentre;
-acohpsk.npilotbits = 0;
-acohpsk.npilotbiterrors = 0;
ch_fdm_frame_buf = zeros(1, Nsw*acohpsk.Nsymbrowpilot*afdmdv.M);
% if we are in sync complete demodulation with symbol rate processing
if (next_sync == 1) || (sync == 1)
- [rx_symb rx_bits rx_symb_linear amp_ phi_ sig_rms noise_rms acohpsk] = qpsk_symbols_to_bits(acohpsk, acohpsk.ct_symb_ff_buf);
+ [rx_symb rx_bits rx_symb_linear amp_ phi_ sig_rms noise_rms] = 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
ber = Nerrs/Tbits;
-printf("\nOctave EsNodB: %4.1f BER......: %4.3f Nerrs..: %d Tbits..: %d\n", EsNodB, ber, Nerrs, Tbits);
-pilot_ber = acohpsk.npilotbiterrors/acohpsk.npilotbits;
-printf(" Pilot BER: %4.3f Nerrs..: %d Tbits..: %d\n", pilot_ber, acohpsk.npilotbiterrors, acohpsk.npilotbits);
+printf("\nOctave EsNodB: %4.1f ber..: %4.3f Nerrs..: %d Tbits..: %d\n", EsNodB, ber, Nerrs, Tbits);
if compare_with_c