function varargout = WORK1(varargin)
% WORK1 MATLAB code for WORK1.fig
% WORK1, by itself, creates a new WORK1 or raises the existing
% singleton*.
%
% H = WORK1 returns the handle to a new WORK1 or the handle to
% the existing singleton*.
%
% WORK1('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in WORK1.M with the given input arguments.
%
% WORK1('Property','Value',...) creates a new WORK1 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before WORK1_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to WORK1_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 WORK1
% Last Modified by GUIDE v2.5 26-Nov-2017 03:26:12
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @WORK1_OpeningFcn, ...
'gui_OutputFcn', @WORK1_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 WORK1 is made visible.
function WORK1_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 WORK1 (see VARARGIN)
% Choose default command line output for WORK1
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes WORK1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = WORK1_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;
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
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 with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (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 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)
axes(handles.axes1);
cla
axes(handles.axes2);
cla
axes(handles.axes3);
cla
axes(handles.axes4);
cla
S=1.5; %演示时,每次变化之间的停顿时间
LW=1; %画图时,线的宽度
L=get(handles.edit3,'string');%计算圆周卷积的长度,原来是字符型
L=str2num(L); %计算圆周卷积的长度,原来是字符型,现在转为数字
x=get(handles.edit1,'string');%用户手动输入序列x[n]
x=str2num(x); %转成数字型
xLENTH=length(x); %修改x[n]的长度
h=get(handles.edit2,'string');%输入序列h[n]
h=str2num(h); %转成数字型
hLENTH=length(h); %修改h[n]的长度
% 线性卷积
if get(handles.radiobutton1,'value')==1 %选择计算线性卷积
disp('线性卷积') %在Workspace中显示是计算线性卷积
xLinear=[zeros(1,hLENTH-1),x,zeros(1,hLENTH-1)]; %补零处理,相乘、求和时候用到
hLinear=[zeros(1,hLENTH-1),h,zeros(1,xLENTH-1)]; %补零处理,相乘、求和时候用到
hturn=fliplr(h); %反转h[n]
hturn=[hturn,zeros(1,length(hLinear)-hLENTH)]; %反转移位之后的h[n]
Index=(-hLENTH+1):(xLENTH+hLENTH-2); %用于指示补零之后序列的横坐标
IndexY=0:(xLENTH+hLENTH-2); %用于指示线性卷积结果的横坐标
axes(handles.axes1); %设axes1为当前坐标轴
stem(0:xLENTH-1,x,'g','LineWidth',LW); %画出序列x[n]的波形,颜色设置为绿色
axis([-hLENTH xLENTH+hLENTH-1 min(xLinear)-1 max(xLinear)+1]);%限定坐标轴的范围,以便观察信号 [xmin xmax ymin ymax]
grid on; %显示网格,以便观察信号
axes(handles.axes2); %设axes2为当前坐标轴
stem(0:hLENTH-1,h,'r','LineWidth',LW); %画出序列h[n]的波形,颜色设置为红色
axis([-hLENTH xLENTH+hLENTH-1 min(hLinear)-1 max(hLinear)+1]);%限定坐标轴的范围,以便观察信号
grid on;
MaxConvL=max(conv(xLinear,hLinear)); %求出线性卷积的最大值,以便下面画图
MinConvL=min(conv(xLinear,hLinear)); %求出线性卷积的最小值,以便下面画图
xhSum=zeros(1,xLENTH+hLENTH-1); %定义一个全零的数组,用于记录每次求和的结果
pause(S) %停顿以便观察
%移位相乘求和计算线性卷积
for i=1:xLENTH+hLENTH-1
xhMult=xLinear.*hturn; %相乘,即相对应位置上的元素相乘
xhSum(i)=sum(xhMult); %求和
axes(handles.axes3);
stem(Index,hturn,'m','LineWidth',LW); %画反转移位的h[m]
axis([-hLENTH xLENTH+hLENTH-1 min(hLinear)-1 max(hLinear)+1]);
grid on;
axes(handles.axes4);
stem(IndexY,xhSum,'b','LineWidth',LW); %画求和得到的结果
axis([-hLENTH xLENTH+hLENTH-1 min(MinConvL)-1 max(MaxConvL)+1]);
grid on;
pause(S) %停顿以便观察
hturn=[0,hturn(1:length(hturn)-1)]; %每循环一次,向右移位补零之后的h[m]一位,即往前面补一个0
end
end
% 圆周卷积
if get(handles.radiobutton2,'value')==1