% ofdm_lib.m
% David Rowe Mar 2017
-%
-% Library of functions that implement a BPSK/QPSK OFDM modem. Rate Fs
-% verison of ofdm_rs.m with OFDM based up and down conversion, and all
-% those nasty real-world details like fine freq, timing.
+#{
+ Library of functions that implement a BPSK/QPSK OFDM modem. Rate Fs
+ verison of ofdm_rs.m with OFDM based up and down conversion, and all
+ those nasty real-world details like fine freq, timing.
+
+
+#}
+
1;
% Also determines frequency offset at maximimum correlation. Can be
% used for acquisition (coarse timing a freq offset), and fine timing
+#{
+ TODO:
+ [ ] attempt to speed up sync
+ + tis rather stateless, this current demod, which is nice
+ [ ] 0.5Hz grid and measure BER
+ + so run demod a bunch of times at different offsets
+ + Hmm cld also try +/- 20Hz multiples as it's aliased?
+ + might to use
+ + need metric for sync, could be callback.
+ [ ] or refine freq offset using pilots
+ [ ] different error measure that 10% maybe soft dec
+ + 10% very high BER
+ [ ] simpler CPU/DFT for freq offset estimation
+ + more suitable for real time implementation
+#}
+
function [t_est foff_est] = coarse_sync(states, rx, rate_fs_pilot_samples)
Nsamperframe = states.Nsamperframe; Fs = states.Fs;
Npsam = length(rate_fs_pilot_samples);
next_state = state;
if strcmp(state,'searching')
- if Nerrs/Nbitsperframe < 0.1
+ if Nerrs/Nbitsperframe < 0.15
next_state = 'synced';
end
end
% reset modem states
states.sample_point = states.timing_est = 1;
- states.foff_est_hz = 0;
+ states.foff_est_hz = foff_est;
else
figure(4); clf;
plot(foff_est_hz_log)
- axis([1 max(Nframes,2) -3 3]);
+ mx = max(abs(foff_est_hz_log));
+ axis([1 max(Nframes,2) -mx mx]);
title('Fine Freq');
figure(5); clf;
% File based ofdm tx. Generate a file of ofdm samples, inclduing
% optional channel simulation.
+#{
+ TODO:
+ [ ] Optional LDPC code
+ [ ] measure and report raw and coded BER
+ [ ] maybe 10s worth of frames, sync up to any one automatically
+ + or start with maybe 10 frames
+ + measure BER match on each one
+#}
function ofdm_tx(filename, Nsec, EbNodB=100, channel='awgn', freq_offset_Hz=0)
ofdm_lib;
% mumble not understood very well mumble magic number.
SNRdB = EbNodB + 10*log10(bps*Rs*Nc/Fs) + 3;
- printf("EbNo: %3.1f SNR(3k): %3.1f foff: %3.1f\n", EbNodB, SNRdB, freq_offset_Hz);
+ printf("EbNo: %3.1f dB SNR(3k): %3.1f dB foff: %3.1fHz\n", EbNodB, SNRdB, freq_offset_Hz);
% set up HF model ---------------------------------------------------------------
rx = rx .* exp(j*woffset*(1:Nsam));
- % note variance/2 as we are using real() operator
+ % note variance/2 as we are using real() operator, mumble,
+ % reflection of -ve freq to +ve, mumble, hand wave
- noise = sqrt(variance/2)*(0.5*randn(1,Nsam) + j*0.5*randn(1,Nsam));
- rx += noise;
- 10*log10(var(tx)/var(noise))
+ noise = sqrt(variance/2)*0.5*randn(1,Nsam);
+ rx = real(rx) + noise;
+ printf("measured SNR: %3.2f dB\n", 10*log10(var(real(tx))/var(noise)));
Ascale = 4E5;
- frx=fopen(filename,"wb"); fwrite(frx, Ascale*real(rx), "short"); fclose(frx);
+ frx=fopen(filename,"wb"); fwrite(frx, Ascale*rx, "short"); fclose(frx);
endfunction