function [hh,ww] = freqz(varargin)
%FREQZ Z-transform digital filter frequency response.
% When N is an integer, [H,W] = FREQZ(B,A,N) returns the N-point frequency
% vector W in radians and the N-point complex frequency response vector H
% of the filter B/A:
% jw -jw -jnbw
% jw B(e) b(1) + b(2)e + .... + b(nb+1)e
% H(e) = ---- = ----------------------------
% jw -jw -jnaw
% A(e) a(1) + a(2)e + .... + a(na+1)e
% given numerator and denominator coefficients in vectors B and A. The
% frequency response is evaluated at N points equally spaced around the
% upper half of the unit circle. If N isn't specified, it defaults to 512.
%
% [H,W] = FREQZ(B,A,N,'whole') uses N points around the whole unit circle.
%
% H = FREQZ(B,A,W) returns the frequency response at frequencies
% designated in vector W, in [radians/sample] (normally between 0 and pi).
%
% [H,F] = FREQZ(B,A,N,Fs) and [H,F] = FREQZ(B,A,N,'whole',Fs) given a
% sampling freq Fs in Hz return a frequency vector F in Hz.
%
% H = FREQZ(B,A,F,Fs) given sampling frequency Fs in Hz returns the
% complex frequency response at the frequencies designated in vector F,
% also in Hz.
%
% FREQZ(B,A,...) with no output arguments plots the magnitude and
% unwrapped phase of B/A in the current figure window.
%
% See also FILTER, FFT, INVFREQZ, FREQS and GRPDELAY.
% CAUTION, parameter-value pairs can be used, but this feature will be
% removed in the next release.
% Author(s): J.N. Little, 6-26-86
% Copyright (c) 1988-98 by The MathWorks, Inc.
% $Revision: 1.25.1.2 $ $Date: 1999/01/22 03:42:34 $
% ------------------------- %
% Parse the input arguments %
% ------------------------- %
[params,fvflag] = freqzparse(varargin{:});
% fvflag will be set to one if a freqvector was specified by the user.
b = params.numerator(:).'; % Make it a row vector
a = params.denominator(:).'; %
fs = params.fs;
nb = length(b);
na = length(a);
% ------------------------------------- %
% Actual Frequency Response Computation %
% ------------------------------------- %
if fvflag, % Frequency vector specified. Use Horner's method of polynomial
% evaluation at the frequency points and divide the numerator
% by the denominator.
%
% Note: we use positive i here because of the relationship
% polyval(a,exp(i*w)) = fft(a).*exp(i*w*(length(a)-1))
% ( assuming w = 2*pi*(0:length(a)-1)/length(a) )
%
a = [a zeros(1,nb-na)]; % Make sure a and b have the same length
b = [b zeros(1,na-nb)];
[digw,xlab,xtickflag,xlim] = freqconv(params.freqvector,fs,...
params.frequency,params.normfreq,params.range,'freq2dig'); % Scale w correctly
s = exp(i*digw); % Digital frequency must be used for this calculation
h = polyval(b,s) ./ polyval(a,s);
w = params.freqvector; % Assign the correct freqvector to w
else
% freqvector not specified, use nfft and RANGE in calculation
s = strmatch(lower(params.range),{'whole','half'});
n = params.nfft;
if s*n < na | s*n < nb
nfft = lcm(n,max(na,nb));
% dividenowarn temporarily shuts off warnings to avoid "Divide by zero"
h = dividenowarn(fft([b zeros(1,s*nfft-nb)]),...
fft([a zeros(1,s*nfft-na)])).';
h = h(1+(0:n-1)*nfft/n);
else
% dividenowarn temporarily shuts off warnings to avoid "Divide by zero"
h = dividenowarn(fft([b zeros(1,s*n-nb)]),...
fft([a zeros(1,s*n-na)])).';
h = h(1:n);
end
h = h(:); % Make it a column only when nfft is given (backwards comp.)
[w,xlab,xtickflag,xlim] = freqconv(n,fs,params.frequency,...
params.normfreq,params.range,'dig2freq',params.return_nyquist); % Scale w correctly
w = w(:); % Make it a column only when nfft is given (backwards comp.)
end
% ------------------------------ %
% Plot or Compute the Output %
% ------------------------------ %
if nargout == 0, % Plot when no output arguments are given
% If it's normalized angular frequency divide by pi
% because the plot's x domain is 0 to 1.
if strmatch(params.normfreq,'yes') & strmatch(params.frequency,'angular'),
w = w./pi;
end
freqzplot(h,w,params,fvflag,xlim,xlab,xtickflag);
else % Don't plot, just return the (complex) frequency response.
hh = h;
ww = w;
end
% ------------------------------ %
% Local Functions %
% ------------------------------ %
%------------------------------------------------------------------------------
function freqzplot(h,w,params,fvflag,xlim,xlab,xtickflag)
% FREQZPLOT Plots the Magnitude and Phase response.
%
% Inputs:
% h - complex frequency response vector
% w - frequency vector
% params - structure containing the following fields
% normmag - YES/NO flag indicating if magnitude is normalized
% magnitude - magnitude units string: 'DB', 'LINEAR' or 'SQUARED'
% phase - YES/NO flag indicating if phase plot is required
% range - frequency range, 'WHOLE' or 'HALF', which corresponds to
% [0,Fs) or [0,Fs/2) respectively
% fvflag - flag indicating if a frequency vector was specified by user
% xlim - x-limits which corresponds to correct x-axis units
% xlab - x-axis label with correct units
% xtickFlag - specifies the frequency units (angular, normalized angular,
% linear, etc.)
newplot;
if ishold,
holdflag = 1;
else
holdflag = 0;
end
% Check if we should scale the magnitude, this is for plotting only
[magh,ylab] = correctmag(h,params.normmag,params.magnitude);
if strmatch(lower(params.phase),'yes'),
subplot(212); % We plot the phase first to retain the functionality of freqz when hold is on
plot(w,unwrap(angle(h))*180/pi);
ax = gca;
xlabel(xlab);
ylabel('Phase (degrees)');
subplot(211);
plot(w,magh);
xlabel(xlab);
ylabel(ylab);
ax = [ax gca];
if ~holdflag,
hfig = get(ax(1),'parent');
set(hfig,'nextplot','replace'); % Resets the figure so that next plot does not subplot
end
else,
plot(w,magh);
xlabel(xlab);
ylabel(ylab);
ax = gca;
end
axes(ax(1)); % Always bring the plot to the top
set(ax,'xgrid','on','ygrid','on');
if fvflag,
xlim = [w(1) w(end)]; % If a freqvector was given, overwrite the xlim returned by freqconv
end
% If hold is on, check if xlim in current plot is greater than the new calculated xlim
if holdflag,
currxlim = get(ax(end),'xlim');
xlim(1) = min([currxlim(1) xlim(1)]);
xlim(2) = max([currxlim(2) xlim(2)]);
end
set(ax,'xlim',xlim);
if ~fvflag,
% If xtickflag='normang' sets the ticks of x-axis in units of pi.
%setxticks(ax,params.range,xtickflag);
end
%------------------------------------------------------------------------------
function [magh,ylab] = correctmag(h,normmag,magnitude)
% CORRECTMAG scale the magnitude correctly according to given parameters.
% CORRECTMAG will take the precomputed frequency response vector, h,
% and calculate its magnitude according to the desired parameters.
% MAGNITUDE can be either 'DB','LINEAR' or 'SQUARED' and NORMMAG can be
% either 'YES' (divide everything by maximum value) or 'NO'.
% [MAGH,YLAB] = correctmag(...) returns the correct y-axis label
% YLAB.
magh = abs(h);
ylab = 'Magnitude';
if strmatch(lower(normmag),'yes'),
magh = magh./max(magh);
ylab = ['Normalized ' ylab];
end
if strmatch(lower(magnitude),'db'),
% These next few lines of code are here to avoid "Log of zero" warnings
zerosIndx = find(magh==0); % Find the indicies where magnitude is zero
magh(zerosIndx) = 1; % Place hold
没有合适的资源?快使用搜索试试~ 我知道了~
freqz_matlab求频响_ahead6yh_whole_freqz函数matlab_

共1个文件
m:1个

1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉

温馨提示
MATLAB提供了专门用于求离散系统频响特性的函数freqz(),调用freqz()的格式有以下两种:(1)[Hw]=freqz(BAN)(2)[Hw]=freqz(BAN’whole’) (1)中B和A分别为离散系统的系统函数分子、分母多项式的系数向量,返回量H则包含了离散系统频响在 0~pi范围内N个频率等分点的值(其中N为正整数),w则包含了范围内N个频率等分点。调用默认的N时,其值是512。(2)中调用格式将计算离散系统在0~pi范内的N个频率等分店的频率响应的值。
资源推荐
资源详情
资源评论




























收起资源包目录


共 1 条
- 1
资源评论

- SaulBadman2022-11-16资源有一定的参考价值,与资源描述一致,很实用,能够借鉴的部分挺多的,值得下载。

Dyingalive
- 粉丝: 112
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 培训学习中小学办公软件Office2010word学习笔记.pdf
- 恩网络品牌营销服务说明书--遇见.doc
- 证券交易所综合业务平台市场参与者接口规格说明书.doc
- 基于单片机的模拟电梯系统毕业设计.doc
- 电子商务专业教学指导方案模板.doc
- 通信工程职业生涯规划.doc
- 浅海石油作业无线电通信安全管理规定.doc
- 网络营销广告.pptx
- 国家开放大学电大专科《网络多媒体素材加工》填空题题库.docx
- 调整《AutoCAD》教材内容的授课顺序获奖科研报告论文.docx
- 智能家居之智能照明方案.docx
- 连锁餐饮信息化应用构想(业务部分).pptx
- 流水施工和网络图讲解.pdf
- 天文观测系统工程项目管理总结.doc
- 使用查账-评估软件核查账务有技巧那些?【2017至2018最新会计实务】.doc
- (源码)基于C语言uCOSII框架的乒乓球收集项目.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
