📄 homework3.asv
字号:
function varargout = homework3(varargin)
% HOMEWORK3 M-file for homework3.fig
% HOMEWORK3, by itself, creates a new HOMEWORK3 or raises the existing
% singleton*.
%
% H = HOMEWORK3 returns the handle to a new HOMEWORK3 or the handle to
% the existing singleton*.
%
% HOMEWORK3('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in HOMEWORK3.M with the given input arguments.
%
% HOMEWORK3('Property','Value',...) creates a new HOMEWORK3 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before homework3_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to homework3_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 homework3
% Last Modified by GUIDE v2.5 08-Oct-2007 20:51:41
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @homework3_OpeningFcn, ...
'gui_OutputFcn', @homework3_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 homework3 is made visible.
function homework3_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 homework3 (see VARARGIN)
% Choose default command line output for homework3
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes homework3 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = homework3_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 selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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)
% 确定所选的信号
type=get(handles.popupmenu1,'Value');
% 信号的采样频率均为100Hz
% 产生时长为10s的信号(-5s到5s)
axes1_title = char('白噪声' ,'单位冲激信号' ,'单位阶越信号', '正弦波', '方波', '三角波', '锯齿波');
t = -5 : 0.01 : 5;
switch type
case 1
%产生时长为10s的白噪声(-5s到5s)
x = wgn(1001,1,1);
case 2
%产生时长为10s的单位冲激信号(-5s到5s)
x = zeros(1001,1);
x(501) = 1;
case 3
%产生时长为10s的单位阶越信号(-5s到5s)
x = zeros(1001,1);
x(501:1001) = 1;
case 4
% 产生时长为10s,频率为1Hz的正弦波信号
x = sin (2*pi*t);
case 5
% 产生时长为10s,频率为1Hz的方波信号
x = square (2*pi*t);
case 6
%产生时长为10s,频率为1Hz的三角波信号
x = sawtooth (2*pi*t,0.5);
case 7
%产生时长为10s,频率为1Hz的锯齿波信号
x = sawtooth(2*pi*t);
end
% 绘制axes1
plot (handles.axes1, x);
axis (handles.axes1, [0,1000,-1.5,1.5]);
title(handles.axes1, axes1_title(type,:));
xlabel(handles.axes1,'times(s)');
ylabel(handles.axes1,'x(t)');
% 按照能量信号的自相关函数公式计算-0.5s到0.5s内的自相关函数值
co = zeros(101,1);
for m = -50:50
for k=-450:450;
co(m+51)=co(m+51)+x(501+k)*x(501+k+m);
end
end
co = co/901;
t2 = [-0.5:0.01:0.5];
% 绘制axes2
plot (handles.axes2, t2, co);
%axis (handles.axes2, [-0.5,0.5,-1,1]);
title(handles.axes2, '自相关函数');
% xlabel(handles.axes2,'times(s)');
% ylabel(handles.axes2,'自相关函数值');
N = 2^ceil(log2(length(x)));
% 绘制axes3
fft1 = fft(x, N);
plot (handles.axes3, fft1);
title(handles.axes3, 'Matlab的fft结果');
% 绘制axes5
ifft1 = ifft(fft1, N);
plot (handles.axes5, ifft1);
axis (handles.axes5, [0,1000,-1.5,1.5]);
title(handles.axes5, 'Matlab的ifft结果');
% 绘制axes4
fft2 = fft_rec(x, N);
plot (handles.axes4, fft2);
title(handles.axes4, '我的fft结果');
% 绘制axes6
ifft2 = myifft(fft2, N);
% axis (handles.axes6, [-5,5,-1.5,1.5]);
% ifft2 = idft(fft2);
plot (handles.axes6, ifft2);
title(handles.axes6, '我的ifft结果');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -