📄 zongy_boxcar.m
字号:
function varargout = zongy_boxcar(varargin)
% ZONGY_BOXCAR M-file for zongy_boxcar.fig
% ZONGY_BOXCAR, by itself, creates a new ZONGY_BOXCAR or raises the existing
% singleton*.
%
% H = ZONGY_BOXCAR returns the handle to a new ZONGY_BOXCAR or the handle to
% the existing singleton*.
%
% ZONGY_BOXCAR('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ZONGY_BOXCAR.M with the given input arguments.
%
% ZONGY_BOXCAR('Property','Value',...) creates a new ZONGY_BOXCAR or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before zongy_boxcar_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to zongy_boxcar_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 zongy_boxcar
% Last Modified by GUIDE v2.5 11-Sep-2007 10:18:14
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @zongy_boxcar_OpeningFcn, ...
'gui_OutputFcn', @zongy_boxcar_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin & isstr(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 zongy_boxcar is made visible.
function zongy_boxcar_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 zongy_boxcar (see VARARGIN)
% Choose default command line output for zongy_boxcar
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes zongy_boxcar wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = zongy_boxcar_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)load Data_7 s i;
fp1=3;fp2=6;fs=20;
N=35; %滤波器的阶数
w1=2*pi*fp1/fs;w2=2*pi*fp2/fs;%将模拟滤波器的指标转换为数字滤波器的指标
wind2=boxcar(N); %使用矩形窗
b2=fir1(N-1,[w1/pi,w2/pi],wind2);%使用标准频率的加窗设计函数fir1
[h2,f2]=freqz(b2,1,512,fs); %在0到fs/2频率范围内选取512个频率点(记录在f中),计算相应的频率响应
axes(handles.axes6);plot(f2,20*log10(abs(h2)));
%xlabel('频率(KHz)');
ylabel('滤波器的幅频响应曲线');grid;
axes(handles.axes7);plot(f2,unwrap(angle(h2)));
xlabel('频率(KHz)');ylabel('滤波器的相频响应曲线');grid;
[gd2 f22]=grpdelay(b2,1,512,20);
tt2=3.4;nn2=tt2*f22;
axes(handles.axes8);plot(nn2,gd2);grid;
xlabel('Samples(n)');ylabel('滤波器的群延迟');
n=-200:200;
t=n/fs;
x=s+i; %叠加之后的混合信号
sf2=filter(b2,1,x); %利用滤波函数对混合信号进行滤波
i2=filter(b2,1,i); %利用滤波函数对噪声信号进行滤波
axes(handles.axes1);plot(t,s);axis([0,8,-10,10]);ylabel('原始信号');grid;
axes(handles.axes2);plot(t,i);axis([0,8,-10,10]);ylabel('噪声信号');grid;
axes(handles.axes3);plot(t,x);axis([0,8,-10,10]);ylabel('混合信号');grid;
axes(handles.axes4);plot(t,sf2);axis([0,8,-10,10]);ylabel('滤波信号');grid;
axes(handles.axes5);plot(t,i2);axis([0,8,-10,10]);ylabel('滤波后的噪声部分');xlabel('单位(ms)');grid;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -