How to store the value of y in the loop being executed?

조회 수: 3 (최근 30일)
adriane duarte
adriane duarte 2020년 9월 3일
댓글: Tamir Suliman 2020년 9월 12일
I'm making a code and I don't know how to get the values that are being made inside the loop.
How do I see what the y results are?
Can anybody help me ?
% BPSK
M = 2;
% number of bits or symbols
N = 10^4;
% Generates random bits
Bits_ale = randi([0 M-1],N,1)>0.5;
% BPSK modulation 0 -> -1; 1 -> 1
s = 2 * Bits_ale-1;
% Generates random watermark bits
Bit_wat = randi([0 M-1],N,1)>0.5;
for k=1:N
if Bit_wat ==1
y = s * exp(1i * pi/4);
else if Bit_wat ==0
y = s * exp(1i *(- pi/4));
end
end
end

답변 (2개)

KSSV
KSSV 2020년 9월 3일
This is how you save y but you need to check your logic.
% BPSK
M = 2;
% number of bits or symbols
N = 10^4;
% Generates random bits
Bits_ale = randi([0 M-1],N,1)>0.5;
% BPSK modulation 0 -> -1; 1 -> 1
s = 2 * Bits_ale-1;
% Generates random watermark bits
Bit_wat = randi([0 M-1],N,1)>0.5;
y = zeros(1,N) ;
for k=1:N
if Bit_wat ==1
y(k) = s * exp(1i * pi/4);
elseif Bit_wat ==0
y(k) = s * exp(1i *(- pi/4));
end
end
  댓글 수: 2
adriane duarte
adriane duarte 2020년 9월 3일
Thank you KSSV.
I did it this way but the u only stores zeros.
It does not store the values of the loop.
Thank you very much for your attention.
then can I take another question?
KSSV
KSSV 2020년 9월 3일
편집: KSSV 2020년 9월 3일
It is because, if-else condition is never executed and the intialized y is as it is. Thats why I said you need to think of your code. You should follow like below:
% BPSK
M = 2;
% number of bits or symbols
N = 10^4;
% Generates random bits
Bits_ale = randi([0 M-1],N,1)>0.5;
% BPSK modulation 0 -> -1; 1 -> 1
s = 2 * Bits_ale-1;
% Generates random watermark bits
Bit_wat = randi([0 M-1],N,1)>0.5;
y = zeros(N,1) ;
y(Bit_wat==1) = s(Bit_wat==1) * exp(1i * pi/4);
y(Bit_wat==0) = s(Bit_wat==0) * exp(1i * -pi/4);

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


Tamir Suliman
Tamir Suliman 2020년 9월 3일
i think yo have so many end after the if statement I modified the number of bits per just to speed it up
clc
% BPSK
M = 2;
% number of bits or symbols
% N = 10^4;
N = 10^1;
% Generates random bits
Bits_ale = randi([0 M-1],N,1)>0.5;
% BPSK modulation 0 -> -1; 1 -> 1
s = 2 * Bits_ale-1;
% Generates random watermark bits
Bit_wat = randi([0 M-1],N,1)>0.5;
for k=1:N
if (Bit_wat ==1)
y = s * exp(1i * pi/4);
else (Bit_wat ==0)
y = s * exp(1i *(- pi/4));
end
end
y
  댓글 수: 2
adriane duarte
adriane duarte 2020년 9월 3일
Thank you Tamir Suliman !!!
the "y" stored the loop values.
can i take another doubt?
Tamir Suliman
Tamir Suliman 2020년 9월 12일
please accept the answer

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by