function varargout = shuzi(varargin)
% SHUZI M-file for shuzi.fig
% SHUZI, by itself, creates a new SHUZI or raises the existing
% singleton*.
%
% H = SHUZI returns the handle to a new SHUZI or the handle to
% the existing singleton*.
%
% SHUZI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SHUZI.M with the given input arguments.
%
% SHUZI('Property','Value',...) creates a new SHUZI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before shuzi_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to shuzi_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 shuzi
% Last Modified by GUIDE v2.5 24-Sep-2015 14:17:23
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @shuzi_OpeningFcn, ...
'gui_OutputFcn', @shuzi_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 shuzi is made visible.
function shuzi_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 shuzi (see VARARGIN)
% Choose default command line output for shuzi
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes shuzi wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = shuzi_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)
close;
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (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 edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
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)
x=str2num(get(handles.edit1,'string'));
grid=300;
t=0:1/grid:length(x); %给出相应的时间序列
for i=1:length(x) %进行码型变换
if(x(i)==1) %若输入的信息是1
for j=1:grid/2
y(grid/2*(2*i-2)+j)=1; %定义前半时间值为1
y(grid/2*(2*i-1)+j)=0; %定义后半时间值为0
end
else
for j=1:grid/2 %反之,输入信息为0
y(grid*(i-1)+j)=0; %定义所有时间值为0
end
end
end
y =[y,x(i)]; %为了画图,注意要将y 序列加上最后一位
M=max(y);
m=min(y);
cla
%subplot(2,1,1);
axes(handles.axes1);
plot(t,y);
axis([0,i,m-0.1,M+0.1]);
title(' 单极性归零信号');
%subplot(2,1,2);
axes(handles.axes2);
w=-90:0.05:90;
z=fftshift(abs(fft(y)));
plot(w,z);
title('单极性归零信号幅度谱');
axis([-5,5,0,1600]);
% --- 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)
x=str2num(get(handles.edit1,'string'));
grid=300;
t=0:1/grid:length(x);
for i=1:length(x) %计算码元的值
if(x(i)==1), %如果信息是1
for j=1:grid, %该码元对应的点值取1
y((i-1)*grid+j)=1;
end
else
for j=1:grid, %反之,信息为0,码元对应点值取0
y((i-1)*grid+j)=0;
end
end
end
y =[y,x(i)];
M=max(y);
m=min(y);
cla
%subplot(2,1,1);
axes(handles.axes1);
plot(t,y);
axis([0,i,m-0.1,M+0.1]);
title(' 单极性不归零信号');
%subplot(2,1,2);
axes(handles.axes2);
w=-90:0.05:90;
z=fftshift(abs(fft(y)));
plot(w,z);
title('单极性不归零信号幅度谱');
axis([-5,5,0,1600]);
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
x=str2num(get(handles.edit1,'string'));
grid=300;
t=0:1/grid:length(x)
for i=1:length(x) %计算码元的值
if(x(i)==1) %如果信息是1
for j=1:grid %该码元对应的点值取1
y((i-1)*grid+j)=1; end
else
for j=1:grid %反之,信息为0,码元对应点值取-1
y((i-1)*grid+j)=-1;end
end
end
y =[y,x(i)]; %为了画图,注意要将y序列加上最后一位
M=max(y);
m=min(y);
axes(handles.axes1);
plot(t,y);
axis([0,i,m-0.1,M+0.1]);
title('双极性不归零信号');
axes(handles.axes2);
w=-90:0.05:90;
z=fftshift(abs(fft(y)));
plot(w,z);
title('双极性不归零信号幅度谱');
axis([-5,5,0,1600]);
% --- 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)
x=str2num(get(handles.edit1,'string'));
grid=300;
t=0:1/grid:length(x); %定义相应的时间序列
for i=1:length(x) %进行编码
if(x(i)==1) %若输入的信息是1
for j=1:grid/2
y(grid/2*(2*i-2)+j)=1; %定义前半时间值为1
y(grid/2*(2*i-1)+j)=0; %定义后半时间值为0
end
else
for j=1:grid/2 %反之,输入信息为0
y(grid/2*(2*i-2)+j)=-1; %定义所有时间值为-1
y(grid/2*(2*i-1)+j)=0; %定义后半时间为0
end
end
end
y =[y,x(i)]; %为了画图,注意要将y 序列加上最后一位
M=max(y);
m=min(y);
cla
axes(handles.axes1);
plot(t,y);
axis([0,i,m-0.1,M+0.1]);
%采用了title 命令来实现标记出各码元对应的二元信息
title('双极性归零信号');
axes(handles.axes2);
w=-90:0.05:90;
z=fftshift(abs(fft(y)));
plot(w,z);
title('双极性归零信号幅度谱');
axis([-5,5,0,1600]);
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure