《DSP using MATLAB》Problem 6.20
先放子函数:
function [C, B, A, rM] = dir2fs_r(h, r);
% DIRECT-form to Frequency Sampling form conversion
% ----------------------------------------------------------
% [C, B, A, rM] = dir2fs_r(h, r)
% 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
% rM = r^M factor needed in the feedforward loop
% r = radius of the circle over which samples are taken (r<1) 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];
A1 = [1, -r, 0; 1, r, 0];
C1 = [real(H(1)), real(H(L+2))];
else
L = (M-1)/2; % M is odd
%A1 = [1, -1, 0];
A1 = [1, -r, 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*r*cos(2*pi*k/M);
A(1:L, 3) = r*r;
A = [A;A1];
% compute numerator coefficients
B(1:L,1) = cos(phaH(2:L+1));
B(1:L,2) = -r*cos(phaH(2:L+1) - (2*pi*k/M));
% compute gain coefficients
C = [2*magH(2:L+1), C1]'; rM = r^M;
再放主函数:
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 6.20 \n\n'); banner();
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%format long;
format short;
fprintf('\n FIR filter DIRECT-form: \n');
h = [1, 2, 3, 2, 1]/9; b = h
a = 1.0 fprintf('\nConvert DIRECT-form to PARALLEL-form : \n');
[C, Bp, Ap] = dir2par(b, a) if size(C)==0
C = 0;
end fprintf('\nConvert DIRECT-form to CASCADE-form : \n');
[b0, Bc, Ac] = dir2cas(b, a) fprintf('\nConvert TF-form to SOS-form : \n');
[sos, g] = tf2sos(b, a) % ----------------------------------------------------------
% NOTE: linear-phase can not use LATTICE-form
% ----------------------------------------------------------
fprintf('\nConvert DIRECT-form to All-Zero LATTICE-form : \n');
[Klc] = dir2latc(b) fprintf('\nConvert DIRECT-form to FREQUENCY-SAMPLE-form 1 : \n');
[Cfs, Bfs, Afs] = dir2fs(b) fprintf('\nConvert DIRECT-form to FREQUENCY-SAMPLE-form 2 : \n');
r = 0.9;
[Cfs_r, Bfs_r, Afs_r, rM] = dir2fs_r(b, r) % -----------------------------------------
% START check
% -----------------------------------------
n = [0:7];
delta = impseq(0, 0, 7)
%format long
format short
hcas = casfiltr(b0, Bc, Ac, delta) hltc = latcfilt(Klc, delta) %hladr = ladrfilt(Klr, Clr, delta) hdir = filter(b, a, delta)
% -------------------------------------------
% END check
% -------------------------------------------
运行结果:
《DSP using MATLAB》Problem 6.20的更多相关文章
- 《DSP using MATLAB》Problem 5.20
窗外的知了叽叽喳喳叫个不停,屋里温度应该有30°,伏天的日子难过啊! 频率域的方法来计算圆周移位 代码: 子函数的 function y = cirshftf(x, m, N) %% -------- ...
- 《DSP using MATLAB》Problem 4.20
代码: %% ------------------------------------------------------------------------ %% Output Info about ...
- 《DSP using MATLAB》Problem 3.20
代码: %% ------------------------------------------------------------------------ %% Output Info about ...
- 《DSP using MATLAB》Problem 2.20
代码: %% ------------------------------------------------------------------------ %% Output Info about ...
- 《DSP using MATLAB》Problem 7.24
又到清明时节,…… 注意:带阻滤波器不能用第2类线性相位滤波器实现,我们采用第1类,长度为基数,选M=61 代码: %% +++++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 7.23
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output Info a ...
- 《DSP using MATLAB》Problem 6.15
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 6.12
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 6.10
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
随机推荐
- linux nginx 安装防火墙ngx_lua_waf
ngx_lua_waf是一款开源的 基于 ngx_lua的 web应用防火墙 github地址是 https://github.com/loveshell/ngx_lua_waf 安装流程如下 1 ...
- java this的用法
this 含义:代表当前对象 用法: 用于返回对象的引用 示例代码 public class Test { public Test f() { return this;//获取当前对象的引用 } pu ...
- java唯一ID生成
有时我们不依赖于数据库中自动递增的字段产生唯一ID,比如多表同一字段需要统一一个唯一ID,这时就需要用程序来生成一个唯一的全局ID,然后在数据库事务中同时插入到多章表中实现同步. 在java中有个类工 ...
- bzoj3277
题解: 后缀自动机 然后抄了一发题解 可以看看这个博客:http://blog.csdn.net/clover_hxy/article/details/53861268 代码: #include< ...
- 重写equals() 和 hashCode()方法
什么情况下需要重写呢? 比如去重操作时, 有时候往Set集合存放对象User,我们User类的字段太多时,比如有50个字段, 判断两个User对象相同,不需要判断它们所有字段都相同,只需要判断它们的某 ...
- Android: android studio配置生成自定义apk名称
1.Android Studio 3.0之前: 在build.gradled 的 android {} 内添加如下代码: android.applicationVariants.all { varia ...
- Github拉取远端的时候提示“ssh: connect to host github.com port 22: Connection timed out”错误
在使用Github的时候,如果使用到拉取远端分支的时候或者测试ssh -T git@github.com的时候可能会出现连接失败的问题,错误描述为“ssh: connect to host githu ...
- FutureTask
因为实现了runnable接口,所以重写了run方法 Future接口如果用在多线程中,实现类一般是有一个volatile的属性,用来标志状态,比如state,如果事情做完了,那么会设置state为成 ...
- Nginx web服务器
文件读取会使用到以下几个配置 1. sendfile 使用nginx作为静态资源服务时,通过配置sendfile可以有效提高文件读取效率,设置为on表示启动高效传输文件的模式.sendfile可以让N ...
- xshell 评估过期
手头拮据的朋友可以通过下面方法绕过: https://www.netsarang.com/download/down_form.html?code=522 删除XShell. 到英文官网下载页找到XS ...