📄 magresp.m
字号:
function magresp(g,varargin);%MAGRESP Magnitude response plot of window% Usage: magresp(g,options);% magresp(g,L,options);% magresp(g,L,sr,options);%% MAGRESP(g) will display the magnitude response of the window g.% This is the DFT of g shown on a log scale normalized such that% the peak is 0 db.%% MAGRESP(g,L) does the same, but extends the window to length L.% Always use this mode for FIR windows, and select an L somewhat% longer than the window to make an accurate plot.%% MAGRESP(g,[],sr) MAGRESP(g,L,sr) will do the same for a window% intended to be used with signals with sampling rate sr. The x-axis% will display Hz.%% If the input window is real, only the positive frequencies will be% shown. Adding the option 'nf' as the last parameter will show the% negative frequencies anyway.% This program is free software: you can redistribute it and/or modify% it under the terms of the GNU General Public License as published by% the Free Software Foundation, either version 3 of the License, or% (at your option) any later version.% % This program is distributed in the hope that it will be useful,% but WITHOUT ANY WARRANTY; without even the implied warranty of% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the% GNU General Public License for more details.% % You should have received a copy of the GNU General Public License% along with this program. If not, see <http://www.gnu.org/licenses/>.error(nargchk(1,4,nargin));L=[];sr=[];donf=0;pcounter=1;for ii=1:length(varargin) if ischar(varargin{ii}) switch(lower(varargin{ii})) case 'nf' donf=1; otherwise error('Unknown option.'); end; end; if isnumeric(varargin{ii}) if pcounter==1 L=varargin{ii}; end; if pcounter==2 sr=varargin{ii}; end; pcounter=pcounter+1; end;end;if isempty(L) L=length(g);end;g=fir2iir(g,L);% Perform unitaty DFT.FF=abs(dft(g));% ScaleFF=FF/max(max(abs(FF)));% Convert to Db. Add eps to avoid log of zero.FF=20*log10(FF+realmin);ymin=max(-100,min(min(FF)));donf=0;if ~isreal(g) donf=1;end;if donf plotff=fftshift(FF); if isempty(sr) xrange=-floor(L/2):ceil(L/2)-1; axisvec=[-L/2 L/2 ymin 0]; else xrange=linspace(-floor(sr/2),ceil(sr/2)-1,L).'; axisvec=[-sr/2 sr/2 ymin 0]; end;else % Only plot positive frequencies for real-valued signals. if isempty(sr) xrange=0:floor(L/2); axisvec=[0 L/2 ymin 0]; else xrange=linspace(0,floor(sr/2),L/2+1).'; axisvec=[0 sr/2 ymin 0]; end; plotff=FF(1:floor(L/2)+1);end;plot(xrange,plotff);axis(axisvec);ylabel('Magnitude response / Db');if isempty(sr) xlabel('Frequency');else xlabel('Frequency / Hz');end;legend('off');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -