subscript indices must either be real positive integers or logicals( X_re(k_r)=XD(1,kd); can anyone help me why i am getting this error

1 回表示 (過去 30 日間)
irfan
irfan 2016 年 7 月 20 日
回答済み: Adam 2016 年 7 月 20 日
clc clear all N=1024; tic; k=50; d=28; aa=6; b=10; a=3; X=zeros(1,N); % xp_unsolved2=[]; % X_p=randperm(N,k); % X_v1=rand(1,k); % X_v=aa*X_v1+b; % X(X_p)=X_v; sss=[0,1,2,3,4,5,6]; ss=[0,1,2,3];
for snr_num=1:9; snr=snr_num*5+0; for exp_num=1:100; % X=zeros(1,N); X_p=randperm(N,k); X_v1=rand(1,k); X_v=aa*X_v1+b; X(X_p)=X_v; % X_v=[aa+b]; X_re=zeros(1,N); x0=ifft((X));
x=awgn(x0,snr,'measured') ;
enerx=sum(x.^2);
energy=abs(sum(x0.^2));
noise=sum((x-x0).^2);
db=10*log10(abs(enerx/noise));
Len=length(x); x1=0.3*(b/d)^2; x2=0.151; x3=4; X4=8; ssss=6; ss=[0,1,2,3]; for l=0:2*a-1; xd(l,:)=downsample(x(ss(l)+1:Len),d); XD(l,:)=fft(xd(l,:)); end % for l=0:2*a-1 % xd(l+1,:)=downsample(x(1+l:Len),d); % % end % D_len=size(xd,2); % d1=2*d; % XD=fft(xd,D_len,2)*d;
xp_unsolved2=[];
k_zeros=[]; k_two=[]; k_1=[]; kk=0; kk1=0; num_1=0; num_2=0; for kd=1:N/d;
if XD(1,kd).^2 < x1;
k_zeros=[k_zeros,kd+N/d];
else
if abs(abs(XD(1,kd).^2)-abs(XD(2,kd).^2)) <x2;
% if abs(XD(1,kd).^2)-(XD(2,kd).^2) <x2;
k_1 =[];
num_1=num_1+1;
for hhh=1:d
k_1=[k_1,kd+(hhh-1)*N/d];
end
kkk_1(num_1,:)=k_1;
phase= mod(angle(XD(2,kd)/XD(1,kd)),2*pi);
k_estim=phase*N/2/pi+1;
k_com=k_1-k_estim;
[value,posn]=min(abs(k_com));
k_r=k_1(posn);
X_re(k_r)=XD(1,kd);
  1 件のコメント
Adam
Adam 2016 年 7 月 20 日
Simplest way to solve this is just to use the debugger when it should become obvious. Without formatting your code correctly it is very difficult to see easily where your indices are coming from for your arrays.
k_r appears to be the result of a chain of operations which is hard to verify if it is a positive integer or logical or not.

サインインしてコメントする。

回答 (1 件)

Adam
Adam 2016 年 7 月 20 日
At a glance N/d is 1024 / 28 which is not an integer so I imagine
k_1=[k_1,kd+(hhh-1)*N/d];
produces non-integer values and you then use results from this array to index into another array.

カテゴリ

Help Center および File ExchangeMultirate Signal Processing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by