- removed fill member

[RX]
- added plot_mode as string for real time plot mode. 'h_pilots', 'h_syms' and 'fac' are available.
- fixed finish condition for main loop

git-svn-id: http://moon:8086/svn/matlab/trunk@79 801c6759-fa7c-4059-a304-17956f83a07c
This commit is contained in:
2015-05-04 06:39:46 +00:00
parent 5b55fda090
commit 50ca3b4b80
2 changed files with 63 additions and 62 deletions
+2 -3
View File
@@ -1,6 +1,6 @@
function [buf] = buffer() function [buf] = buffer()
buf = struct('mem', [], 'ri', 0, 'wi', 0, 'fill', 0, 'obj', @()obj_(), 'len', @()len_(), 'read', @(len)read_(len), 'readAt', @(len, offset)readAt_(len, offset), 'setReadIndex', @(offset)setReadIndex_(offset), 'write', @(x)write_(x)); buf = struct('mem', [], 'ri', 0, 'wi', 0, 'obj', @()obj_(), 'len', @()len_(), 'read', @(len)read_(len), 'readAt', @(len, offset)readAt_(len, offset), 'setReadIndex', @(offset)setReadIndex_(offset), 'write', @(x)write_(x));
function b = obj_() function b = obj_()
b = buf; b = buf;
@@ -36,8 +36,7 @@ function [buf] = buffer()
function write_(x) function write_(x)
len = length(x); len = length(x);
buf.mem(buf.wi+1:buf.wi+len,:) = x; buf.mem(buf.wi+1:buf.wi+len, :) = x;
buf.fill = buf.fill + len;
buf.wi = buf.wi + len; buf.wi = buf.wi + len;
end end
+14 -12
View File
@@ -1,6 +1,6 @@
function ofdm_rx(filename, foff, flip_spec, SNR, show_H) function ofdm_rx(filename, foff, flip_spec, SNR, plot_mode)
% %
% [sym_out, H, W] = ofdm_rx(filename, foff, flip_spec, SNR, show_H) % [sym_out, H, W] = ofdm_rx(filename, foff, flip_spec, SNR, plot_mode)
% Example: ofdm_rx('drm-15435-if.wav', -174.65, 0, 400, 1) % Example: ofdm_rx('drm-15435-if.wav', -174.65, 0, 400, 1)
% Example: ofdm_rx('xv.wav', 0, 0, 400, 1) % Example: ofdm_rx('xv.wav', 0, 0, 400, 1)
% or ofdm_rx('yv.wav', 0, 0, 400, 1) % or ofdm_rx('yv.wav', 0, 0, 400, 1)
@@ -71,12 +71,10 @@ if (wav_numCh == 1)
fprintf('Mode: Passband\n'); fprintf('Mode: Passband\n');
isModePassband = 1; isModePassband = 1;
fs = fix(wav_fs/4); fs = fix(wav_fs/4);
fileChunkSize = N; % Fix: don't leave loop, if file has been consumed. There may be samples left in buf_recv to process
elseif (wav_numCh == 2) elseif (wav_numCh == 2)
fprintf('Mode: Baseband\n'); fprintf('Mode: Baseband\n');
fs = wav_fs; fs = wav_fs;
fileChunkSize = N/4; % Fix: don't leave loop, if file has been consumed. There may be samples left in buf_recv to process
else else
error('Cannot read file'); error('Cannot read file');
end end
@@ -100,6 +98,7 @@ frameTiming = struct('Z', 0, 'started', 0, 'sync_counter', 20, 'sync', 0, 'kc_ma
% Equalization stuff % Equalization stuff
equalizer = struct('Z', 0, 'started', 0, 'sync_counter', 20, 'sync', 0, 'sync_frame_num', 0, 'f_err', 1000, 'f_err_', [], 's', 0, 'm', 0, 'kk', 1, 'eps_abs_h', MIN_ABS_H); equalizer = struct('Z', 0, 'started', 0, 'sync_counter', 20, 'sync', 0, 'sync_frame_num', 0, 'f_err', 1000, 'f_err_', [], 's', 0, 'm', 0, 'kk', 1, 'eps_abs_h', MIN_ABS_H);
fileChunkSize = N;
fileCunkCounter = 0; fileCunkCounter = 0;
phi_mix = 0; phi_mix = 0;
phi_foff = 0; phi_foff = 0;
@@ -116,8 +115,9 @@ buf_Z = buffer();
% -------------------------------------------------------------- % --------------------------------------------------------------
% Main loop % Main loop
% -------------------------------------------------------------- % --------------------------------------------------------------
while(fileRemain > fileChunkSize) % ToDo: don't leave loop, if file has been consumed. There may be samples left in buf_recv to process while((fileRemain > fileChunkSize) | (buf_Z.len() > N)) % ToDo: don't leave loop, if file has been consumed. There may be samples left in buf_recv to process
if (fileRemain > fileChunkSize)
n0 = fileCunkCounter*fileChunkSize+1; n0 = fileCunkCounter*fileChunkSize+1;
n1 = (fileCunkCounter+1)*fileChunkSize; n1 = (fileCunkCounter+1)*fileChunkSize;
[wav_x] = wavread(filename, [n0 n1]); [wav_x] = wavread(filename, [n0 n1]);
@@ -130,7 +130,7 @@ while(fileRemain > fileChunkSize) % ToDo: don't leave loop, if file has been con
end end
if (isModePassband) if (isModePassband)
x = wav_x - mean(wav_x); % ToDo: Remove DC x = wav_x; % ToDo: Remove DC
x = x .*exp(-j*(2*pi*(0.25-foff/wav_fs)*(0:length(x)-1)' + phi_mix)); x = x .*exp(-j*(2*pi*(0.25-foff/wav_fs)*(0:length(x)-1)' + phi_mix));
phi_mix = mod(phi_mix + 2*pi*(0.25-foff/wav_fs)*length(x), 2*pi); phi_mix = mod(phi_mix + 2*pi*(0.25-foff/wav_fs)*length(x), 2*pi);
[x, filter_z] = filter(filter_h, 1, x, filter_z); [x, filter_z] = filter(filter_h, 1, x, filter_z);
@@ -146,6 +146,7 @@ while(fileRemain > fileChunkSize) % ToDo: don't leave loop, if file has been con
% Write to buffer % Write to buffer
buf_recv.write(x); buf_recv.write(x);
end
% -------------------------------------------------------------- % --------------------------------------------------------------
% Timing coarse % Timing coarse
@@ -363,7 +364,7 @@ while(fileRemain > fileChunkSize) % ToDo: don't leave loop, if file has been con
% equalize symbol % equalize symbol
sym_eq = sym ./ H_syms; sym_eq = sym ./ H_syms;
if 0 if strcmpi(plot_mode, 'h_pilots')
subplot(2, 1, 1) subplot(2, 1, 1)
plot(1:length(Hr), abs(Hr), 'b-', 1:length(H_pilots), abs(H_pilots), 'r-'); grid; plot(1:length(Hr), abs(Hr), 'b-', 1:length(H_pilots), abs(H_pilots), 'r-'); grid;
subplot(2, 1, 2) subplot(2, 1, 2)
@@ -371,8 +372,7 @@ while(fileRemain > fileChunkSize) % ToDo: don't leave loop, if file has been con
title(str); title(str);
pause(0.01); pause(0.01);
end end
if 1 if strcmpi(plot_mode, 'h_syms')
if show_H
max_H_plot = ceil(max(max_H_plot, max(abs(H_raw(2:2:N))))); max_H_plot = ceil(max(max_H_plot, max(abs(H_raw(2:2:N)))));
H_raw(1:2:N) = H_raw(2:2:N); H_raw(1:2:N) = H_raw(2:2:N);
subplot(3, 1, 1) subplot(3, 1, 1)
@@ -390,7 +390,8 @@ while(fileRemain > fileChunkSize) % ToDo: don't leave loop, if file has been con
hold off; hold off;
pause(0.01); pause(0.01);
elseif (equalizer.sync) end
if strcmpi(plot_mode, 'fac') & (equalizer.sync)
fac_c = fac_cell_list{mod(equalizer.s-symbols_to_delay, symbols_per_frame)+1}; fac_c = fac_cell_list{mod(equalizer.s-symbols_to_delay, symbols_per_frame)+1};
if (~isempty(fac_c)) if (~isempty(fac_c))
fac_i = fac_c - ofdm_spec_occ.kmin + 1; fac_i = fac_c - ofdm_spec_occ.kmin + 1;
@@ -402,7 +403,6 @@ while(fileRemain > fileChunkSize) % ToDo: don't leave loop, if file has been con
end end
end end
end end
end
equalizer.kk = equalizer.kk + 1; equalizer.kk = equalizer.kk + 1;
equalizer.m = mod(equalizer.m + 1, frames_per_window); equalizer.m = mod(equalizer.m + 1, frames_per_window);
equalizer.s = mod(equalizer.s + 1, symbols_per_frame); equalizer.s = mod(equalizer.s + 1, symbols_per_frame);
@@ -467,9 +467,11 @@ xup = filter(hlp, 1, xup);
y = exp(j*2*pi.*(0:length(xup)-1)'*0.25) .* xup; y = exp(j*2*pi.*(0:length(xup)-1)'*0.25) .* xup;
fprintf('.'); fprintf('.');
wavwrite(y,4*fs,nbits,'rx_y.wav'); tt = equalizer.f_err_ ./ max(abs(equalizer.f_err_));
wavwrite(0.8*tt,fs/8,nbits,'rx_cfo_err.wav');
fprintf(' done\n'); fprintf(' done\n');
% -------------------------------------------------------------- % --------------------------------------------------------------
function Y = spec_order(N, X) function Y = spec_order(N, X)
Y = [X(N/2+1:N)' X(1:N/2)']'; Y = [X(N/2+1:N)' X(1:N/2)']';