How to store the value of y in the loop being executed?
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(2 个)
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 个评论
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
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 BPSK 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!