Spero di aver fatto quello che mi hai detto...

Di seguito il codice:


#clear all
close all

nc = 100; % numero di realizzazioni di canale
ns = 100; % numero di simboli che trasmetto (Scegliere pari)

snr_max = 30;
delta_snr = 1;
snr_db = [0:delta_snr:snr_max];
snr = 10 .^ (snr_db / 10);
dim_asc = size(snr);

a = [1+sqrt(-1), -1+sqrt(-1), -1-sqrt(-1), 1-sqrt(-1)] / sqrt(2);
x = zeros(2,1);

nbt = 2 * ns * nc;

y = zeros(dim_asc);
y_zf = zeros(dim_asc);
ber_zf = zeros(dim_asc);

for i=1:1:nc
H = (randn(2,2) + (sqrt(-1) * randn (2,2))) / sqrt(2);
Cherm = pinv(H);

for j=1:1:dim_asc

nezf = 0;

for k=1:1:ns/2

x = [a(ceil(rand*4)); a(ceil(rand*4))];
n = (randn(2,1) + sqrt(-1) * randn(2,1)) / sqrt(2);

y = sqrt(snr(j) / 2) * H * x + n;

y_zf = Cherm * y;

if real(y_zf(1)) > 0 && imag(y_zf(1)) > 0
szf(1) = a(1);
else if real(y_zf(1)) < 0 && imag(y_zf(1)) > 0
szf(1) = a(2);
else if real(y_zf(1)) < 0 && imag(y_zf(1)) < 0
szf(1) = a(3);
else
szf(1) = a(4);
end

if real(y_zf(2)) > 0 && imag(y_zf(2)) > 0
szf(2) = a(1);
else if real(y_zf(2)) < 0 && imag(y_zf(2)) > 0
szf(2) = a(2);
else if real(y_zf(2)) < 0 && imag(y_zf(2)) < 0
szf(2) = a(3);
else
szf(2) = a(4);
end

if szf(1) ~= x(1)
if real(szf(1)) ~= real(x(1)) && imag(szf(1)) ~= imag(x(1))
nezf = nezf + 2;
else
nezf = nezf +1;
end
end

if szf(2) ~= x(2)
if real(szf(2)) ~= real(x(2)) && imag(szf(2)) ~= imag(x(2))
nezf = nezf + 2;
else
nezf = nezf +1;
end
end

end % ns (simboli)
end % dim_asc (snr)
ber_zf(j) = ber_zf(j) + nezf;
i
end % nc (canali)

ber_zf = ber_zf / nbt;

end % fa più cicli anche se io non gliel'ho detto. Mah.....
end
end
end

plot(snr_db, ber_zf, 'b'),
title('Prestazioni'),
xlabel('snr [dB]'),
ylabel('BER'),
legend('ZF'),
grid on;



Non funziona...cosa sto sbagliando?