Index exceeds matrix dimensions
Show older comments
My matlab code is as follows
function [g,shift,M] = nsgcqwin(fmin,fmax,bins,sr,Ls,varargin)
% Set defaults
bwfac = 1;
min_win = 4;
fractional = 0;
winfun = 'hann';
gamma = 0;
% Check input arguments
if nargin < 5
error('Not enough input arguments');
end
if nargin >= 6
Lvar = length(varargin);
if mod(Lvar,2)
error('Invalid input argument');
end
for kk = 1:2:Lvar
if ~ischar(varargin{kk})
error('Invalid input argument');
end
switch varargin{kk}
case {'min_win'}
min_win = varargin{kk+1};
case {'gamma'}
gamma = varargin{kk+1};
case {'bwfac'}
bwfac = varargin{kk+1};
case {'fractional'}
fractional = varargin{kk+1};
case {'winfun'}
winfun = varargin{kk+1};
otherwise
error(['Invalid input argument: ', varargin{kk}]);
end
end
end
nf = sr/2;
if fmax > nf
fmax = nf;
end
fftres = sr / Ls;
b = floor(bins * log2(fmax/fmin));
fbas = fmin .* 2.^((0:b).'./bins);
Q = 2^(1/bins) - 2^(-1/bins);
cqtbw = Q*fbas + gamma; cqtbw = cqtbw(:);
%make sure the support of highest filter won't exceed nf
tmpIdx = find(fbas+cqtbw/2>nf,1,'first');
if (~isempty(tmpIdx))
fbas = fbas(1:tmpIdx-1);
cqtbw = cqtbw(1:tmpIdx-1);
end
%make sure the support of the lowest filter won't exceed DC
tmpIdx = find(fbas-cqtbw/2<0,1,'last');
if (~isempty(tmpIdx))
fbas = fbas(tmpIdx+1:end);
cqtbw = cqtbw(tmpIdx+1:end);
warning(['fmin set to' num2str(fftres*floor(fbas(1)/fftres),6) ' Hz!']);
end
Lfbas = length(fbas);
fbas = [0;fbas];
fbas(Lfbas+2) = nf;
fbas(Lfbas+3:2*(Lfbas+1)) = sr-fbas(Lfbas+1:-1:2);
bw = [2*fmin; cqtbw; fbas(Lfbas+3)-fbas(Lfbas+1); cqtbw(end:-1:1)];
fftres = sr / Ls;
bw = bw / fftres;
fbas = fbas / fftres;
% center positions of filters in DFT frame
posit = zeros(size(fbas));
posit(1:Lfbas+2) = floor(fbas(1:Lfbas+2));
posit(Lfbas+3:end) = ceil(fbas(Lfbas+3:end));
shift = [mod(-posit(end),Ls); diff(posit)];
if fractional
corr_shift = fbas-posit;
M = ceil(bw+1);
else
bw = round(bw);
M = bw;
end
for ii = 1:2*(Lfbas+1)
if bw(ii) < min_win;
bw(ii) = min_win;
M(ii) = bw(ii);
end
end
if fractional
g = arrayfun(@(x,y,z) ...
winfuns(winfun,([0:ceil(z/2),-floor(z/2):-1]'-x)/y)/sqrt(y),corr_shift,...
bw,M,'UniformOutput',0);
else
g = arrayfun(@(x) winfuns(winfun,x),...
bw,'UniformOutput',0);
end
M = bwfac*ceil(M/bwfac);
% Setup Tukey window for 0- and Nyquist-frequency
for kk = [1,Lfbas+2]
if M(kk) > M(kk+1);
g{kk} = ones(M(kk),1);
g{kk}((floor(M(kk)/2)-floor(M(kk+1)/2)+1):(floor(M(kk)/2)+...
ceil(M(kk+1)/2))) = winfuns('hann',M(kk+1));
g{kk} = g{kk}/sqrt(M(kk));
end
end
and the error i am getting is this
_Index exceeds matrix dimensions.
Error in nsgcqwin (line 161) bw = [2*fmin; cqtbw; fbas(Lfbas+3)-fbas(Lfbas+1); cqtbw(end:-1:1)];
Error in slicq (line 124) [g,shift,M] = nsgcqwin(fmin,fmax,bins,sr,sl_len,'min_win',min_win,'bwfac',4,'fractional',1,'winfun','modblackharr'); _
1 Comment
Matt J
on 13 Sep 2017
In,
fbas(Lfbas+3)-fbas(Lfbas+1)
what are the values of Lfbas and what is the size of fbas?
Answers (0)
Categories
Find more on MATLAB Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!