How to create conditions according to the digital signal ?

3 次查看(过去 30 天)
If i have a digital signal and if first 2 bits are 10(i have designed the pulse to have 10 as first two bits), then xp and yp should be assigned a value. The code is matching only the first bit with the digital signal it is not matching the second bit.
clc
clear all
close all
t=0:0.01:6;
fm=0.5;
pulse=(0.5).*square(2.*pi*fm.*t)+0.5;
subplot(2,1,1)
plot(t,pulse)
L=length(t)
for i=1:L
if pulse(i)==1 && pulse(i-1)==0
xp=0.402
yp=0.597
else if pulse(i)==1 && pulse(i-1)==1
xp=0.435
yp=0.290
end
end
end

回答(2 个)

Walter Roberson
Walter Roberson 2018-11-11
You are checking backwards, looking at location i and then at the one before that.
Note you will have a problem when i is 1 as that could try to access location 1-1 = 0
  2 个评论
Awais Saeed
Awais Saeed 2018-11-11
by backwards you mean right to left of signal? how can i make the matching correct
Walter Roberson
Walter Roberson 2018-11-11
t=0:0.01:6;
fm=0.5;
pulse=(0.5).*square(2.*pi*fm.*t)+0.5;
subplot(2,1,1)
plot(t,pulse)
L=length(t)
if pulse(1)==1 && pulse(2)==0
xp=0.402
yp=0.597
elseif pulse(1)==1 && pulse(2)==1
xp=0.435
yp=0.290
else
error('What did you intend xp and yp to be if the first bit is not 1?')
end

请先登录,再进行评论。


madhan ravi
madhan ravi 2018-11-11

Community Treasure Hunt

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

Start Hunting!

Translated by