% d1 = Passband tolerance % d2 = Stopband tolerance % Rp = Passband ripple
% As = Stopband attenuation %
K = 10^(Rp/20); d1 = (K-1)/(K+1);
d2 = (1+d1)*(10^(-As/20));
function [Rp,As] = delta2db(delta1,delta2)
% Conversion from Absolute delta specs to Relative dB specs % --------------------------------------------------------- % [Rp,As] = delta2db(delta1,delta2) % Rp = Passband ripple
% As = Stopband attenuation % d1 = Passband tolerance % d2 = Stopband tolerance %
Rp = -20*log10((1-delta1)/(1+delta1)); As = -20*log10(delta2/(1+delta1));
function [Xk] = dfs(xn,N)
% Computes Discrete Fourier Series Coefficients % --------------------------------------------- % [Xk] = dfs(xn,N)
% Xk = DFS coeff. array over 0 <= k <= N-1
% xn = One period of periodic signal over 0 <= n <= N-1 % N = Fundamental period of xn %
n = [0:1:N-1]; % row vector for n k = [0:1:N-1]; % row vecor for k WN = exp(-j*2*pi/N); % Wn factor
nk = n'*k; % creates a N by N matrix of nk values
WNnk = WN .^ nk; % DFS matrix
Xk = xn * WNnk; % row vector for DFS coefficients
function [Xk] = dft(xn,N)
% Computes Discrete Fourier Transform % -----------------------------------
31
% [Xk] = dft(xn,N)
% Xk = DFT coeff. array over 0 <= k <= N-1 % xn = N-point finite-duration sequence % N = Length of DFT %
n = [0:1:N-1]; % row vector for n k = [0:1:N-1]; % row vecor for k WN = exp(-j*2*pi/N); % Wn factor
nk = n'*k; % creates a N by N matrix of nk values
WNnk = WN .^ nk; % DFT matrix
Xk = xn * WNnk; % row vector for DFT coefficients
function [b0,B,A] = dir2cas(b,a);
% DIRECT-form to CASCADE-form conversion (cplxpair version) % --------------------------------------------------------- % [b0,B,A] = dir2cas(b,a) % b0 = gain coefficient
% B = K by 3 matrix of real coefficients containing bk's % A = K by 3 matrix of real coefficients containing ak's % b = numerator polynomial coefficients of DIRECT form % a = denominator polynomial coefficients of DIRECT form
% compute gain coefficient b0 b0 = b(1); b = b/b0; a0 = a(1); a = a/a0; b0 = b0/a0; %
M = length(b); N = length(a); if N > M
b = [b zeros(1,N-M)]; elseif M > N
a = [a zeros(1,M-N)]; N = M; else
NM = 0; end %
K = floor(N/2); B = zeros(K,3); A = zeros(K,3); if K*2 == N; b = [b 0]; a = [a 0]; end
32
%
broots = cplxpair(roots(b)); aroots = cplxpair(roots(a)); for i=1:2:2*K
Brow = broots(i:1:i+1,:); Brow = real(poly(Brow)); B(fix((i+1)/2),:) = Brow; Arow = aroots(i:1:i+1,:); Arow = real(poly(Arow)); A(fix((i+1)/2),:) = Arow; end
function [C,B,A] = dir2fs(h)
% Direct form to Frequency Sampling form conversion % ------------------------------------------------- % [C,B,A] = dir2fs(h)
% C = Row vector containing gains for parallel sections
% B = Matrix containing numerator coefficients arranged in rows % A = Matrix containing denominator coefficients arranged in rows% h = impulse response vector of an FIR filter %
M = length(h); H = fft(h,M);
magH = abs(H); phaH = angle(H)'; % check even or odd M if (M == 2*floor(M/2))
L = M/2-1; % M is even A1 = [1,-1,0;1,1,0];
C1 = [real(H(1)),real(H(L+2))]; else
L = (M-1)/2; % M is odd A1 = [1,-1,0]; C1 = [real(H(1))]; end
k = [1:L]';
% initialize B and A arrays B = zeros(L,2); A = ones(L,3); % compute denominator coefficients
A(1:L,2) = -2*cos(2*pi*k/M); A = [A;A1]; % compute numerator coefficients B(1:L,1) = cos(phaH(2:L+1));
B(1:L,2) = -cos(phaH(2:L+1)-(2*pi*k/M)); % compute gain coefficients C = [2*magH(2:L+1),C1]';
33
function [K,C] = dir2ladr(b,a)
% IIR Direct form to pole-zero Lattice/Ladder form Conversion % ----------------------------------------------------------- % [K,C] = dir2ladr(b,a)
% K = Lattice coefficients (reflection coefficients), [K1,...,KN] % C = Ladder Coefficients, [C0,...,CN]
% b = Numerator polynomial coefficients (deg <= Num deg) % a = Denominator polynomial coefficients %
a1 = a(1); a = a/a1; b = b/a1; M = length(b); N = length(a); if M > N
error(' *** length of b must be <= length of a ***') end
b = [b, zeros(1,N-M)]; K = zeros(1,N-1); A = zeros(N-1,N-1); C = b; for m = N-1:-1:1
A(m,1:m) = -a(2:m+1)*C(m+1); K(m) = a(m+1); J = fliplr(a);
a = (a-K(m)*J)/(1-K(m)*K(m)); a = a(1:m);
C(m) = b(m) + sum(diag(A(m:N-1,1:N-m))); end
function [K] = dir2latc(b)
% FIR Direct form to All-Zero Lattice form Conversion % --------------------------------------------------- % [K] = dir2latc(b)
% K = Lattice filter coefficients (reflection coefficients) % b = FIR direct form coefficients (impulse response) %
M = length(b); K = zeros(1,M); b1 = b(1); if b1 == 0
error('b(1) is equal to zero') end
K(1) = b1; A = b/b1; for m=M:-1:2 K(m) = A(m);
34
J = fliplr(A);
A = (A-K(m)*J)/(1-K(m)*K(m)); A = A(1:m-1); end
function [C,B,A] = dir2par(b,a);
% DIRECT-form to PARALLEL-form conversion % -------------------------------------- % [C,B,A] = dir2par(b,a)
% C = Polynomial part when length(b) >= length(a)
% B = K by 2 matrix of real coefficients containing bk's % A = K by 3 matrix of real coefficients containing ak's % b = numerator polynomial coefficients of DIRECT form % a = denominator polynomial coefficients of DIRECT form %
M = length(b); N = length(a);
[r1,p1,C] = residuez(b,a); p = cplxpair(p1,10000000*eps); I = cplxcomp(p1,p); r = r1(I);
K = floor(N/2); B = zeros(K,2); A = zeros(K,3);
if K*2 == N; %N even, order of A(z) odd, one factor is first order for i=1:2:N-2
Brow = r(i:1:i+1,:); Arow = p(i:1:i+1,:);
[Brow,Arow] = residuez(Brow,Arow,[]); B(fix((i+1)/2),:) = real(Brow); A(fix((i+1)/2),:) = real(Arow); end
[Brow,Arow] = residuez(r(N-1),p(N-1),[]);
B(K,:) = [real(Brow) 0]; A(K,:) = [real(Arow) 0]; else
for i=1:2:N-1
Brow = r(i:1:i+1,:); Arow = p(i:1:i+1,:);
[Brow,Arow] = residuez(Brow,Arow,[]); B(fix((i+1)/2),:) = real(Brow); A(fix((i+1)/2),:) = real(Arow); end end
function[y]=dtft-dftplot(w,Xw,k,Xk)
35
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库数字信号处理实验指导(7)在线全文阅读。
相关推荐: