我试图在matlab中设置一个滤波器的分段传递函数来获得它的脉冲响应。我有以下代码:
function H = H(w)
H = zeros(size(w)); % Preallocating enough memory for y
nd = 0;
region1 = (abs(w)<(pi/4)) & (abs(w)>(pi/8)) ; % First interval
H(region1) = exp((-(w(region1))*1i*nd));
region2 = (abs(w)<(7*pi/8)) & (abs(w)>(5*pi/8)); % Second interval
H(region2) = exp((-0.5*(w(region1))*1i*nd));
region3 = ~(abs(w)<(pi/4)) & (abs(w)>(pi/8)) & ~(abs(w)<(7*pi/8)) & (abs(w)>(5*pi/8)) ; % Third interval
H(region3) = 0;
但是当我尝试运行时,它给了我这个错误:
In an assignment A(I) = B, the number of elements in B and I must be the same.Error
in H (line 9)
H(region2) = exp((-0.5*(w(region1))*1i*nd));
我是以正确的方式去做,还是有更简单的方法来做这样的事情?