I'm trying to set up a piecewise transfer function of a filter in matlab to get its impulse response. I have the code below:
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;
But it gives me this error, when I try to run:
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));
Am I going about this the right way or is there an easier way to do something like this?
I think the problem is that:
H(region2) = exp((-0.5*(w(region1))*1i*nd));
Should be:
H(region2) = exp((-0.5*(w(region2))*1i*nd));
Where region1
is corrected as region2
.
Also, nd
is always 0.
You ask if you're going about it the right way, seems decent enough to me as long as you realize the frequency response between the points you specify could be all over the place, or not depending on the transitions.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.