⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example3_6.m

📁 This complete matlab for neural network
💻 M
字号:
nbits = 8;      % 滤波器阶数
maxbin = 2^nbits-1;     
n=3;             % 滤波器的阶数为n-1
Wn = 0.2;       % 滤波器的截止频率
Rp = 1.5;       % 通带内波纹的分贝值
w = 128;        % 频率点数目
% 连续切比雪夫滤波器设计 
[b1,a1]=cheby1(n-1,Rp, Wn); 
[h,w]=freqz(b1,a1,w);   % 频率响应
h=abs(h);       % 幅频响应
plot(w, h);
title ('Frequency response using non-integer variables')
x = [b1,a1];        % 设计变量

% 设置x的最大最小边界值
if (any(x < 0))
    maxbin = floor (maxbin/2);
    vlb = -maxbin * ones(1, 2*n)-1;
    vub = maxbin * ones(1, 2*n); 
else
    vlb = zeros(1,2*n); 
    vub = maxbin * ones(1, 2*n); 
end

%归一化滤波器系数
[m, mix] = max(abs(x)); 
factor =  maxbin/m; 
x =  factor * x;    % 
xorig = x;
xmask = 1:2*n;
xmask([mix]) = [];
nx = 2*n; 
% 设置算法终止准则,加速解的收敛
options = optimset('Display','iter','TolX',0.1,…
'TolFun',1e-3,'TolCon',1e-6);
if length(w) == 1
   options = optimset(options,'MinAbsMax',w);
else
   options = optimset(options,'MinAbsMax',length(w));
end
%离散化第一个变量
[x, xmask] = elimone(x, xmask, h, w, n, maxbin)

niters = length(xmask); 
for m = 1:niters
%计算最优的离散整数值
x(xmask) = fminimax('filtobj',x(xmask),[],[],[],[],vlb(xmask),…
vub(xmask),'filtcon',options, x, xmask, n, h, maxbin);
[x, xmask] = elimone(x, xmask, h, w, n, maxbin);
end

xold = x;
xmask = 1:2*n;
xmask([n+1, mix]) = [];
x = x + 0.5; 
for i = xmask
    [x, xmask] = elimone(x, xmask, h, w, n, maxbin);
end
xmask = 1:2*n;
xmask([n+1, mix]) = [];
x= x - 0.5;
for i = xmask
    [x, xmask] = elimone(x, xmask, h, w, n, maxbin);
end
if any(abs(x) > maxbin)
x = xold;
end

% 优化滤波器的频率响应
subplot(211)
bo = x(1:n); 
ao = x(n+1:2*n); 
h2 = abs(freqz(bo,ao,128));
plot(w,h,w,h2,'o')
title('Optimized filter versus original')

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -