📄 firdf.asv
字号:
function varargout = firdf(varargin)
% FIRDF M-file for firdf.fig
% FIRDF, by itself, creates a new FIRDF or raises the existing
% singleton*.
%
% H = FIRDF returns the handle to a new FIRDF or the handle to
% the existing singleton*.
%
% FIRDF('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FIRDF.M with the given input arguments.
%
% FIRDF('Property','Value',...) creates a new FIRDF or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before firdf_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to firdf_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 firdf
% Last Modified by GUIDE v2.5 03-Jan-2008 12:38:17
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @firdf_OpeningFcn, ...
'gui_OutputFcn', @firdf_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 firdf is made visible.
function firdf_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 firdf (see VARARGIN)
% Choose default command line output for firdf
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes firdf wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = firdf_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)
figure(1);
[y,Fs,bits]=wavread('wang1.wav');
subplot(2,2,1);
plot(y);title('1 原始信号时域波形');grid
fp=600;fs=1200;
wp=2*fp/Fs;ws=2*fs/Fs;
[N,wn,beta,ftype]=kaiserord([wp ws],[1 0],[0.00001 0.00001]);
N=mod(N,2)+N;
A=kaiser(N+1,beta);
h=fir1(N,wn,ftype,A);
Y=fftfilt(h,y);
subplot(2,2,2);plot(Y);title('低通输出');grid
fp=4800;fsh=6000;
wp=2*fp/Fs;ws=2*fsh/Fs;
[N,wn,beta,ftype]=kaiserord([wp ws],[0 1],[0.00001 0.00001]);
N=mod(N,2)+N;
A=kaiser(N+1,beta);
h=fir1(N,wn,ftype,A);
Y=fftfilt(h,y);
subplot(2,2,3);plot(Y);title('高通输出');grid
fp1=1200;fp2=3000;fs1=600;fs2=4800; %利用凯泽窗设计FIR带通滤波器
wp1=2*fp1/Fs;ws1=2*fs1/Fs;wp2=2*fp2/Fs;ws2=2*fs2/Fs;
[N,wn,beta,ftype]=kaiserord([ws1 wp1 wp2 ws2],[0 1 0],[0.00001 0.00001 0.00001]);
N=mod(N,2)+N;
A=kaiser(N+1,beta); %得到凯泽窗函数
h=fir1(N,wn,ftype,A);
Y=fftfilt(h,y);
subplot(2,2,4);plot(Y);title('4 输出波形');title('带通输出');grid
figure(2);
[y,Fs,bits]=wavread('wang1.wav');
sound(y,Fs);
subplot(3,4,1);
plot(y);title('1 原始信号时域波形');grid
YDFT=fft(y);
subplot(3,4,5);
plot(abs(YDFT));title('4 原始信号幅度谱');grid
fp=600;fs=1200;
wp=2*fp/Fs;ws=2*fs/Fs;
[N,wn,beta,ftype]=kaiserord([wp ws],[1 0],[0.00001 0.00001]);
N=mod(N,2)+N;
A=kaiser(N+1,beta);
h=fir1(N,wn,ftype,A);
w=linspace(0,pi,256);
h5=freqz(h,[1],w);
subplot(3,4,2);plot(w/pi,20*log10(abs(h5)));
title('FIR低通滤波器频率响应');grid
Y=fftfilt(h,y);
subplot(3,4,3);plot(Y);title('低通输出');grid
ylp=fft(Y);
subplot(3,4,4);plot(abs(ylp));title('低通输出频率幅度响应');grid
fp=4800;fsh=6000;
wp=2*fp/Fs;ws=2*fsh/Fs;
[N,wn,beta,ftype]=kaiserord([wp ws],[0 1],[0.00001 0.00001]);
N=mod(N,2)+N;
A=kaiser(N+1,beta);
h=fir1(N,wn,ftype,A);
w=linspace(0,pi,256);
h4=freqz(h,[1],w);
subplot(3,4,6);
plot(w/pi,20*log10(abs(h4)));title('FIR高通滤波器频率响应');grid
Y=fftfilt(h,y);
subplot(3,4,7);plot(Y);title('高通输出');grid
yhp=fft(Y);
subplot(3,4,8);plot(abs(ylp));title('高通输出频率幅度响应');grid
fp1=1200;fp2=3000;fs1=600;fs2=4800; %利用凯泽窗设计FIR带通滤波器
wp1=2*fp1/Fs;ws1=2*fs1/Fs;wp2=2*fp2/Fs;ws2=2*fs2/Fs;
[N,wn,beta,ftype]=kaiserord([ws1 wp1 wp2 ws2],[0 1 0],[0.00001 0.00001 0.00001]);
N=mod(N,2)+N;
A=kaiser(N+1,beta); %得到凯泽窗函数
h=fir1(N,wn,ftype,A);
w=linspace(0,pi,256);
h6=freqz(h,[1],w); %求得频率响应
subplot(3,4,10);
plot(w/pi,20*log10(abs(h6)));title('FIR带通滤波器频率响应');
xlabel('频率/Hz'); ylabel('magnitude');grid
Y=fftfilt(h,y);
subplot(3,4,11);plot(Y);title('4 输出波形');title('带通输出');grid
ybp=fft(Y);
subplot(3,4,12);plot(abs(ylp));title('带通输出频率幅度响应');grid
guide;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -