How to create conditions according to the digital signal ?

2 Ansichten (letzte 30 Tage)
Awais Saeed
Awais Saeed am 11 Nov. 2018
Kommentiert: Walter Roberson am 11 Nov. 2018
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

Antworten (2)

Walter Roberson
Walter Roberson am 11 Nov. 2018
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 Kommentare
Awais Saeed
Awais Saeed am 11 Nov. 2018
by backwards you mean right to left of signal? how can i make the matching correct
Walter Roberson
Walter Roberson am 11 Nov. 2018
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

Melden Sie sich an, um zu kommentieren.


madhan ravi
madhan ravi am 11 Nov. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by