www.pudn.com > tryGUI.rar > uwbsim.m
function varargout = uwbsim(varargin)
% UWBSIM M-file for uwbsim.fig
% UWBSIM, by itself, creates a new UWBSIM or raises the existing
% singleton*.
%
% H = UWBSIM returns the handle to a new UWBSIM or the handle to
% the existing singleton*.
%
% UWBSIM('Property','Value',...) creates a new UWBSIM using the
% given property value pairs. Unrecognized properties are passed via
% varargin to uwbsim_OpeningFcn. This calling syntax produces a
% warning when there is an existing singleton*.
%
% UWBSIM('CALLBACK') and UWBSIM('CALLBACK',hObject,...) call the
% local function named CALLBACK in UWBSIM.M with the given input
% arguments.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help uwbsim
% Last Modified by GUIDE v2.5 31-Dec-2004 12:03:40
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @uwbsim_OpeningFcn, ...
'gui_OutputFcn', @uwbsim_OutputFcn, ...
'gui_LayoutFcn', [], ...
'gui_Callback', []);
if nargin & isstr(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before uwbsim is made visible.
function uwbsim_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin unrecognized PropertyName/PropertyValue pairs from the
% command line (see VARARGIN)
% Choose default command line output for uwbsim
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes uwbsim wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = uwbsim_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in Run_button.
function Run_button_Callback(hObject, eventdata, handles)
% hObject handle to Run_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Dg=str2double(get(handles.Dg_input,'String')); %高斯脉冲宽度
Ts=str2double(get(handles.Ts_input,'String')); %信号采样间隔
Tf=str2double(get(handles.Tf_input,'String')); %Tf=80,duty_cycle=1:160
NCM=str2double(get(handles.CM_input,'String')); %信道环境CM1-CM4
Th=str2double(get(handles.Th_input,'String')); %信道冲激相应间隔
SNR_db=str2double(get(handles.snr_input,'String')); %输入信噪比
N_path=str2double(get(handles.Nb_input ,'String')); %The number of RAKE Branches
%=======第一部分:基本参数========
Num_Tf=Tf/Ts; %每个符号持续时间内采样点个数
Num_pluse= Dg/Ts;
Eb=Eb_halfcos(Ts,Dg); %一个脉冲周期内的码元能量
%信道估计需要的训练序列长度
N_monocycle=str2double(get(handles.Tr_length ,'String'));;
A=ones(1,N_monocycle);
%数据长度
N_Data=str2double(get(handles.N_datainput,'String'));
%========第二部分:生成基本波形==========
%产生占空比1:160的半余弦脉冲波形,脉冲波形的占空比可以通过Tf调整
Tf0=80;
gt=waveshape(Dg,Ts,Tf0);
gt_len=length(gt);
%========第三部分:生成信道冲激响应及高斯白噪声==========
Th=Dg; %信道冲激响应间隔
h0=UWB_SV_channel(2,NCM,Th); %信道冲激响应
h1=h0(:,2);
h=n_upsample(h1,Th,Ts);
figure(1);
plot(0:Th:(length(h1)-1)*Th,h1);
title('SV信道模型CM4环境下的信道冲激相应');
xlabel('Time(ns)');ylabel('Gain');
clear h0 h1 Th;
%=============
pn_code=[1,1,1,1,1,-1,-1,1,1,-1,1,-1,1];
%pn_code=1;
N_symbol = length (pn_code); % PN码长度
gt1=waveshape(Dg,Ts,Tf); %实际的数据波形,占空比为1:Tf1
Sim_Data=randn(1,N_Data)>0; %产生数据序列;
%---------------------------------------------
Noise_sigma=sqrt(Eb/(1*Dg*10^(SNR_db/10))); %S/N=(Eb/T)/(N0*B) 高斯白噪声
%============第四部分:信道估计过程==========================
%信道估计过程
st=gt'*A;
st=reshape(st,1,[]); %理想发送信号
%画图语句,不影响程序
% figure(1);
% subplot(2,1,1);
% plot(0:Ts:(length(st)-1)*Ts,st);
rt=conv(st,h);
rt_len=length(rt); %通过信道后的信号
%------------------
rt=rt +Noise_sigma*randn(1,rt_len); %接收信号
% %画图语句,不影响程序
% subplot(2,1,2);
% plot([0:Ts:(rt_len-1)*Ts],rt);
[peak_h,t_h]=ch_est(rt,Ts,N_monocycle,gt,Tf0,Dg,h);
[Tao,Atten]=selectpath(peak_h,t_h,N_path); %选择比较大的多径分量;N_path表示所需要的多径数
clear st rt rt_len peak_h t_h;
%===================信道估计过程到此结束=====================
%==============第五部分:同步以及信号接收==============
%g=[1 0 0 0 0 1 0 1 1 0 1 0 1 0 1 1]; %卷积编码生成矩阵
%k0=1; %编码器一次输入个数
%coded_Data=cnv_encd(g,k0,Sim_Data); %卷积编码后的数据
%Total_Num=length(coded_Data);
%syn_training=spreadgren(randn(1,12),pn_code); %同步训练序列
spread_Data=spreadgren(Sim_Data,pn_code); %扩频并且加上训练序列(未扩频的)后的数据,[1,-1]
%trans_data=[syn_training,spread_Data];
Train_st0=gt1'*spread_Data;
Train_st1=reshape(Train_st0,1,[]); %理想发送信号
Train_rt=conv(Train_st1,h);
%clear Train_st0 Train_st1 spread_Data;
Train_rtlen=length(Train_rt);
Train_rt=Train_rt + Noise_sigma*randn(1,Train_rtlen); %接收信号
figure(2);
subplot(2,1,1);
plot(0:Ts:(length(Train_st1)-1)*Ts,Train_st1);
title('理想发射信号');
xlabel('time(ns)');ylabel('amplitude');
subplot(2,1,2);
plot(0:Ts:(length(Train_rt)-1)*Ts,Train_rt);
title('接收机输入信号(CM4,信道冲激响应间隔0.5ns,SNR=5dB)');
xlabel('time(ns)');ylabel('amplitude');
%ref_st=reshape((pn_code'*gt)',1,[]);
%yt=MRC_combine(Tao,Atten,Train_rt,Tf,Ts,N_Data*N_symbol); %多径合并过程,不进行相关积分
yn=MRC_Rake(Tao,Atten,Train_rt,Dg,10,Ts,N_Data,pn_code,gt1);
% subplot(3,1,3);
% plot(0:Ts:(length(yt)-1)*Ts,yt);
% title('RAKE多径合并结果(CM4,信道冲激响应间隔0.5ns,SNR=5dB)');
% xlabel('time(ns)');ylabel('amplitude');
err_bit_rate=sum(abs(yn-Sim_Data))/N_Data;
% clear yn Sim_Data;
% clear Tao Atten Train_rt Noise_sigma;
% end
% end
% ave_err=sum(err_bit_rate)/sim_times;
%[decoder_output,survivor_state,cumulated_metric]=viterbi(g,k0,Rx_Dispread);
%画图
figure(3);
plot(0:Ts:79*Ts,gt(1:80));
title('半余弦脉冲波形');
xlabel('time(ns)');ylabel('amplitude');
temp=ones(1,100);
source_data=reshape((Sim_Data'*temp)',1,[]);
out_data=reshape((yn'*temp)',1,[]);
figure(4);
subplot(2,2,1);
plot(source_data);axis([0 3000 -0.5 1.5 ]);
title('发射数据');
subplot(2,2,2);
plot(4500*Ts:Ts:14500*Ts,Train_st1(4500:14500));axis([4500*Ts 14500*Ts -1 1]);
title('理想发射波形');
xlabel('time(ns)');ylabel('amplitude');
subplot(2,2,3);
plot(out_data);axis([ 0 3000 -0.5 1.5]);
title('判决结果');
subplot(2,2,4);
plot(4500*Ts:Ts:14500*Ts,Train_rt(4500:14500));axis([4500*Ts 14500*Ts -2 2]);
%plot(Train_rt(4500:14500));axis([0 10000 -0.5 0.5 ]);
title('接收机输入信号');
xlabel('time(ns)');ylabel('amplitude');
%===========END of RUN_Button_Callback Function=====================
% --- Executes during object creation, after setting all properties.
function Tf_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to Tf_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes during object creation, after setting all properties.
function N_datainput_CreateFcn(hObject, eventdata, handles)
% hObject handle to N_datainput (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function N_datainput_Callback(hObject, eventdata, handles)
% hObject handle to N_datainput (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of N_datainput as text
% str2double(get(hObject,'String')) returns contents of N_datainput as a double
% --- Executes during object creation, after setting all properties.
function Th_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to Th_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes during object creation, after setting all properties.
function Tr_length_CreateFcn(hObject, eventdata, handles)
% hObject handle to Tr_length (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes during object creation, after setting all properties.
function snr_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to snr_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function snr_input_Callback(hObject, eventdata, handles)
% hObject handle to snr_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of snr_input as text
% str2double(get(hObject,'String')) returns contents of snr_input as a double
% --- Executes during object creation, after setting all properties.
function Nb_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to Nb_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function Nb_input_Callback(hObject, eventdata, handles)
% hObject handle to Nb_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Nb_input as text
% str2double(get(hObject,'String')) returns contents of Nb_input as a double
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton9 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton11.
function pushbutton11_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton11 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton12.
function pushbutton12_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton12 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton15.
function pushbutton15_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton15 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton14.
function pushbutton14_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton14 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton13.
function pushbutton13_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton13 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes during object creation, after setting all properties.
function CM_Input_CreateFcn(hObject, eventdata, handles)
% hObject handle to CM_Input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function CM_Input_Callback(hObject, eventdata, handles)
% hObject handle to CM_Input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of CM_Input as text
% str2double(get(hObject,'String')) returns contents of CM_Input as a double
% --- Executes during object creation, after setting all properties.
function CM_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to CM_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function CM_input_Callback(hObject, eventdata, handles)
% hObject handle to CM_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of CM_input as text
% str2double(get(hObject,'String')) returns contents of CM_input as a double