How to create conditions according to the digital signal ?

1 visualización (últimos 30 días)
Awais Saeed
Awais Saeed el 11 de Nov. de 2018
Comentada: Walter Roberson el 11 de Nov. de 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

Respuestas (2)

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

Iniciar sesión para comentar.


madhan ravi
madhan ravi el 11 de Nov. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by