% better on fading channels, but increases BER slighlty for AWGN
% channels.
- sampling_points = [1 2 7 8];
+ 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(Nsymbrow, Nc*Nd);
amp_ = zeros(Nsymbrow, Nc*Nd);
% Init HF channel model from stored sample files of spreading signal ----------------------------------
-function [spread spread_2ms hf_gain] = init_hf_model(Fs, Rs, nsam)
+function [spread spread_2ms hf_gain] = init_hf_model(Fs, nsam)
- % convert "spreading" samples from 1kHz carrier at Fs to complex
+ % convert "spreading" samples from 1kHz carrier at Fss to complex
% baseband, generated by passing a 1kHz sine wave through PathSim
% with the ccir-poor model, enabling one path at a time.
- Fc = 1000; M = Fs/Rs;
+ Fc = 1000; Fss = 8000;
fspread = fopen("../raw/sine1k_2Hz_spread.raw","rb");
spread1k = fread(fspread, "int16")/10000;
fclose(fspread);
fclose(fspread);
% down convert to complex baseband
- spreadbb = spread1k.*exp(-j*(2*pi*Fc/Fs)*(1:length(spread1k))');
- spreadbb_2ms = spread1k_2ms.*exp(-j*(2*pi*Fc/Fs)*(1:length(spread1k_2ms))');
+ spreadbb = spread1k.*exp(-j*(2*pi*Fc/Fss)*(1:length(spread1k))');
+ spreadbb_2ms = spread1k_2ms.*exp(-j*(2*pi*Fc/Fss)*(1:length(spread1k_2ms))');
% remove -2000 Hz image
- b = fir1(50, 5/Fs);
+ b = fir1(50, 5/Fss);
spread = filter(b,1,spreadbb);
spread_2ms = filter(b,1,spreadbb_2ms);
spread = spread(1000:length(spread));
spread_2ms = spread_2ms(1000:length(spread_2ms));
- % decimate down to Rs
+ % change output samples so they are at rate Fs reqd by caller
- spread = spread(1:M:length(spread));
- spread_2ms = spread_2ms(1:M:length(spread_2ms));
+ spread = resample(spread, Fs, Fss);
+ spread_2ms = resample(spread_2ms, Fs, Fss);
% Determine "gain" of HF channel model, so we can normalise
% carrier power during HF channel sim to calibrate SNR. I imagine
% sample pilots at start of this frame and start of next frame
- sampling_points = [1 2 7 8];
+ sampling_points = [1 2 cohpsk.Nsymbrow+3 cohpsk.Nsymbrow+4];
pilot2 = [ cohpsk.pilot(1,:); cohpsk.pilot(2,:); cohpsk.pilot(1,:); cohpsk.pilot(2,:);];
if sync == 0
f_off = sim_in.f_off;
div_time_shift = sim_in.div_timeshift;
- [spread spread_2ms hf_gain] = init_hf_model(Fs, Rs, Nsymbrowpilot*(Ntrials+2));
+ [spread spread_2ms hf_gain] = init_hf_model(Rs, Nsymbrowpilot*(Ntrials+2));
if strcmp(modulation,'dqpsk')
Nsymbrowpilot = Nsymbrow;
% select which test ----------------------------------------------------------
%test = 'compare to c';
-test = 'awgn';
-%test = 'fading';
+%test = 'awgn';
+test = 'fading';
% some parameters that can be over ridden, e.g. to disable parts of modem
% should be BER around 0.015 to 0.02
if strcmp(test, 'awgn')
- frames = 10;
+ frames = 100;
foff = 0;
dfoff = 0;
- EsNodB = 80;
+ EsNodB = 8;
fading_en = 0;
hf_delay_ms = 2;
compare_with_c = 0;
if strcmp(test, 'fading');
frames = 100;
- foff = -52.3;
+ foff = -53.1;
dfoff = 0.5/Fs;
EsNodB = 12;
fading_en = 1;
% modem constants ----------------------------------------------------------
Rs = 75; % symbol rate in Hz
-Nc = 4; % number of carriers
+Nc = 7; % number of carriers
Nd = 2; % diveristy factor
-framesize = 32; % number of payoad data bits in the frame
+framesize = 56; % number of payload data bits in the frame
Nsw = 3; % frames we demod for initial sync window
afdmdv.Nsym = 6; % size of tx/tx root nyquist filter in symbols
afdmdv.Nt = 5; % number of symbols we estimate timing over
+clip = 6.5; % Clipping of tx signal to reduce PAPR. Adjust by
+ % experiment as Nc and Nd change. Check out no noise
+ % scatter diagram and AWGN/fading BER perf
+ % at operating points
+
% FDMDV init ---------------------------------------------------------------
Fs = afdmdv.Fs = 7500;
afdmdv.Nc = Nd*Nc-1;
afdmdv.Rs = Rs;
+if Fs/afdmdv.Rs != floor(Fs/afdmdv.Rs)
+ printf("\n Oops, Fs/Rs must be an integer!\n\n");
+ return
+end
+
M = afdmdv.M = afdmdv.Fs/afdmdv.Rs;
afdmdv.Nfilter = afdmdv.Nsym*M;
afdmdv.tx_filter_memory = zeros(afdmdv.Nc+1, afdmdv.Nfilter);
afdmdv.Nfilter = afdmdv.Nsym*afdmdv.M;
afdmdv.rx_fdm_mem = zeros(1,afdmdv.Nfilter + afdmdv.M);
Q = afdmdv.Q = afdmdv.M/4;
+if Q != floor(Q)
+ printf("\n Yeah .... if (Fs/Rs)/4 = M/4 isn't an integer we will just go and break things.\n\n");
+end
afdmdv.rx_filter_mem_timing = zeros(afdmdv.Nc+1, afdmdv.Nt*afdmdv.P);
afdmdv.Nfiltertiming = afdmdv.M + afdmdv.Nfilter + afdmdv.M;
ptx_bits_coh = 1;
Nerrs = Tbits = 0;
-prev_tx_bits = [];
+prev_tx_bits = prev_tx_bits2 = [];
phase_ch = 1;
sync = initial_sync;
acohpsk.ct = 4;
acohpsk.ftrack_en = ftrack_en;
-[spread spread_2ms hf_gain] = init_hf_model(Fs, Fs, frames*acohpsk.Nsymbrowpilot*afdmdv.M);
+[spread spread_2ms hf_gain] = init_hf_model(Fs, frames*acohpsk.Nsymbrowpilot*afdmdv.M);
hf_n = 1;
nhfdelay = floor(hf_delay_ms*Fs/1000);
ch_fdm_delay = zeros(1, acohpsk.Nsymbrowpilot*M + nhfdelay);
tx_fdm_frame = [tx_fdm_frame tx_fdm];
end
- clip = 5;
ind = find(abs(tx_fdm_frame) > clip);
tx_fdm_frame(ind) = clip*exp(j*angle(tx_fdm_frame(ind)));
papr = max(tx_fdm_frame_log.*conj(tx_fdm_frame_log)) / mean(tx_fdm_frame_log.*conj(tx_fdm_frame_log));
papr_dB = 10*log10(papr);
- printf("av tx pwr: %f PAPR: %4.2f dB av rx pwr: %f\n", var(tx_fdm_frame_log), papr_dB, var(ch_fdm_frame_log));
+ printf("av tx pwr: %4.2f PAPR: %4.2f av rx pwr: %4.2f\n", var(tx_fdm_frame_log), papr_dB, var(ch_fdm_frame_log));
% some other useful plots
title('tx fdm imag');
figure(2)
- clf;
- plot(rx_symb_log*exp(j*pi/4),'+')
- title('Scatter');
+ clf
+ spec = 20*log10(abs(fft(tx_fdm_frame_log)));
+ l = length(spec);
+ plot((Fs/l)*(1:l), spec)
+ axis([1 Fs/2 0 max(spec)]);
+ title('tx spectrum');
+ ylabel('Amplitude (dB)')
+ xlabel('Frequency (Hz)')
+ grid;
figure(3)
clf;
- plot(rx_timing_log)
- title('rx timing');
+ plot(rx_symb_log*exp(j*pi/4),'+')
+ title('Scatter');
figure(4)
clf;
- stem(nerr_log)
- title('Bit Errors');
+ subplot(211)
+ plot(rx_phi_log)
+ subplot(212)
+ plot(rx_amp_log)
figure(5)
clf;
+ subplot(211)
+ plot(rx_timing_log)
+ title('rx timing');
+ subplot(212)
stem(ratio_log)
title('Sync ratio');
- figure(6);
+ figure(6)
+ clf;
+ stem(nerr_log)
+ title('Bit Errors');
+
+ figure(7);
clf;
subplot(211)
plot(foff_log,';freq offset;');
plot(foff_log(1:length(f_est_log)) - f_est_log + Fcentre)
title('freq offset estimation error');
- figure(7)
- clf
- spec = 20*log10(abs(fft(tx_fdm_frame_log)));
- l = length(spec);
- plot((Fs/l)*(1:l), spec)
- axis([1 Fs/2 0 max(spec)]);
- title('tx spectrum');
- ylabel('Amplitude (dB)')
- xlabel('Frequency (Hz)')
end