?? 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 + -