How to create conditions according to the digital signal ?

조회 수: 2 (최근 30일)
Awais Saeed
Awais Saeed 2018년 11월 11일
댓글: Walter Roberson 2018년 11월 11일
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일

카테고리

Help CenterFile Exchange에서 Pulse and Transition Metrics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by