matlab程序,求解错误在哪
%DesignofEquirippleHalf-BandFIRFilter%clear,clfreset,adB=-80;%SpecificationsforExampl...
% Design of Equiripple Half-Band FIR Filter
%
clear, clf reset,
adB=-80; % Specifications for Example No. 2
omp=0.475*pi;
A00=-33.64775299940740; A01=-29.13196870512581;
A10= 18.18840663850262; A11 =18.54155180910656;
N=(adB-A10*omp-A00)/(A11*omp+A01); N=ceil(N);
k00=-0.00665856769717; k01= 1.57111377495119;
k10= 0.37221483652163; k11=-1.01927559802890;
k=(N*omp-k01*N-k00)/(k11*N+k10);
a12=0.01525753184125; a11=0.03682344002622; a10=9.24760314166335;
a01=1.01701406973534; a00=0.73512297663750;
b12=0.00233666682716; b11=-1.35418408482371; b10=5.75145813400838;
b01=1.02999650170704; b00=-0.72759508233144;
AA=(a12*N*N+a11*N+a10)*k+a01*N+a00; BB=(b12*N*N+b11*N+b10)*k+b01*N+b00;
h1=h_uarg(N,k); h2=h_uarg(N-1,k); h = h1_plus_h2(AA*h1,BB*h2);
w01=sqrt(k*k+(1-k*k)*(cos(pi/(2*N+1)))?2); om01=acos(-w01);
vals=abs(freqz(h,1,[om01 pi]));
if 2*floor(N/2)==N extr=vals(2); else extr=-vals(1); end
NN=1+2*(2*N+1); N2=floor(NN/2);
hleft=h(1,1:N2); hright=h(1,N2+2:NN);
h=[hleft/(2*extr) 0.5 hright/(2*extr)]; % Impulse Response
[H,om]=freqz(h,1,10000);
figure(1),
plot(om/pi,20*log10(abs(H))), grid on, axis([0 1 -100 5]),
xlabel(’\omega T/ \pi’), ylabel(’20log|H(e?{j \omega T})| [dB]’),
function [alfa,kc]=uarg(n,kc)
%
if n==0
alfa(2*n+1)=1/(1-kc*kc)?n;
elseif n==1
alfa(2*n+1)=1/(1-kc*kc)?n; alfa(2*n-1)=-(2*n*kc*kc+1)*alfa(2*n+1);
else
alfa=zeros(1,2*n+3);
%initialization
alfa(2*n+1)=1/(1-kc*kc)?n; alfa(2*n-1)=-(2*n*kc*kc+1)*alfa(2*n+1);
alfa(2*n-3)=-(4*n+1+kc*kc*(n-1)*(2*n-1))/2/n*alfa(2*n-1)-(2*n+1)*((n+1)*kc*kc+1)/2/n*alfa(2*n+1);
m=n;
% recursion
for j=m:-1:3
c7=m*(m+2)-(j-3)*(j-1); c5=3*(m*(m+2)-(j-2)*j)+2*j-3 + 2*(j-2)*(2*j-3)*kc*kc;
c3=3*(m*(m+2)-(j-1)*(j+1))+2*(2*j-1)+ 2*j*(2*j-1)*kc*kc; c1=m*(m+2)-(j-1)*(j+1);
alfa(2*j-5)= - (c5*alfa(2*j-3) + c3*alfa(2*j-1) + c1*alfa(2*j+1))/c7;
end
end
function h=h_uarg(m,k)
%
a=uarg(m,k);
ai=0;
for j=0:1:m, ai(1+2*j)=a(1+2*j)/(1+2*j); end
ai=[0 ai];
h=a2h(ai);
这是给出的错误??? Undefined function or method 'h_uarg' for input arguments of type 'double'.
要怎么改呢? 展开
%
clear, clf reset,
adB=-80; % Specifications for Example No. 2
omp=0.475*pi;
A00=-33.64775299940740; A01=-29.13196870512581;
A10= 18.18840663850262; A11 =18.54155180910656;
N=(adB-A10*omp-A00)/(A11*omp+A01); N=ceil(N);
k00=-0.00665856769717; k01= 1.57111377495119;
k10= 0.37221483652163; k11=-1.01927559802890;
k=(N*omp-k01*N-k00)/(k11*N+k10);
a12=0.01525753184125; a11=0.03682344002622; a10=9.24760314166335;
a01=1.01701406973534; a00=0.73512297663750;
b12=0.00233666682716; b11=-1.35418408482371; b10=5.75145813400838;
b01=1.02999650170704; b00=-0.72759508233144;
AA=(a12*N*N+a11*N+a10)*k+a01*N+a00; BB=(b12*N*N+b11*N+b10)*k+b01*N+b00;
h1=h_uarg(N,k); h2=h_uarg(N-1,k); h = h1_plus_h2(AA*h1,BB*h2);
w01=sqrt(k*k+(1-k*k)*(cos(pi/(2*N+1)))?2); om01=acos(-w01);
vals=abs(freqz(h,1,[om01 pi]));
if 2*floor(N/2)==N extr=vals(2); else extr=-vals(1); end
NN=1+2*(2*N+1); N2=floor(NN/2);
hleft=h(1,1:N2); hright=h(1,N2+2:NN);
h=[hleft/(2*extr) 0.5 hright/(2*extr)]; % Impulse Response
[H,om]=freqz(h,1,10000);
figure(1),
plot(om/pi,20*log10(abs(H))), grid on, axis([0 1 -100 5]),
xlabel(’\omega T/ \pi’), ylabel(’20log|H(e?{j \omega T})| [dB]’),
function [alfa,kc]=uarg(n,kc)
%
if n==0
alfa(2*n+1)=1/(1-kc*kc)?n;
elseif n==1
alfa(2*n+1)=1/(1-kc*kc)?n; alfa(2*n-1)=-(2*n*kc*kc+1)*alfa(2*n+1);
else
alfa=zeros(1,2*n+3);
%initialization
alfa(2*n+1)=1/(1-kc*kc)?n; alfa(2*n-1)=-(2*n*kc*kc+1)*alfa(2*n+1);
alfa(2*n-3)=-(4*n+1+kc*kc*(n-1)*(2*n-1))/2/n*alfa(2*n-1)-(2*n+1)*((n+1)*kc*kc+1)/2/n*alfa(2*n+1);
m=n;
% recursion
for j=m:-1:3
c7=m*(m+2)-(j-3)*(j-1); c5=3*(m*(m+2)-(j-2)*j)+2*j-3 + 2*(j-2)*(2*j-3)*kc*kc;
c3=3*(m*(m+2)-(j-1)*(j+1))+2*(2*j-1)+ 2*j*(2*j-1)*kc*kc; c1=m*(m+2)-(j-1)*(j+1);
alfa(2*j-5)= - (c5*alfa(2*j-3) + c3*alfa(2*j-1) + c1*alfa(2*j+1))/c7;
end
end
function h=h_uarg(m,k)
%
a=uarg(m,k);
ai=0;
for j=0:1:m, ai(1+2*j)=a(1+2*j)/(1+2*j); end
ai=[0 ai];
h=a2h(ai);
这是给出的错误??? Undefined function or method 'h_uarg' for input arguments of type 'double'.
要怎么改呢? 展开
展开全部
这段代码太乱了,目前发现有以下问题:
1、把函数(function)和脚本(script)混在一起,这应该是出错最大的原因。h_uarg是一个函数,在后面有定义,但文件的开始却没有function,会被视作脚本。
解决办法:在文件的最前面加一行
function xxx
其中xxx是函数的名字,可以是任何合法标识符(以英文字母开始的字母、数字或下划线序列)。
2、代码中仍有未定义的函数,例如h1_plus_h2、a2h,至于这些函数是什么,你要找提供代码的人,我无法判断这些函数到底完成什么功能。
3、有部分字符错误,例如xlabel和ylabel的单引号应为半角字符('),却被写成全角的了(’或‘);还有5个莫名其妙的问号(?),我猜测应该是乘方的符号(^)。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询