收藏 分销(赏)

实验用Matlab基本函数.doc

上传人:仙人****88 文档编号:11987522 上传时间:2025-08-25 格式:DOC 页数:24 大小:178.10KB 下载积分:10 金币
下载 相关 举报
实验用Matlab基本函数.doc_第1页
第1页 / 共24页
实验用Matlab基本函数.doc_第2页
第2页 / 共24页


点击查看更多>>
资源描述
实验用Matlab基本函数 1.abs Absolute value (magnitude) Syntax y = abs(x) Description y = abs(x) returns the absolute value of the elements of x. If x is complex, abs returns the complex modulus (magnitude). abs(x) = sqrt(real(x).^2 + imag(x).^2) If x is a MATLAB string, abs returns the numeric values of the ASCII characters in the string. The display format of the string changes; the internal representation does not. The abs function is part of the standard MATLAB language. Example Calculate the magnitude of the FFT of a sequence. t = (0:99)/100; % time vector x = sin(2*pi*15*t) + sin(2*pi*40*t); % signal y = fft(x); % compute DFT of x m = abs(y); % magnitude Plot the magnitude. f = (0:length(y)-1)'/length(y)*100; % frequency vector plot(f,m) 2. angle Phase angle Syntax p = angle(h) Description p = angle(h) returns the phase angles, in radians, of the elements of complex vector or array h. The phase angles lie between - and . For complex sequence h = x + iy = meip, the magnitude and phase are given by m = abs(h) p = angle(h) To convert to the original h from its magnitude and phase, type i = sqrt(-1) h = m.*exp(i*p) The angle function is part of the standard MATLAB language. Example Calculate the phase of the FFT of a sequence. t = (0:99)/100; % time vector x = sin(2*pi*15*t) + sin(2*pi*40*t); % signal y = fft(x); % compute DFT of x p = unwrap(angle(y)); % phase Plot the phase. f = (0:length(y)-1)'/length(y)*100; % frequency vector plot(f,p) Algorithm angle can be expressed as angle(x) = imag(log(x)) = atan2(imag(x),real(x)) 3. besself Bessel analog filter design Syntax [b,a] = besself(n,Wn) [b,a] = besself(n,Wn,'ftype') [z,p,k] = besself(...) [A,B,C,D] = besself(...) Description besself designs lowpass, bandpass, highpass, and bandstop analog Bessel filters. Analog Bessel filters are characterized by almost constant group delay across the entire passband, thus preserving the wave shape of filtered signals in the passband. Digital Bessel filters do not retain this quality, and besself therefore does not support the design of digital Bessel filters. [b,a] = besself(n,Wn) designs an order n lowpass analog filter with cutoff frequency Wn. It returns the filter coefficients in the length n+1 row vectors b and a, with coefficients in descending powers of s, derived from the transfer function Cutoff frequency is the frequency at which the magnitude response of the filter begins to decrease significantly. For besself, the cutoff frequency Wn must be greater than 0. The magnitude response of a Bessel filter designed by besself is always less than at the cutoff frequency, and it decreases as the order n increases. If Wn is a two-element vector, Wn = [w1 w2] with w1 < w2, then besself(n,Wn) returns an order 2*n bandpass analog filter with passband w1 <ω< w2. [b,a] = besself(n,Wn,'ftype') designs a highpass or bandstop filter, where the string 'ftype' is: l 'high' for a highpass analog filter with cutoff frequency Wn l 'stop' for an order 2*n bandstop analog filter if Wn is a two-element vector, Wn = [w1 w2] The stopband is w1 <ω< w2. With different numbers of output arguments, besself directly obtains other realizations of the analog filter. To obtain zero-pole-gain form, use three output arguments as shown below. [z,p,k] = besself(n,Wn) or [z,p,k] = besself(n,Wn,'ftype') returns the zeros and poles in length n or 2*n column vectors z and p and the gain in the scalar k. Algorithm besself performs a four-step algorithm: l It finds lowpass analog prototype poles, zeros, and gain using the besselapfunction. l It converts the poles, zeros, and gain into state-space form. l It transforms the lowpass filter into a bandpass, highpass, or bandstop filterwith desired cutoff frequencies using a state-space transformation. l It converts the state-space filter back to transfer function or zero-pole-gain form, as required. 4. bilinear Bilinear transformation method for analog-to-digital filter conversion Syntax [zd,pd,kd] = bilinear(z,p,k,fs) [zd,pd,kd] = bilinear(z,p,k,fs,Fp) [numd,dend] = bilinear(num,den,fs) [numd,dend] = bilinear(num,den,fs,Fp) [Ad,Bd,Cd,Dd] = bilinear(A,B,C,D,fs) [Ad,Bd,Cd,Dd] = bilinear(A,B,C,D,fs,Fp) Description The bilinear transformation is a mathematical mapping of variables. In digital filtering, it is a standard method of mapping the s or analog plane into the z or digital plane. It transforms analog filters, designed using classical filter design techniques, into their discrete equivalents. Zero-Pole-Gain [zd,pd,kd] = bilinear(z,p,k,fs) and [zd,pd,kd] = bilinear(z,p,k,fs,Fp) convert the s-domain transfer function specified by z, p, and k to a discrete equivalent. Inputs z and p are column vectors containing the zeros and poles, k is a scalar gain, and fs is the sampling frequency in hertz. bilinear returns the discrete equivalent in column vectors zd and pd and scalar kd. Fp is the optional match frequency, in hertz, for prewarping. Transfer Function [numd,dend] = bilinear(num,den,fs) and [numd,dend] = bilinear(num,den,fs,Fp) convert an s-domain transfer function given by num and den to a discrete equivalent. Row vectors num and den specify the coefficients of the numerator and denominator, respectively, in descending powers of s. fs is the sampling frequency in hertz. bilinear returns the discrete equivalent in row vectors numd and dend in descending powers of z (ascending powers of z-1). Fp is the optional match frequency, in hertz, for prewarping. 5. butter Butterworth analog and digital filter design Syntax [b,a] = butter(n,Wn) [b,a] = butter(n,Wn,'ftype') [b,a] = butter(n,Wn,'s') [b,a] = butter(n,Wn,'ftype','s') [z,p,k] = butter(...) [A,B,C,D] = butter(...) Description butter designs lowpass, bandpass, highpass, and bandstop digital and analog Butterworth filters. Butterworth filters are characterized by a magnitude response that is maximally flat in the passband and monotonic overall. Butterworth filters sacrifice rolloff steepness for monotonicity in the pass- and stopbands. Unless the smoothness of the Butterworth filter is needed, an elliptic or Chebyshev filter can generally provide steeper rolloff characteristics with a lower filter order. Digital Domain [b,a] = butter(n,Wn) designs an order n lowpass digital Butterworth filter with cutoff frequency Wn. It returns the filter coefficients in length n+1 row vectors b and a, with coefficients in descending powers of z. Cutoff frequency is that frequency where the magnitude response of the filter is . For butter, the normalized cutoff frequency Wn must be a number between 0 and 1, where 1 corresponds to the Nyquist frequency, π radians per sample. If Wn is a two-element vector, Wn = [w1 w2], butter returns an order 2*n digital bandpass filter with passband w1 <ω< w2. [b,a] = butter(n,Wn,'ftype') designs a highpass or bandstop filter, where the string 'ftype' is either: l 'high' for a highpass digital filter with cutoff frequency Wn l 'stop' for an order 2*n bandstop digital filter if Wn is a two-element vector, Wn = [w1 w2]. The stopband is w1 <ω< w2. With different numbers of output arguments, butter directly obtains other realizations of the filter. To obtain zero-pole-gain form, use three output arguments as shown below. [z,p,k] = butter(n,Wn) or [z,p,k] = butter(n,Wn,'ftype') returns the zeros and poles in length n column vectors z and p, and the gain in the scalar k. Analog Domain [b,a] = butter(n,Wn,'s') designs an order n lowpass analog Butterworth filter with cutoff frequency Wn rad/s. It returns the filter coefficients in the length n+1 row vectors b and a, in descending powers of s, derived from the transfer function butter's cutoff frequency Wn must be greater than 0 rad/s. If Wn is a two-element vector with w1 < w2, butter(n,Wn,'s') returns an order 2*n bandpass analog filter with passband w1 <ω< w2. [b,a] = butter(n,Wn,'ftype','s') designs a highpass or bandstop filter. With different numbers of output arguments, butter directly obtains other realizations of the analog filter. To obtain zero-pole-gain form, use three output arguments as shown below. [z,p,k] = butter(n,Wn,'s') or [z,p,k] = butter(n,Wn,'ftype','s') returns the zeros and poles in length n or 2*n column vectors z and p and the gain in the scalar k. Examples Example 1 For data sampled at 1000 Hz, design a 9th-order highpass Butterworth filter with cutoff frequency of 300 Hz. [b,a] = butter(9,300/500,'high'); The filter's frequency response is freqz(b,a,128,1000) Example 2 Design a 10th-order bandpass Butterworth filter with a passband from 100 to 200 Hz and plot its impulse response, or unit sample response. n = 5; Wn = [100 200]/500; [b,a] = butter(n,Wn); [y,t] = impz(b,a,101); stem(t,y) 6. cheby1 Chebyshev Type I filter design (passband ripple) Syntax [b,a] = cheby1(n,Rp,Wn) [b,a] = cheby1(n,Rp,Wn,'ftype') [b,a] = cheby1(n,Rp,Wn,'s') [b,a] = cheby1(n,Rp,Wn,'ftype','s') [z,p,k] = cheby1(...) [A,B,C,D] = cheby1(...) Description cheby1 designs lowpass, bandpass, highpass, and bandstop digital and analog Chebyshev Type I filters. Chebyshev Type I filters are equiripple in the passband and monotonic in the stopband. Type I filters roll off faster than type II filters, but at the expense of greater deviation from unity in the passband. Digital Domain [b,a] = cheby1(n,Rp,Wn) designs an order n Chebyshev lowpass digital Chebyshev filter with cutoff frequency Wn and Rp dB of peak-to-peak ripple in the passband. It returns the filter coefficients in the length n+1 row vectors b and a, with coefficients in descending powers of z. Cutoff frequency is the frequency at which the magnitude response of the filter is equal to -Rp dB. For cheby1, the cutoff frequency Wn is a number between 0 and 1, where 1 corresponds to the Nyquist frequency, π radians per sample. Smaller values of passband ripple Rp lead to wider transition widths (shallower rolloff characteristics). If Wn is a two-element vector, Wn = [w1 w2], cheby1 returns an order 2*n bandpass filter with passband w1 <ω< w2. [b,a] = cheby1(n,Rp,Wn,'ftype') designs a highpass or bandstop filter, where the string 'ftype' is either: l 'high' for a highpass digital filter with cutoff frequency Wn l 'stop' for an order 2*n bandstop digital filter if Wn is a two-element vector, Wn = [w1 w2] The stopband is w1 <ω< w2. With different numbers of output arguments, cheby1 directly obtains other realizations of the filter. To obtain zero-pole-gain form, use three output arguments as shown below. [z,p,k] = cheby1(n,Rp,Wn) or [z,p,k] = cheby1(n,Rp,Wn,'ftype') returns the zeros and poles in length n column vectors z and p and the gain in the scalar k. Analog Domain [b,a] = cheby1(n,Rp,Wn,'s') designs an order n lowpass analog Chebyshev Type I filter with cutoff frequency Wn rad/s. It returns the filter coefficients in length n+1 row vectors b and a, in descending powers of s, derived from the transfer function Cutoff frequency is the frequency at which the magnitude response of the filter is -Rp dB. For cheby1, the cutoff frequency Wn must be greater than 0 rad/s. If Wn is a two-element vector Wn = [w1 w2] with w1 < w2, then cheby1(n,Rp,Wn,'s') returns an order 2*n bandpass analog filter with passband w1 <ω< w2. [b,a] = cheby1(n,Rp,Wn,'ftype','s') designs a highpass or bandstop filter. You can supply different numbers of output arguments for cheby1 to directly obtain other realizations of the analog filter. To obtain zero-pole-gain form, use three output arguments as shown below. [z,p,k] = cheby1(n,Rp,Wn,'s') or [z,p,k] = cheby1(n,Rp,Wn,'ftype','s') returns the zeros and poles in length n or 2*n column vectors z and p and the gain in the scalar k. Examples Example 1: Lowpass Filter For data sampled at 1000 Hz, design a 9th-order lowpass Chebyshev Type I filter with 0.5 dB of ripple in the passband and a cutoff frequency of 300 Hz. [b,a] = cheby1(9,0.5,300/500); The frequency response of the filter is freqz(b,a,512,1000) Example 2: Bandpass Filter Design a 10th-order bandpass Chebyshev Type I filter with a passband from 100 to 200 Hz and plot its impulse response. n = 10; Rp = 0.5; Wn = [100 200]/500; [b,a] = cheby1(n,Rp,Wn); [y,t] = impz(b,a,101); stem(t,y) 7. conv Convolution and polynomial multiplication Syntax c = conv(a,b) Description c = conv(a,b) convolves vectors a and b. The convolution sum is where N is the maximum sequence length. The series is indexed from n + 1 and k + 1 instead of the usual n and k because MATLAB vectors run from 1 to n instead of from 0 to n-1. The conv function is part of the standard MATLAB language. Example The convolution of a = [1 2 3] and b = [4 5 6] is c = conv(a,b) c = 4 13 28 27 18 8. ellip Elliptic (Cauer) filter design Syntax [b,a] = ellip(n,Rp,Rs,Wn) [b,a] = ellip(n,Rp,Rs,Wn,'ftype') [b,a] = ellip(n,Rp,Rs,Wn,'s') [b,a] = ellip(n,Rp,Rs,Wn,'ftype','s') [z,p,k] = ellip(...) [A,B,C,D] = ellip(...) Description ellip designs lowpass, bandpass, highpass, and bandstop digital and analog elliptic filters. Elliptic filters offer steeper rolloff characteristics than Butterworth or Chebyshev filters, but are equiripple in both the pass- and stopbands. In general, elliptic filters meet given performance specifications with the lowest order of any filter type. Digital Domain [b,a] = ellip(n,Rp,Rs,Wn) designs an order n lowpass digital elliptic filter with cutoff frequency Wn, Rp dB of ripple in the passband, and a stopband Rs dB down from the peak value in the passband. It returns the filter coefficients in the length n+1 row vectors b and a, with coefficients in descending powers of z. The cutoff frequency is the edge of the passband, at which the magnitude response of the filter is -Rp dB. For ellip, the cutoff frequency Wn is a number between 0 and 1, where 1 corresponds to half the sampling frequency (Nyquist frequency). Smaller values of passband ripple Rp and larger values of stopband attenuation Rs both lead to wider transition widths (shallower rolloff characteristics). If Wn is a two-element vector, Wn = [w1 w2], ellip returns an order 2*n bandpass filter with passband w1 <ω< w2. [b,a] = ellip(n,Rp,Rs,Wn,'ftype') designs a highpass or bandstop filter, where the string 'ftype' is either: l 'high' for a highpass digital filter with cutoff frequency Wn l 'stop' for an order 2*n bandstop digital filter if Wn is a two-element vector, Wn = [w1 w2]. The stopband is w1 <ω< w2. With different numbers of output arguments, ellip directly obtains other realizations of the fil
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服