How to store the value of y in the loop being executed?
1 回表示 (過去 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
2 件のコメント
参考
カテゴリ
Help Center および File Exchange で BPSK についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!