diff --git a/ofdm/ofdm_rx.m b/ofdm/ofdm_rx.m index 1b132a4..f5cd845 100644 --- a/ofdm/ofdm_rx.m +++ b/ofdm/ofdm_rx.m @@ -1,4 +1,4 @@ -function [x] = ofdm_rx(filename, foff, knoise_dB, with_cir) +function [sym_out, H, W] = ofdm_rx(filename, foff, SNR, with_cir) % % Example: ofdm_rx('drm-15435-if.wav', -174.65, -400, 0) % Example: ofdm_tx(40, 1) @@ -33,7 +33,7 @@ if (ndim == 2) elseif (ndim == 1) fprintf('Mode: Passband\n'); x = xwav.*exp(-j*(2*pi*(0.25-foff/fs_)*(0:len-1)')); - hlp = FIRCalcLowpass(12000/fs_, 33); + hlp = FIRCalcLowpass(12000/fs_, 15); x = filter(hlp, 1, x); % Downsample @@ -50,9 +50,7 @@ x = x./max(abs(x)); xout = [real(x) imag(x)]; wavwrite(xout,fs,nbits,'ofdm_rx.wav'); -x = x + sqrt(0.5)*10^(knoise_dB/20)*(randn(size(x)) + j*randn(size(x))); - - +x = awgn(x, SNR, 'measured'); K = fix((length(x))/(N+Ng))-1; % Timing coarse @@ -190,9 +188,10 @@ end bins = c2i(N, carrier_time); kc_max = -1000; n_max = 0; +skip_syms = 15*4; for n=0:15-1 frame_timing_Z = 0; - k = 200+n; + k = skip_syms+n; for m=1:2 [kc valid frame_timing_Z] = timing_frame(Z_(bins, k)', bins, 15, frame_timing_Z); k = k + 15; @@ -207,7 +206,7 @@ end frame_start = n_max; figure; -start = 200+frame_start; +start = skip_syms+frame_start; Z_timing = Z_(bins, start:15:length(Z_))'; plot(real(Z_timing), imag(Z_timing), '+'); grid; title('SymPilot_{Time}'); maxZ = max(max(abs(Z_timing))); @@ -217,47 +216,73 @@ else axis([-maxZ maxZ -maxZ maxZ]); end +W = calcWiener(drm_mode, drm_bw); + figure; % Detect scattered gain pilots sym_count = 0; -start = 200+frame_start; +win_count = 0; +start = skip_syms+frame_start; H = zeros(N, 1); sym_H = []; +sym_out = []; +kk = 1; +G = []; +bin = c2i(N, 13); +Hraw = []; + +symbols_per_frame = 15; +symbols_to_delay = ofdm_drm_params.y; +symbol_counter = 0; +frames_per_window = 2*ofdm_drm_params.y +H_gain_cell = cell (frames_per_window, 1); +H_gain_carriers_cell = cell (frames_per_window, 1); for k=start:length(Z_) - [carrier_gain, phi_gain, mag_gain] = getRefGain(ofdm_spec_occ, ofdm_drm_params, sym_count); + + %shifted symbol index + nn = rem(k-1-symbols_to_delay + symbols_per_frame, symbols_per_frame); + n = rem(nn, ofdm_drm_params.y); + m = floor(nn/ofdm_drm_params.y); + + [carrier_gain, phi_gain, mag_gain] = getRefGain(ofdm_drm_params, ofdm_spec_occ, symbol_counter); symbol_counter = symbol_counter + 1; carrier_gain_bins = c2i(N, carrier_gain); - Hp = Z_(carrier_gain_bins, k)./(mag_gain.*exp(-j*2*pi*phi_gain/1024))'; - H(carrier_gain_bins) = Hp; - sym_count_str = sprintf('%d', sym_count); - if 0 - plot(abs(Hp)); grid; title(sym_count_str); - pause(0.1); - end - - if (sym_count < 14) - sym_count = sym_count+1; - else - H(1:2:N) = H(2:2:length(H)); + Hp = Z_(carrier_gain_bins, k)./(mag_gain.*exp(j*2*pi*phi_gain/1024)).'; + + H_gain_cell{win_count+1} = transpose(Z_(carrier_gain_bins, k)./(mag_gain.*exp(j*2*pi*phi_gain/1024)).'); + ii = 1+mod(0+win_count+(0:frames_per_window-1), frames_per_window); + H_gain = [H_gain_cell{ii}]; + H_gain_carriers_cell{win_count+1} = carrier_gain; + if length(H_gain) == 208 if 1 -% G = ones(size(H)); -% G = 1./(H+1e-6); - G = (conj(H)*1)./(abs(H).^2 * 1 + sigma_Hp(1)); - subplot(4, 1, 1) - plot(abs(spec_order(N, H))); grid; title('abs(H)'); - subplot(4, 1, 2) - plot(angle(spec_order(N, H))); grid; title('phi(H)'); - subplot(4, 1, 3) - plot(abs(spec_order(N, G))); grid; title('abs(G)'); - subplot(4, 1, 4) - plot(angle(spec_order(N, G))); grid; title('phi(G)'); + H = H_gain*W{n+1}; + ZZ = Z_(c2i(N, ofdm_spec_occ.kmin:ofdm_spec_occ.kmax), k).'; + sym_out(:, kk) = ZZ ./ H; + if 1 + subplot(2, 1, 1) + plot(abs(H)); grid; title('abs(H)'); + subplot(2, 1, 2) + plot(angle(H)); grid; title('phi(H)'); + else + hold on; + plot(sym_out(:, kk), '+'); + hold off; + grid; title('Sym'); + end + pause(0.01); + else + ii = [H_gain_carriers_cell{1:6}] + H = H_gain; + sym_out(:, kk) = 0; + subplot(2, 1, 1) + plot(abs(H)); grid; title('abs(H)'); + subplot(2, 1, 2) + plot(angle(H)); grid; title('phi(H)'); pause(0.01); - - bin = c2i(N, 13); - sym_H = [sym_H Z_(bin, k).*G(bin)]; end - H_gather = zeros(N, 1); - sym_count = 0; - end; + end + kk = kk + 1; + win_count = mod(win_count+1, frames_per_window); + end figure; diff --git a/ofdm/ofdm_tx.m b/ofdm/ofdm_tx.m index 45df8d4..bbd0efc 100644 --- a/ofdm/ofdm_tx.m +++ b/ofdm/ofdm_tx.m @@ -59,24 +59,25 @@ for k=1:N_frames X(data_i) = qlut(sym); end; - if WITH_FREQ_REF == 1 - [ref_c ref_p ref_a] = getRefFreq(ofdm_params.mode); - bins = c2i(N, ref_c); - X(bins) = ref_a.*(exp(2*pi*i*ref_p/1024)); + if WITH_GAIN_REF == 1 + [ref_c ref_p ref_a] = getRefGain(ofdm_params, ofdm_spec_occ, sym_count); + X(c2i(N, ref_c)) = ref_a.*(exp(2*pi*i*ref_p/1024)); end; - if (sym_count==0) & (WITH_TIME_REF == 1) [ref_c ref_p ref_a] = getRefTime(ofdm_params.mode); bins = c2i(N, ref_c); X(bins) = ref_a.*(exp(2*pi*i*ref_p/1024)); end; - - if WITH_GAIN_REF == 1 - [ref_c ref_p ref_a] = getRefGain(ofdm_spec_occ, ofdm_params, sym_count); - X(c2i(N, ref_c)) = ref_a.*(exp(2*pi*i*ref_p/1024)); - end; + if WITH_FREQ_REF == 1 + [ref_c ref_p ref_a] = getRefFreq(ofdm_params.mode); + bins = c2i(N, ref_c); + X(bins) = ref_a.*(exp(2*pi*i*ref_p/1024)); + end; + + X(c2i(N, 0)) = 0; + % Modulate xu = conj(k_fft*ifft(X, N)'); if WITH_RCWIN == 1 @@ -95,7 +96,7 @@ for k=1:N_frames xv = [xv xs(1:Ng+N)]; if (DO_PLOT == 1) - Xs = fft(xs(Ng+1:Ng+N), N)/k_fft; + Xs = fftshift(fft(xs(Ng+1:Ng+N), N)/k_fft); plot(0:N-1, abs(Xs(1:N)), '-*'); grid; pause(0.01); end