function varargout = main(varargin)
% MAIN MATLAB code for main.fig
% MAIN, by itself, creates a new MAIN or raises the existing
% singleton*.
%
% H = MAIN returns the handle to a new MAIN or the handle to
% the existing singleton*.
%
% MAIN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MAIN.M with the given input arguments.
%
% MAIN('Property','Value',...) creates a new MAIN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before main_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to main_OpeningFcn via varargin.
%
% *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 main
% Last Modified by GUIDE v2.5 24-Mar-2018 12:14:33
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @main_OpeningFcn, ...
'gui_OutputFcn', @main_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(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 main is made visible.
function main_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 command line arguments to main (see VARARGIN)
% Choose default command line output for main
handles.output = hObject;
global data;
data = [];
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes main wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = main_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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%sig_pick = get(handles.,'Value');
global M;
global data;
global k;
global sig_pick;
sig_pick = get(handles.popupmenu2,'Value');
M = str2num(char(get(handles.edit2,'String')));
N = 5;
ook_M = ceil(log2(k));
ook_NRZ = reshape((double(dec2bin(data,ook_M))-48)',1,N*ook_M);
ook_RZ = [ook_NRZ;zeros(1,length(ook_NRZ))];
ook_RZ = ook_RZ(:);
ppm = zeros(1,M*5);
for i = 1:N
ppm(1,(i-1)*M+data(i)+1) = 1;
end
pim_location(1) = 1;
for i = 1:N
pim_location(i+1) = pim_location(i) + data(i) + 1;
end
pim = zeros(1,pim_location(N+1));
pim(pim_location) = 1;
dh_pim_location(1) = 1;
for i = 1:N
dh_pim_location(i+1) = dh_pim_location(i) + data(i) + 3;
if(data(i)>2^M-1)
dh_pim_head_location(i) = dh_pim_location(i)+1;
else
dh_pim_head_location(i) = 1;
end
end
fc = 10;
fs = 1000;
carry_data = repmat(ook_NRZ,fs,1);
carry_data = carry_data(:)';
t_sub = linspace(0,5*ceil(log2(k)),5*ceil(log2(k))*fs);
carry = cos(2*pi*fc*t_sub);
sub_carry = carry_data.*carry;
dh_pim_location_l = unique([dh_pim_head_location,dh_pim_location]);
dh_pim = zeros(1,max(dh_pim_location_l));
dh_pim(dh_pim_location_l) = 1;
if(sig_pick == 1)
figure(1);
t_NRZ = 1:length(ook_NRZ);
stairs(t_NRZ-1,ook_NRZ,'Linewidth',1.5),axis([0,length(ook_NRZ),0,2])
set(gca,'XTick',0:length(ook_NRZ))
end
if(sig_pick == 2)
figure(1);
t_RZ = 1:length(ook_RZ);
stairs((t_RZ-1)/2,ook_RZ,'Linewidth',1.5),axis([0,length(ook_RZ)/2,0,2])
set(gca,'XTick',0:length(ook_RZ))
end
if(sig_pick == 3)
figure(1);
t_ppm = 1:length(ppm);
stairs(t_ppm-1,ppm,'Linewidth',1.5),axis([0,length(ppm),0,2])
set(gca,'XTick',0:length(ppm))
end
if(sig_pick == 4)
figure(1);
t_pim = 1:length(pim);
stairs(t_pim-1,pim,'Linewidth',1.5),axis([0,length(pim),0,2])
set(gca,'XTick',0:length(pim))
end
if(sig_pick == 5)
figure(1);
t_dh_pim = 1:length(dh_pim);
stairs(t_dh_pim-1,dh_pim,'Linewidth',1.5),axis([0,length(dh_pim),0,2])
set(gca,'XTick',0:length(dh_pim))
end
if(sig_pick == 6)
figure(1),
plot(t_sub,sub_carry,'Linewidth',1.5),axis([0,length(ook_NRZ),-2,2])
set(gca,'XTick',0:max(t_sub))
end
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global sig_pick;
global M;
M = str2num(char(get(handles.edit2,'String')));
global k;
k = str2num(char(get(handles.edit1,'String')));
sig_pick = get(handles.popupmenu2,'Value');
switch(sig_pick)
case {1,2,3}
Rb = 1;
Tb = 1/Rb;
df = Rb/100;
f =0:df:8*Rb;
x1 = f*Tb;
x2 = f*Tb/2;
x3 = f*Tb*log2(k)/M;
temp1 = sinc(x1).^2;
temp2 = sinc(x2).^2;
temp3 = sinc(x3).^2;
p1 = 4*temp1;
p2 = 4*temp2;
p3 = 4*temp3;
p1(1) = p1(1)+1;
for i = 1:8
p2(Rb/df*i+1) = p2(Rb/df*i+1)+4*sinc(i*Rb*Tb/2)^2;
end
Psd_NRZ = p1;
Psd_RZ = p2;
Psd_PPM = p3;
if(sig_pick == 1)
figure(2),plot(f,Psd_NRZ),title('OOK NRZ'),xlabel('频率(0-8*Rb)'),ylabel('功率')
end
if(sig_pick == 2)
figure(2),plot(f,Psd_RZ),title('OOK RZ'),xlabel('频率(0-8*Rb)'),ylabel('功率')
end
if(sig_pick == 3)
figure(2),plot(f,Psd_PPM),title('PPM'),xlabel('频率(0-8*Rb)'),ylabel('功率')
end
case{4}
Rb = 1;
Tb = 1/Rb;
L = 2^M;
p_avg = 1;
R = 1;
a = R*L*p_avg;
Ts = M/(L*Rb);
Rs = 1/Ts;
df = Rs/1000;
f = 0:df:8*Rb;
P_sq = (a*Ts)^2*(abs(sinc(f*Ts))).^2;
temp1 = 0;
for k = 1:L-1
temp1 = temp1+(k/L-1).*cos(2*pi*f*k*Ts);
end
S_c = (1/(L*Ts))*(((L-1)/L)+(2/L)*temp1);
S = P_sq.*S_c;
S = S/(((p_avg*R)^2)*Tb);
figure(2),plot(f,S),title('DPPM'),xlabel('频率(0-8*Rb)'),ylabel('功率')
case{5}
Rb = 1;
Tb = 1/Rb;
M = 4;
L = 2^M;
Lavg = .5*(2^M+1);
p_avg = 1;
R = 1;
a = R*Lavg*p_avg;
Ts = M/(Lavg*Rb);
Rs = 1/Ts;
df = Rs/100;
f = 0:df:8*Rb;
x = f*Ts;
r(1) = 2/(L+1);
k = 0;
for k = 1:L
r(k+1) = (2/(L^k))*((L+1)^(k-2));
end
for k = L+1:5*L
temp = 0;
for i = 1:L
temp = temp+r(k-i+1);
end
r(k+1) = (1/L)*temp;
end
for k = (5*L)+1:1000
r(k) = (1/Lavg)^2;
end
P_sq = (a*Ts)^2*(abs(sinc(f*Ts))).^2;
term2 = 0;
for j = 1:length(r)-1
term2 = term2+((r(j+1)-((1/Lavg)^2))*cos(2*j*pi*f*Ts));
end
p = (1/Ts)*P_sq.*((r(1)-1/Lavg^2)+2*term2);
figure(2),plot(f,p),title('DH_PIM'),xlabel('频率(0-8*Rb)'),ylabel('功率')
case{6}
Rb = 1;
Tb = 1/Rb;
f = -4*Rb:Rb/100:4*Rb;
x1 = f*Tb;
temp1 = sinc(x1).^2;
fc = 10;
figure(2),plot(f+fc,4*temp1);title('副载波(fc = 10Rb)'),xlabel('频率fc+(-4*Rb-4*Rb)'),ylabel('功率')
end
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
for M = 1:8
B_ook_RZ(M) = 2;
B_ook_NRZ(M) = 1;
B_ppm(M) = 2^M/M;
B_pim(M) = (2^M+1)/(2*M);
B_dh_pim(M) = (2^(M-1))/(2*M);
B