我正在尝试创建一个信号,然后通过对我首先创建的CT信号进行采样来构建离散时间信号。在最后一个for循环之前,一切正常,但我需要获取N个由T分隔的样本。如果没有if语句,我将得到一个索引越界错误,并且我必须将采样限制在信号持续时间内。由于某些原因,我的代码只进入了if语句一次,并且为了调试,我输出了if和out of if中的值。尽管逻辑运算在多次迭代中应该为true (打印语句将显示值),但它并不打印if语句中的语句。这是怎么回事?
function x = myA2D(b,w,p,T,N)
%MYA2D description: Takes in parameters to construct the CT-sampled DT signal
%b,w,p are Mx1 vectors and it returns Nx1 vector.
timeSpace = 0:0.001:3*pi;
xConstT = zeros(size(timeSpace));
%Construct Xc(t) signal
for k = 1:size(b,1)
temp = b(k) .* cos(w(k).*timeSpace + p(k));
xConstT = xConstT + temp;
end
plot(xConstT);
%Sampling CT-Signal to build DT-signal
disp(strcat('xConstT size',int2str(size(xConstT))));**strong text**
x = zeros(N,1);
sizeConstT = size(xConstT);
for i = 0:N-1
index = i .* T .* 1000 + 1;
disp(strcat('indexoo=',int2str(index)));
disp(strcat('xConstSizeeee',int2str(sizeConstT)));
if index <= sizeConstT
disp(strcat('idx=',int2str(index)));
disp(strcat('xSize',int2str(sizeConstT)));
%x(i+1,1) = xConstT(index);
end
end
endhttps://stackoverflow.com/questions/47616512
复制相似问题