- RX added wiener filtering and other stuff

- Tx reordered generation of pilots

git-svn-id: http://moon:8086/svn/matlab/trunk@41 801c6759-fa7c-4059-a304-17956f83a07c
This commit is contained in:
2015-04-29 19:24:52 +00:00
parent b3924ead7d
commit e0b9373318
2 changed files with 75 additions and 49 deletions
+63 -38
View File
@@ -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_rx('drm-15435-if.wav', -174.65, -400, 0)
% Example: ofdm_tx(40, 1) % Example: ofdm_tx(40, 1)
@@ -33,7 +33,7 @@ if (ndim == 2)
elseif (ndim == 1) elseif (ndim == 1)
fprintf('Mode: Passband\n'); fprintf('Mode: Passband\n');
x = xwav.*exp(-j*(2*pi*(0.25-foff/fs_)*(0:len-1)')); 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); x = filter(hlp, 1, x);
% Downsample % Downsample
@@ -50,9 +50,7 @@ x = x./max(abs(x));
xout = [real(x) imag(x)]; xout = [real(x) imag(x)];
wavwrite(xout,fs,nbits,'ofdm_rx.wav'); 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; K = fix((length(x))/(N+Ng))-1;
% Timing coarse % Timing coarse
@@ -190,9 +188,10 @@ end
bins = c2i(N, carrier_time); bins = c2i(N, carrier_time);
kc_max = -1000; kc_max = -1000;
n_max = 0; n_max = 0;
skip_syms = 15*4;
for n=0:15-1 for n=0:15-1
frame_timing_Z = 0; frame_timing_Z = 0;
k = 200+n; k = skip_syms+n;
for m=1:2 for m=1:2
[kc valid frame_timing_Z] = timing_frame(Z_(bins, k)', bins, 15, frame_timing_Z); [kc valid frame_timing_Z] = timing_frame(Z_(bins, k)', bins, 15, frame_timing_Z);
k = k + 15; k = k + 15;
@@ -207,7 +206,7 @@ end
frame_start = n_max; frame_start = n_max;
figure; figure;
start = 200+frame_start; start = skip_syms+frame_start;
Z_timing = Z_(bins, start:15:length(Z_))'; Z_timing = Z_(bins, start:15:length(Z_))';
plot(real(Z_timing), imag(Z_timing), '+'); grid; title('SymPilot_{Time}'); plot(real(Z_timing), imag(Z_timing), '+'); grid; title('SymPilot_{Time}');
maxZ = max(max(abs(Z_timing))); maxZ = max(max(abs(Z_timing)));
@@ -217,47 +216,73 @@ else
axis([-maxZ maxZ -maxZ maxZ]); axis([-maxZ maxZ -maxZ maxZ]);
end end
W = calcWiener(drm_mode, drm_bw);
figure; figure;
% Detect scattered gain pilots % Detect scattered gain pilots
sym_count = 0; sym_count = 0;
start = 200+frame_start; win_count = 0;
start = skip_syms+frame_start;
H = zeros(N, 1); H = zeros(N, 1);
sym_H = []; 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_) 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); carrier_gain_bins = c2i(N, carrier_gain);
Hp = Z_(carrier_gain_bins, k)./(mag_gain.*exp(-j*2*pi*phi_gain/1024))'; 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); H_gain_cell{win_count+1} = transpose(Z_(carrier_gain_bins, k)./(mag_gain.*exp(j*2*pi*phi_gain/1024)).');
if 0 ii = 1+mod(0+win_count+(0:frames_per_window-1), frames_per_window);
plot(abs(Hp)); grid; title(sym_count_str); H_gain = [H_gain_cell{ii}];
pause(0.1); H_gain_carriers_cell{win_count+1} = carrier_gain;
end if length(H_gain) == 208
if (sym_count < 14)
sym_count = sym_count+1;
else
H(1:2:N) = H(2:2:length(H));
if 1 if 1
% G = ones(size(H)); H = H_gain*W{n+1};
% G = 1./(H+1e-6); ZZ = Z_(c2i(N, ofdm_spec_occ.kmin:ofdm_spec_occ.kmax), k).';
G = (conj(H)*1)./(abs(H).^2 * 1 + sigma_Hp(1)); sym_out(:, kk) = ZZ ./ H;
subplot(4, 1, 1) if 1
plot(abs(spec_order(N, H))); grid; title('abs(H)'); subplot(2, 1, 1)
subplot(4, 1, 2) plot(abs(H)); grid; title('abs(H)');
plot(angle(spec_order(N, H))); grid; title('phi(H)'); subplot(2, 1, 2)
subplot(4, 1, 3) plot(angle(H)); grid; title('phi(H)');
plot(abs(spec_order(N, G))); grid; title('abs(G)'); else
subplot(4, 1, 4) hold on;
plot(angle(spec_order(N, G))); grid; title('phi(G)'); 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); pause(0.01);
bin = c2i(N, 13);
sym_H = [sym_H Z_(bin, k).*G(bin)];
end end
H_gather = zeros(N, 1); end
sym_count = 0; kk = kk + 1;
end; win_count = mod(win_count+1, frames_per_window);
end end
figure; figure;
+12 -11
View File
@@ -59,24 +59,25 @@ for k=1:N_frames
X(data_i) = qlut(sym); X(data_i) = qlut(sym);
end; end;
if WITH_FREQ_REF == 1 if WITH_GAIN_REF == 1
[ref_c ref_p ref_a] = getRefFreq(ofdm_params.mode); [ref_c ref_p ref_a] = getRefGain(ofdm_params, ofdm_spec_occ, sym_count);
bins = c2i(N, ref_c); X(c2i(N, ref_c)) = ref_a.*(exp(2*pi*i*ref_p/1024));
X(bins) = ref_a.*(exp(2*pi*i*ref_p/1024));
end; end;
if (sym_count==0) & (WITH_TIME_REF == 1) if (sym_count==0) & (WITH_TIME_REF == 1)
[ref_c ref_p ref_a] = getRefTime(ofdm_params.mode); [ref_c ref_p ref_a] = getRefTime(ofdm_params.mode);
bins = c2i(N, ref_c); bins = c2i(N, ref_c);
X(bins) = ref_a.*(exp(2*pi*i*ref_p/1024)); X(bins) = ref_a.*(exp(2*pi*i*ref_p/1024));
end; 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 % Modulate
xu = conj(k_fft*ifft(X, N)'); xu = conj(k_fft*ifft(X, N)');
if WITH_RCWIN == 1 if WITH_RCWIN == 1
@@ -95,7 +96,7 @@ for k=1:N_frames
xv = [xv xs(1:Ng+N)]; xv = [xv xs(1:Ng+N)];
if (DO_PLOT == 1) 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; plot(0:N-1, abs(Xs(1:N)), '-*'); grid;
pause(0.01); pause(0.01);
end end