% shifting for the purpose of testing easier
tx_fdm = 2*tx_fdm;
+
+ % normalise digital oscilators as the magnitude can drift over time
+
+ for c=1:Nc+1
+ mag = abs(phase_tx(c));
+ phase_tx(c) /= mag;
+ end
+
endfunction
% LPF and peak pick part of freq est, put in a function as we call it twice
-function [foff imax pilot_lpf S] = lpf_peak_pick(pilot_baseband, pilot_lpf, nin)
+function [foff imax pilot_lpf_out S] = lpf_peak_pick(pilot_baseband, pilot_lpf, nin)
global M;
global Npilotlpf;
+ global Npilotbaseband;
global Npilotcoeff;
global Fs;
global Mpilotfft;
% LPF cutoff 200Hz, so we can handle max +/- 200 Hz freq offset
pilot_lpf(1:Npilotlpf-nin) = pilot_lpf(nin+1:Npilotlpf);
- j = 1;
+ j = Npilotcoeff+1;
for i = Npilotlpf-nin+1:Npilotlpf
- pilot_lpf(i) = pilot_baseband(j:j+Npilotcoeff-1) * pilot_coeff';
+ pilot_lpf(i) = pilot_baseband(j-Npilotcoeff+1:j) * pilot_coeff';
+ %pilot_lpf(i) = pilot_baseband(j-Npilotcoeff+1);
j++;
end
foff = (ix - 1)*r;
endif
+ pilot_lpf_out = pilot_lpf;
+
endfunction
global pilot_lpf1;
global pilot_lpf2;
- % down convert latest nin samples of pilot by multiplying by
- % ideal BPSK pilot signal we have generated locally. This
- % peak of the resulting signal is sensitive to the time shift between
- % the received and local version of the pilot, so we do it twice at
+ % down convert latest nin samples of pilot by multiplying by ideal
+ % BPSK pilot signal we have generated locally. The peak of the DFT
+ % of the resulting signal is sensitive to the time shift between the
+ % received and local version of the pilot, so we do it twice at
% different time shifts and choose the maximum.
pilot_baseband1(1:Npilotbaseband-nin) = pilot_baseband1(nin+1:Npilotbaseband);
% Version 2
%
-NumCarriers = 20;
+NumCarriers = 14;
fdmdv; % load modem code
% Generate reference vectors using Octave implementation of FDMDV modem
foff_phase_rect = 1;
coarse_fine = 0;
fest_state = 0;
-channel = zeros(1,10*M);
+channel = [];
channel_count = 0;
next_nin = M;
sig_est = zeros(Nc+1,1);
%else
% nin = M;
%end
+ nin = M;
channel = [channel real(tx_fdm)];
channel_count += M;
rx_fdm = channel(1:nin);
[pilot prev_pilot pilot_lut_index prev_pilot_lut_index] = get_pilot(pilot_lut_index, prev_pilot_lut_index, nin);
[foff_coarse S1 S2] = rx_est_freq_offset(rx_fdm, pilot, prev_pilot, nin);
- if coarse_fine == 0
+ foff_coarse = 0;
+ sync = 0;
+ if sync == 0
foff = foff_coarse;
end
foff_coarse_log = [foff_coarse_log foff_coarse];
% freq est state machine
- [coarse_fine fest_state] = freq_state(sync_bit, fest_state);
- coarse_fine_log = [coarse_fine_log coarse_fine];
+ [sync fest_state] = freq_state(sync_bit, fest_state);
+ sync_log = [coarse_fine_log sync];
end
% Compare to the output from the C version
function stem_sig_and_error(plotnum, subplotnum, sig, error, titlestr, axisvec)
figure(plotnum)
subplot(subplotnum)
- stem(sig);
+ stem(sig,'g;C version;');
hold on;
- stem(error,'g');
+ stem(error,'r;Error between C and Octave;');
hold off;
if nargin == 6
axis(axisvec);
function plot_sig_and_error(plotnum, subplotnum, sig, error, titlestr, axisvec)
figure(plotnum)
subplot(subplotnum)
- plot(sig);
+ plot(sig,'g;C version;');
hold on;
- plot(error,'g');
+ plot(error,'r;Error between C and Octave;');
hold off;
if nargin == 6
axis(axisvec);
% tx_filter()
diff = tx_baseband_log - tx_baseband_log_c;
-c=15;
-plot_sig_and_error(2, 211, real(tx_baseband_log_c(c,:)), real(sum(diff)), 'tx baseband real')
-plot_sig_and_error(2, 212, imag(tx_baseband_log_c(c,:)), imag(sum(diff)), 'tx baseband imag')
+c=1;
+plot_sig_and_error(2, 211, real(tx_baseband_log_c(c,:)), real(tx_baseband_log(c,:) - tx_baseband_log_c(c,:)), 'tx baseband real')
+plot_sig_and_error(2, 212, imag(tx_baseband_log_c(c,:)), imag(tx_baseband_log(c,:) - tx_baseband_log_c(c,:)), 'tx baseband imag')
% fdm_upconvert()
% rx_est_freq_offset()
-st=1; en = 3*Npilotbaseband;
+st=1; en = 5*Npilotbaseband;
plot_sig_and_error(5, 211, real(pilot_baseband1_log(st:en)), real(pilot_baseband1_log(st:en) - pilot_baseband1_log_c(st:en)), 'pilot baseband1 real' )
plot_sig_and_error(5, 212, real(pilot_baseband2_log(st:en)), real(pilot_baseband2_log(st:en) - pilot_baseband2_log_c(st:en)), 'pilot baseband2 real' )
-st=1; en = 3*Npilotlpf;
+st=1; en = 5*Npilotlpf;
plot_sig_and_error(6, 211, real(pilot_lpf1_log(st:en)), real(pilot_lpf1_log(st:en) - pilot_lpf1_log_c(st:en)), 'pilot lpf1 real' )
plot_sig_and_error(6, 212, real(pilot_lpf2_log(st:en)), real(pilot_lpf2_log(st:en) - pilot_lpf2_log_c(st:en)), 'pilot lpf2 real' )
plot_sig_and_error(9, 212, foff_fine_log, foff_fine_log - foff_fine_log_c, 'Fine Freq Offset' )
plot_sig_and_error(10, 211, foff_log, foff_log - foff_log_c, 'Freq Offset' )
-plot_sig_and_error(10, 212, coarse_fine_log, coarse_fine_log - coarse_fine_log_c, 'Freq Est Coarse(0) Fine(1)', [1 frames -0.5 1.5] )
+plot_sig_and_error(10, 212, sync_log, sync_log - sync_log_c, 'Freq Est Coarse(0) Fine(1)', [1 frames -0.5 1.5] )
c=15;
plot_sig_and_error(11, 211, real(rx_baseband_log(c,:)), real(rx_baseband_log(c,:) - rx_baseband_log_c(c,:)), 'Rx baseband real' )
end
printf(": ");
- if sum(abs(a - b))/n < 1E-3
+ e = sum(abs(a - b))/n;
+ if e < 1E-3
printf("OK\n");
passes++;
else
check(rx_symbols_log, rx_symbols_log_c, 'rx_symbols');
check(rx_bits_log, rx_bits_log_c, 'rx bits');
check(sync_bit_log, sync_bit_log_c, 'sync bit');
-check(coarse_fine_log, coarse_fine_log_c, 'coarse_fine');
+check(sync_log, sync_log_c, 'sync');
check(nin_log, nin_log_c, 'nin');
check(sig_est_log, sig_est_log_c, 'sig_est');
check(noise_est_log, noise_est_log_c, 'noise_est');
-
printf("\npasses: %d fails: %d\n", passes, fails);