📄 ui_params.m
字号:
% keep all variables local in scope
function [] = ui_params();
% declare global variables
dfec_global;
ui_private_global;
%%%%%%%%%%%%%%%%%%%%%%
% Channel Parameters %
%%%%%%%%%%%%%%%%%%%%%%
% handle the "channel type" setting
read_chan=0;
% 8-tap channel
switch get(h_chan,'Value')
case 1,
set(h_coefs,'String','[ -1 3 10 7 3 -1 -5 2 ]');
set(h_coefs,'Enable','inactive');
% 3-tap channel
case 2,
set(h_coefs,'String','[ 1 0.6 -0.55 ]');
set(h_coefs,'Enable','inactive');
% Custom channel
case 3,
if ~isempty(findstr('.mat',get(h_coefs,'String')))
set(h_coefs,'String','[ 1 0.0 ]');
warn('Found filename.','Setting channel to [1 0].');
end;
set(h_coefs,'Enable','on');
% Read from file
case 4,
cname = get(h_coefs,'String');
if isempty(findstr('.mat',cname)),
warn('File name needs .mat extension.',...
'Setting filename to default channel.mat');
cname='channel.mat';
set(h_coefs,'String',cname);
end
set(h_coefs,'Enable','on');
read_chan=1;
end;
% Spacing
switch get(h_spa,'Value')
% Baud-spaced
case 1
spacing=1;
% Fractionally-spaced
case 2
spacing=1/2;
end;
% Read in channel taps
if read_chan,
err_string = ['Request ignored! File "',cname,'" not found.'];
eval(['load ',cname,' c'],'disp(err_string)');
else
c=evalin('base',get(h_coefs,'String'));
end;
if length(c) < 2,
warn('Must have at least two channel coefficients',[]);
elseif min(size(c)) ~= 1,
warn('Channel must be an FIR vector',[]);
set(h_coefs,'String','[ 1 0.0 ]');
c=[1 0];
end
c=c(:);
Nc=length(c);
% Check if length of channel string is too long
% to be read on the screen and warn user
if (length(get(h_coefs,'String'))>30)
warn('Channel vector is too long to fit in screen.',...
'Take a look at it by typing "dfec_global" and "c"');
end;
% Normalize channel if needed
if get(h_norm,'Value'),
c=c/norm(c);
end
% Divide taps into subchannels if needed
if (spacing==1)
ca=[];
cb=[];
C=freqz(c,1,256,'whole');
Ca=[];
Cb=[];
elseif (spacing==1/2)
ca=c(1:2:Nc);
cb=c(2:2:Nc);
C=freqz(c,1,256,'whole');
Ca=freqz(ca,1,256,'whole');
Cb=freqz(cb,1,256,'whole');
end;
% Get SNR
SNR=str2num(get(h_SNR,'String'));
SNR=sort(SNR);
if (~isreal(SNR))
SNR=20;
set(h_SNR,'String','20');
warn('SNR must be a real-valued or "Inf"',[]);
end
% Source parameters
src_type = get(h_source, 'Value');
switch src_type
case 1, Ms = 2; % BPSK
case 2, Ms = 4; % 4-PAM
case 3, Ms = 8; % 8-PAM
case 4, Ms = 16; % 16-PAM
case 5, Ms = 32; % 32-PAM
case 6, Ms = 4; % QPSK
case 7, Ms = 16; % 16-QAM
case 8, Ms = 64; % 64-QAM
case 9, Ms = 256; % 256-QAM
case 10,Ms = 1024; % 1024-QAM
case 11,Ms = 4; % 4-VSB
case 12,Ms = 8; % 8-VSB
case 13,Ms = 16; % 16-VSB
end
% PAM
if src_type < 6,
real_source = 1;
cnstl_type=1;
% QAM
elseif ((6<=src_type) & (src_type<11))
real_source = 0;
cnstl_type=2;
else
real_source = 0;
cnstl_type=3;
end;
[constellation,csig]=make_constellation(cnstl_type,Ms);
% Real noise only when both {source,chan} are real!
if real_source & isreal(c), real_noise = 1; else, real_noise = 0; end;
%%%%%%%%%%%%%%%%%%%%%%%%
% Equalizer Parameters %
%%%%%%%%%%%%%%%%%%%%%%%%
% Get equalizer parameters for FSE+DFE design
% Total number of taps
if length(str2num(get(h_len,'String')))== 1,
Nfd = str2num(get(h_len,'String'));
if Nfd < 2,
warn('Need toal num params Nf+Nd>1',...
'Setting Nf+Nd=2');
Nfd=2;
set(h_len,'String',num2str(2));
end;
% Separate equalizer lengths
elseif length(str2num(get(h_len,'String')))== 2,
Nfd=[];
temp = str2num(get(h_len,'String'));
Nf = temp(1);
Nd = temp(2);
if (Nf<1 | Nd<0)
warn('Need Nf>0 and Nd>=0','Setting Nf=1, Nd=0');
Nf=1;
Nd=0;
elseif (Nf<2 & spacing==1/2)
warn('Need Nf>1 for fractionally spaced designs',...
'Setting Nf=2');
Nf=2;
set(h_len,'String',['[' num2str([Nf Nd]) ']']);
end;
% Any other case
else
warn('Something wrong with length specification.',[]);
end;
% Get delay if in data simulation mode
if (data~=4)
% Cursor delay
switch get(h_deltype,'Value')
% Match channel maximum
% Optimum delay
case 1,
if (isempty(Nfd))
maxdel=floor((Nc+Nf-1)*spacing);
else
maxdel=floor((Nc+Nfd-1)*spacing);
end;
delay=1:maxdel;
set(h_del,'String','');
set(h_del,'Enable','off');
% Maximum tap
case 2,
delay=-1;
set(h_del,'String','');
set(h_del,'Enable','off');
% End of forward filter
case 3,
delay=floor(Nf*spacing);
set(h_del,'String','');
set(h_del,'Enable','off');
% Delay from center-spike init
case 4,
[yy,I]=max(c);
delay=floor((Nf/2+I)*spacing);
set(h_del,'String','');
set(h_del,'Enable','off');
% Range of delays
case 5,
% If was empty
if (isempty(get(h_del,'String')))
if (isempty(Nfd))
maxdel=floor((Nc+Nf-1)*spacing);
else
maxdel=floor((Nc+Nfd-1)*spacing);
end;
set(h_del,'String',['1:' num2str(maxdel)]);
delay=1:maxdel;
% Otherwise get the range and think about it...
else
delay=str2num(get(h_del,'String'));
delay=sort(delay);
end;
% Negative delays?
if (min(delay)<0)
warn('Delay must be positive.',...
'Setting delay to allowable range.');
if (isempty(Nfd))
maxdel=floor((Nc+Nf-1)*spacing);
else
maxdel=floor((Nc+Nfd-1)*spacing);
end;
set(h_del,'String',['1:' num2str(maxdel)]);
delay=1:maxdel;
end;
% Too large?
if ((isempty(Nfd)) & floor((Nc+Nf-1)*spacing)<max(delay))
warn('Delay outside achievable range',...
'Setting delay to allowable range.');
maxdel=floor((Nc+Nf-1)*spacing);
set(h_del,'String',['1:' num2str(maxdel)]);
delay=1:maxdel;
elseif floor((Nc+Nfd-1)*spacing)<max(delay)
warn('Delay outside achievable range',...
'Setting delay to allowable range.');
maxdel=floor((Nc+Nfd-1)*spacing);
set(h_del,'String',['1:' num2str(maxdel)]);
delay=1:maxdel;
end;
set(h_del,'Enable','on');
end;
end;
% Processing delay
pdelay=str2num(get(h_proc,'String'));
if (pdelay<1)
warn('Processing delay must be greater than or equal to 1',...
'Setting processing delay to 1');
set(h_proc,'String','1');
pdelay=1;
elseif pdelay>floor((Nc+Nf-1)*spacing)
warn('Processing delay too long',...
'Setting processing delay to 1');
set(h_proc,'String','1');
pdelay=1;
elseif (length(pdelay)>1)
warn('Processing delay should be scalar',...
'Setting processing delay to 1');
set(h_proc,'String','1');
pdelay=1;
end;
% bias
if get(h_bias,'Value'),
bias=0;
else
bias=1;
end;
%%%%%%%%%%%%%%%%%%%%%%%%%
% Adaptation Parameters %
%%%%%%%%%%%%%%%%%%%%%%%%%
% handle the "initialization type" setting
read_var=0;
read_init=0;
if (isempty(Nfd))
% Zero initialization
switch get(h_init,'Value')
case 1,
f0=zeros(Nf,1);
d0=zeros(Nd,1);
set(h_f0,'String',['[' num2str(f0.') ']']);
set(h_d0,'String',['[' num2str(d0.') ']']);
set(h_f0,'Enable','inactive');
set(h_d0,'Enable','inactive');
% Single, center-spike initialization
case 2,
f0=zeros(Nf,1);
f0(ceil(Nf/2))=1;
d0=zeros(Nd,1);
set(h_f0,'String',['[' num2str(f0.') ']']);
set(h_d0,'String',['[' num2str(d0.') ']']);
set(h_f0,'Enable','inactive');
set(h_d0,'Enable','inactive');
% Double, center-spike initialization
case 3,
f0=zeros(Nf,1);
if (Nf>1)
f0(floor(Nf/2))=1;
f0(floor(Nf/2)+1)=1;
else
f0=1;
end;
d0=zeros(Nd,1);
set(h_f0,'String',['[' num2str(f0.') ']']);
set(h_d0,'String',['[' num2str(d0.') ']']);
set(h_f0,'Enable','inactive');
set(h_d0,'Enable','inactive');
% DFE-MMSE initialization
case 4,
% If using external data, cannot create DFE-MMSE init
if (data==3)
warn('Using external data-cannot use DFE-MMSE init',...
'Setting init to "Zero"');
set(h_init,'Value',1);
f0=zeros(Nf,1);
d0=zeros(Nd,1);
set(h_f0,'String',['[' num2str(f0.') ']']);
set(h_d0,'String',['[' num2str(d0.') ']']);
set(h_f0,'Enable','inactive');
set(h_d0,'Enable','inactive');
else
f0=f;
d0=zeros(Nd,1);
d0(1:length(d))=d;
set(h_f0,'String',['[' num2str(f0.') ']']);
set(h_d0,'String',['[' num2str(d0.') ']']);
set(h_f0,'Enable','inactive');
set(h_d0,'Enable','inactive');
end;
% IIR-MMSE initialization
case 5,
if (data==3)
warn('Using external data-cannot use IIR-MMSE init',...
'Setting init to "Zero"');
set(h_init,'Value',1);
f0=zeros(Nf,1);
d0=zeros(Nd,1);
set(h_f0,'String',['[' num2str(f0.') ']']);
set(h_d0,'String',['[' num2str(d0.') ']']);
set(h_f0,'Enable','inactive');
set(h_d0,'Enable','inactive');
else
[f0,d0,fa0,fb0,g]=iirmmse(c,SNR,Nf,spacing);
if ((Nf~=length(f0)) | (Nd~=length(d0)))
warn('IIR-MMSE initialization requires different filter lengths',...
'Changing filter length settings in EQUALIZER PARAMETERS');
end;
Nf=length(f0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -