我試圖一段在Python代碼的出現誤導result.i只是想確認np.randn的功能是一樣的Matlab的randn plzz helpppMatlab的隨機VS np.randn
S=[ 3.+3.j 1.-3.j -3.+1.j 1.+3.j 1.-1.j]
SNR=arange(6,23,1)
BER=zeros(len(SNR))
Es=10
for ii in arange(0,len(SNR)):
variance=Es*(10**(-SNR[ii]/10))
std_dev=cmath.sqrt(variance/2)
noise=(np.random.randn(len(S))+cmath.sqrt(-1)*np.random.randn(len(S))) *std_dev
S_noisy=S+noise
print(noise)
MATLAB代碼
SNR=6:22;
display(SNR)
display(length(SNR))
BER=zeros(1,length(SNR));
display(BER)
display(length(BER))
Es=10;
for ii=1:length(SNR)
variance=Es*10^(-SNR(ii)/10);
std_dev=sqrt(variance/2);
noise=(randn(1,length(S))+sqrt(-1)*randn(1,length(S)))*std_dev;
S_noisy=S+noise;
end
display(noise)
結果應該是
[0.1150 + 0.1889i -0.0756 + 0.2055i 0.1862 + 0.0094i 0.1174 - 0.2288i
0.4456 - 0.0659i]
如果我添加在matlab中生成的確切噪聲序列,即使它沒有給出正確的答案 –