Creating a Filter bank?

Hi, I need help with creating a filter bank. Here's some ideas on how my code goes:
% Filter Bank
% Filter parameters are a, b, c, and d
c = [0 1];
for a = 1:5 % 5 different a's
for b = 1:5 % 5 different b's
for d = 1:5 % 5 different d's
filter_bank{a,b,c,d} = filter_function(a,b,c(1),d)+ ...
1i * filter_function(a,b,c(2),d)
end
end
end
It gives me this error: ??? The right hand side of this assignment has too few values to satisfy the left hand side.
Any help is appreciated. Thanks!
Edit1: I think I'll just put down the actual codes here. It's the Gabor Filter function posted on MATLAB Central: File Exchange. I don't know how to properly cite the author's work, so please advise too!
% Copyright (c) 2009, Gao Yang
% All rights reserved
% Gabor Filter parameters
lambda = 8;
theta = 0;
psi = [0 pi/2];
gamma = 0.5;
bw = 1;
N = 8;
for n = 1:N
gb = gabor_fn(bw,gamma,psi(1),lambda,theta)+ 1i * ...
gabor_fn(bw,gamma,psi(2),lambda,theta); % gb is the n-th gabor filter
% Then the filtering goes here
end
Here is the function gabor_fn.
function gb=gabor_fn(bw,gamma,psi,lambda,theta)
% bw = bandwidth, (1)
% gamma = aspect ratio, (0.5)
% psi = phase shift, (0)
% lambda= wave length, (>=2)
% theta = angle in rad, [0 pi)
sigma = lambda/pi*sqrt(log(2)/2)*(2^bw+1)/(2^bw-1);
sigma_x = sigma;
sigma_y = sigma/gamma;
sz=fix(8*max(sigma_y,sigma_x));
if mod(sz,2)==0, sz=sz+1;end
% alternatively, use a fixed size
% sz = 60;
[x y]=meshgrid(-fix(sz/2):fix(sz/2),fix(sz/2):-1:fix(-sz/2));
% x (right +)
% y (up +)
% Rotation
x_theta=x*cos(theta)+y*sin(theta);
y_theta=-x*sin(theta)+y*cos(theta);
gb=exp(-0.5*(x_theta.^2/sigma_x^2+y_theta.^2/sigma_y^2)).*cos(2*pi/lambda*x_theta+psi);
Edit2: Here's what I tried.
for bw = 1:1:8 % total: 8
for gamma = 0.5:0.5:3 % total: 6
for lambda = 1:1:10 % total 10
for theta = 0:pi/6:pi % total: 7
gf_bank{bw,gamma,lambda,theta} = gabor_fn(bw,gamma,psi(1),lambda,theta) + 1i * gabor_fn(bw,gamma,psi(2),lambda,theta);
end
end
end
end

댓글 수: 5

Jason
Jason 2011년 6월 30일
Any help, people?
Walter Roberson
Walter Roberson 2011년 6월 30일
Your original code used strictly integer indices. You were asking us to debug on the basis of code that wasn't your real code :(
Jason
Jason 2011년 6월 30일
Hi Walter, awesome, thank you very much! I am now able to see what's wrong with the code that I tried. Correct me if I am wrong, I was using non-integer values as the indices of the bank filter, thus giving me the error. That's why you first defined the values of the parameters that were intended to vary prior to computing the bank, then referenced to them via the () brackets. Am I right?
Jason
Jason 2011년 6월 30일
By the way, forgive me if I am mistaken, I thought it's permissible to modify the code, I just needed to retain the copyright notice. I was needing help with modifying the code to suit the intended application. Is this whole thread inappropriate?
Walter Roberson
Walter Roberson 2011년 6월 30일
Legally speaking, "all rights reserved" includes prohibiting others from making "derivative works". Look, however, at the download page for that file: a few years ago Mathworks changed their rules to insist that any contributions be under one of the open-source licenses. If the contribution does not predate that change-over, then the open-source license would have been mentioned in the download page and you can use that license.

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2011년 6월 28일

1 개 추천

c is a constant array with more than one element, so subscript {a,b,c,d} designates more than one location, but the right hand side only generates a single value.
Warning: using a subscript of 0 is going to lead you to grief...

댓글 수: 11

Jason
Jason 2011년 6월 28일
Thanks, Walter, but I am afraid I don't get what you are meaning. Can you please clarify?
Walter Roberson
Walter Roberson 2011년 6월 28일
Substitute particular loop values. On the first iteration through each of the loops, you are going to be assigning to
filter_bank{1,1,c,1}
where c is a vector of two values. Expanding c, you are asking to assign to
filter_bank{1,1,[0 1],1}
which is the pair of locations
filter_bank{1,1,0,1} and filter_bank{1,1,1,1}
You thus are naming _two_ destinations on your left side, but on your right-hand side you have the _one_ value
filter_function(1,1,0,1) + 1i * filter_function(1,1,1,1)
You are not creating enough values on the right to match the locations you indicate on the right side.
You are also trying to assign to filter_bank{1,1,0,1} but using a numeric subscript of 0 is not allowed in MATLAB, as indexing starts from 1.
I would suggest that what you want is
filter_bank{a,b,d} = filter_function(a,b,c(1),d) + ...
1i * filter_function(a,b,c(2),d);
This would remove both problems at the same time.
Jason
Jason 2011년 6월 28일
That was very well explained, thank you! I tried what you suggested (removing the 'c'), and got this error: Subscript indices must either be real positive integers or logicals. Perhaps this has got something to do with the 'subscript of 0' thing?
Walter Roberson
Walter Roberson 2011년 6월 28일
That could happen if it thought that filter_function was an array instead of a function.
Jason
Jason 2011년 6월 28일
You are right, filter_function, when executed, results in an array of functions. So, am I right to say that I am creating arrays of arrays of functions?
Walter Roberson
Walter Roberson 2011년 6월 28일
filter_function is returning an array of functions? Do you mean an array of coefficients, or do you mean an array of "inline" code, or do you mean an array of anonymous handles?
If the answer is anything other than an array of coefficients, you will not be able to multiply by 1i or to add the arrays.
If filter_function is indeed a function, then the subscript error must have occurred within that function rather than directly in your code.
Walter Roberson
Walter Roberson 2011년 6월 28일
What is
class(filter_function(1,1,1,1))
and
size(filter_function(1,1,1,1))
??
Jason
Jason 2011년 6월 28일
Kindly refer to the additional information up there, thank you. Maybe that will give some hints on what I wanted to achieve.
class(gabor_fn(1,1,1,1,1)) gives me double and size(gabor_fn(1,1,1,1,1)) gives me 5 5.
Walter Roberson
Walter Roberson 2011년 6월 28일
To check: the current error is still about subscripts must be positive integers? Which line does it point to as having the error, and what is the current code for that line?
Jason
Jason 2011년 6월 28일
Thanks for the reply. Please refer to above, the 'Subscript indices must either be real positive integers or logicals' error points to the line: gf_bank{bw,gamma,lambda,theta} = gabor_fn(bw,gamma,psi(1),lambda,theta) + 1i * gabor_fn(bw,gamma,psi(2),lambda,theta);
Walter Roberson
Walter Roberson 2011년 6월 30일
gammavals = 0.5:0.5:3;
thetavals = 0:pi/6:pi;
for bw = 1:1:8 % total: 8
for gammaidx = 1:length(gammavals)
for lambda = 1:1:10 % total 10
for thetaidx = 1:length(thetavals)
gf_bank{bw,gammaidx,lambda,thetaidx} = gabor_fn(bw,gammavals(gammaidx),psi(1),lambda,thetavals(thetaidx)) + 1i * gabor_fn(bw,gammavals(gammaidx),psi(2),lambda,thetavals(thetaidx));
end
end
end
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Phased Array Design and Analysis에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by