我正在编写一个代码来检查Bipolar-RZ。如果你得到一个0,没有任何事情发生,但如果有一个,那么转换发生在中间,从正电压到0,然后从负电压到0电压。 所以我接触到这个的方式是,例如,如果你有b=[0 1 0 1 1 0 1]
。你计算你有多少人。然后你将这些放入for循环并添加它们。然后使用if语句检查添加后的数字是偶数还是奇数,然后转换。 问题是我正在使用另一个for循环,for循环(检查偶数和奇数)进入另一个for循环。使用嵌套for循环并检查数字是偶数还是奇数
也使用iseven和isodd,我在网上搜索。他们有MATLAB中的代码。否则,该功能不起作用。这里是链接:http://www.mathworks.com/matlabcentral/fileexchange/35105-isevenisodd
如果有人回复,我会非常棒。 谢谢
% for ibs, I'm using ibs=[0 1 0 0 1 1 0 0 0 1 1]
function output = lc_bi(ibs,tlc, Rb)
output=1;
numofbits=length(ibs);
% Bipolar RZ coding
if isequal(tlc,'RZ')
%for loop to calculate 1's
y=0;
for k=1:length(ibs)
if ibs(k)==1
y=y+1;
end
end
oness=ones(1,y); %converting it in to list of ones
samptime= 0.001;
endtime= numofbits-samptime;
t=0:samptime:endtime;
cycle= floor(length(t)/(numofbits-1));
j=1;
tran_in_middle= j+cycle/2;
bit=1;
for i=0:samptime:endtime
if (floor(i)+1 ~=bit)
tran_in_middle=j+cycle/2;
bit=bit+1;
end
if (ibs(bit)==1)
if(j< tran_in_middle)
%put the loop her to check if itseven or odd
%using the list of ones here and adding them to check for even and odd
g=0;
for h=1:length(oness)
g=g+1;
if isodd(g)==true
s(j) =Rb;
disp('+')
elseif isodd(g)==false
s(j)=-Rb;
disp('-')
end
end
else
s(j) = 0;
end
end
j=j+1;
end
plot(t,s);
axis([0 numofbits -(Rb+1) (Rb+1)]);
xlabel ('Time');
ylabel ('Voltage');
end
这里有很多代码,但没有指出问题出在哪里。破解你想要做的事情也很困难。也许你可以为你的示例输入提供一个示例输出? – Dan