필터 지우기
필터 지우기

plot binary vs time

조회 수: 4 (최근 30일)
Aswas
Aswas 2018년 8월 3일
답변: Guillaume 2018년 8월 3일
Hi, I have 1's and 0's but want 1's to be plotted as a positive number and o's as negative number:
Code:
if(z>0)
a=1;
else
a=0;
end
mn=[t1 a];
  댓글 수: 2
Guillaume
Guillaume 2018년 8월 3일
"want 1's to be plotted as a positive number"
Which number? +1?
"and o's as negative number"
Which number? -1?
The code snippet you show makes no sense at all and is not commented so we have no idea what its intent is.
Aswas
Aswas 2018년 8월 3일
편집: Guillaume 2018년 8월 3일
It is for PSK demodulation, and yes, -1 and + 1....
% Binary PSK demodulation
mn=[];
for n=ss:ss:length(m)
t=bp/99:bp/99:bp;
y=A*(sin(2*pi*f*t2+pi))%+(sin(2*pi*f*t+pi));
%y=sin(2*pi*f*t)for 0 deg shift; % carrier signal
mm=y.*m((n-(ss-1)):n);% mm=y.*m((n-(ss-1)):n)
t4=bp/99:bp/99:bp;
z=trapz(t4,mm) % intregation method
zz=round((2*z/bp))
if(zz>0)
a=1;
else
a=0;
end
mn=[mn a];
end
disp(' Binary information at Reciver :');
disp(mn);

댓글을 달려면 로그인하십시오.

답변 (1개)

Guillaume
Guillaume 2018년 8월 3일
If you want +1 and -1, why don't you store that in the first place in your vector instead of 1/0?
if zz > 0
a = 1;
else
a = -1;
end
Why go use 0 if you want -1?. If you really do want to do it afterwards for some reason:
%after the loop
mn(mn == 0) = -1;
By the way, there's a lot of variable that get recreated each step of the loop but never change ( t, y, t4). These should be calculated once before the loop. You're just wasting time recalculating the same thing over and over.
Also, the way you construct you mn is very awkward and slow as it gets resized a every step of the loop. Preallocation and indexing would be faster:
%stuff that doesn't need to be calculated in the loop
t=bp/99:bp/99:bp;
y=A*(sin(2*pi*f*t2+pi))%+(sin(2*pi*f*t+pi));
t4=bp/99:bp/99:bp;
%loop preparation,
v = ss:ss:length(m);
mn = zeros(1, numel(v); %preallocation
%loop
for idx = 1:numel(v)
n = v(idx);
mm=y.*m((n-(ss-1)):n);% mm=y.*m((n-(ss-1)):n);
z=trapz(t4,mm); % intregation method
zz=round((2*z/bp));
if zz > 0
mn(idx) = 1;
else
mn(idx) = -1; %or 0 if you really must
end
end
plot(mn);

카테고리

Help CenterFile Exchange에서 PSK에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by