From: drowe67 Date: Tue, 10 Apr 2012 05:13:17 +0000 (+0000) Subject: pilot used for rx converted to LUT, _ut & _demod work OK X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=5d5592719602d8e9014755d03d2ee41f6bdeb246;p=freetel-svn-tracking.git pilot used for rx converted to LUT, _ut & _demod work OK git-svn-id: https://svn.code.sf.net/p/freetel/code@365 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/octave/fdmdv.m b/codec2-dev/octave/fdmdv.m index f0cf8037..444fef8e 100644 --- a/codec2-dev/octave/fdmdv.m +++ b/codec2-dev/octave/fdmdv.m @@ -636,6 +636,43 @@ function [pilot_fdm bit symbol filter_mem phase] = generate_pilot_fdm(bit, symbo endfunction +% Generate a 4M sample vector of DBPSK pilot signal. As the pilot signal +% is periodic in 4M samples we can then use this vector as a look up table +% for pilot signsl generation at the demod. + +function pilot_lut = generate_pilot_lut + global Nc; + global Nfilter; + global M; + global freq; + + % pilot states + + pilot_rx_bit = 0; + pilot_symbol = sqrt(2); + pilot_freq = freq(Nc+1); + pilot_phase = 1; + pilot_filter_mem = zeros(1, Nfilter); + prev_pilot = zeros(M,1); + + pilot_lut = []; + + F=8; + + for f=1:F + [pilot pilot_rx_bit pilot_symbol pilot_filter_mem pilot_phase] = generate_pilot_fdm(pilot_rx_bit, pilot_symbol, pilot_filter_mem, pilot_phase, pilot_freq); + prev_pilot = pilot; + pilot_lut = [pilot_lut pilot]; + end + + % discard first 4 symbols as filer memory is filling, just keep last + % four symbols + + pilot_lut = pilot_lut(4*M+1:M*F); + +endfunction + + % Change the sample rate by a small amount, for example 1000ppm (ratio % = 1.001). Always returns nout samples in buf_out, but uses a % variable number of input samples nin to accomodate the change in diff --git a/codec2-dev/octave/fdmdv_demod.m b/codec2-dev/octave/fdmdv_demod.m index 96ebabf7..0d52c5cf 100644 --- a/codec2-dev/octave/fdmdv_demod.m +++ b/codec2-dev/octave/fdmdv_demod.m @@ -1,6 +1,7 @@ % fdmdv_demod.m % -% Demodulator function for FDMDV modem. +% Demodulator function for FDMDV modem. Requires 48kHz sample rate raw files +% as input % % Copyright David Rowe 2012 % This program is distributed under the terms of the GNU General Public License @@ -20,14 +21,11 @@ function fdmdv_demod(rawfilename, nbits) prev_rx_symbols = ones(Nc+1,1); foff_phase = 1; - % pilot states, used for copy of pilot at rx - - pilot_rx_bit = 0; - pilot_symbol = sqrt(2); - pilot_freq = freq(Nc+1); - pilot_phase = 1; - pilot_filter_mem = zeros(1, Nfilter); - prev_pilot = zeros(M,1); + % pilot LUT, used for copy of pilot at rx + + pilot_lut = generate_pilot_lut; + pilot_lut_index = 1; + prev_pilot = zeros(1,M); % BER stats @@ -45,13 +43,14 @@ function fdmdv_demod(rawfilename, nbits) % resampler states t = 3; - ratio = 1.002; + ratio = 1.000; F=6; MF=M*F; nin = MF; nin_size = MF+6; buf_in = zeros(1,nin_size); rx_fdm_buf = []; + ratio_log = []; % Main loop ---------------------------------------------------- @@ -63,13 +62,15 @@ function fdmdv_demod(rawfilename, nbits) buf_in(i) = buf_in(i+nin); end - % obtain n samples of the test input signal + % obtain nin samples of the test input signal for i=m+1:nin_size buf_in(i) = fread(fin, 1, "short")/gain; end - [rx_fdm_mf t nin] = resample(buf_in, t, ratio, MF); + % resample at 48kHz and decimate to 8kHz + + [rx_fdm_mf t nin] = resample(buf_in, t, 1.0, MF); rx_fdm = rx_fdm_mf(1:F:MF); %rx_fdm = buf_in(m+1:m+n); @@ -81,7 +82,13 @@ function fdmdv_demod(rawfilename, nbits) % frequency offset estimation and correction - [pilot pilot_rx_bit pilot_symbol pilot_filter_mem pilot_phase] = generate_pilot_fdm(pilot_rx_bit, pilot_symbol, pilot_filter_mem, pilot_phase, pilot_freq); + for i=1:M + pilot(i) = pilot_lut(pilot_lut_index); + pilot_lut_index++; + if pilot_lut_index > 4*M + pilot_lut_index = 1; + end + end foff = rx_est_freq_offset(rx_fdm, pilot, prev_pilot); prev_pilot = pilot; foff_log = [ foff_log foff ]; @@ -100,6 +107,15 @@ function fdmdv_demod(rawfilename, nbits) [rx_symbols rx_timing] = rx_est_timing(rx_filt, rx_baseband); rx_timing_log = [rx_timing_log rx_timing]; + beta = 1E-7; + ratio += beta*rx_timing; + if (ratio > 1.002) + ratio = 1.002; + end + if (ratio < 0.998) + ratio = 0.998; + end + ratio_log = [ratio_log ratio]; if strcmp(modulation,'dqpsk') rx_symbols_log = [rx_symbols_log rx_symbols.*conj(prev_rx_symbols)*exp(j*pi/4)]; @@ -167,17 +183,20 @@ function fdmdv_demod(rawfilename, nbits) figure(2) clf; subplot(211) - plot(rx_timing_log) + plot(rx_timing_log(15:m)) title('timing offset (samples)'); subplot(212) plot(foff_log) title('Freq offset (Hz)'); + grid figure(3) clf; subplot(211) - plot(rx_fdm_buf); - title('FDM Rx Signal'); + %plot(rx_fdm_buf); + %title('FDM Rx Signal'); + plot(ratio_log-1); + title('Sampling Clock error (ppm)'); subplot(212) Nfft=Fs; S=fft(rx_fdm_buf,Nfft); @@ -199,4 +218,5 @@ function fdmdv_demod(rawfilename, nbits) axis([0 frames 0 1.5]); title('Test Frame Sync') + mean(ratio_log) endfunction diff --git a/codec2-dev/octave/fdmdv_ut.m b/codec2-dev/octave/fdmdv_ut.m index 40557397..65cb0d54 100644 --- a/codec2-dev/octave/fdmdv_ut.m +++ b/codec2-dev/octave/fdmdv_ut.m @@ -43,14 +43,10 @@ sync_log = []; test_frame_sync_log = []; test_frame_sync_state = 0; -% pilot states, used for copy of pilot at rx +% pilot look up table, used for copy of pilot at rx -pilot_rx_bit = 0; -pilot_symbol = sqrt(2); -pilot_freq = freq(Nc+1); -pilot_phase = 1; -pilot_filter_mem = zeros(1, Nfilter); -prev_pilot = zeros(M,1); +pilot_lut = generate_pilot_lut; +pilot_lut_index = 1; % fixed delay simuation @@ -153,7 +149,13 @@ for f=1:frames % frequency offset estimation and correction - [pilot pilot_rx_bit pilot_symbol pilot_filter_mem pilot_phase] = generate_pilot_fdm(pilot_rx_bit, pilot_symbol, pilot_filter_mem, pilot_phase, pilot_freq); + for i=1:M + pilot(i) = pilot_lut(pilot_lut_index); + pilot_lut_index++; + if pilot_lut_index > 4*M + pilot_lut_index = 1; + end + end foff = rx_est_freq_offset(rx_fdm_delay, pilot, prev_pilot); prev_pilot = pilot; foff_log = [ foff_log foff ];