need help for iteration

edited August 2010 in Science & Tech
I have this certain iteration to simulate multiuser detection.And the thing is,i cannot get what i'm supposed to get.

function testme

rand('state',11);
randn('state',11);

L = 5000;  % Number of bits
N = 16;    % Number of chips per bit
U = 2;     % Number of users

S = codematrix(N,U);
b = sign(rand(U,L)-0.5);

snr   = 0:20;
sigma = sqrt(1./(10.^(snr/10)));

T = inv(transpose(S)*S)*transpose(S);

mu = 0.1;

for k1 = 1:length(sigma)
    y = S*b;
    n = impulsenoise(sigma(k1),[N L]);
    r = y+n;
    r = r(:);
    
    for k2 = 1:L
        r0 = r((k2-1)*N+(1:N));
        b0 = T*r0;
        b02 = b0;
        x = r0-S*b0;
        [x,e] = minimax(x,sigma(k1)*sigma(k1));
        b01 = b0+mu*T*x;
        
                
        while b01 - b02 > 0.000001
            b02 = b0;
            x         = r0-S*b0;           
            [x,e] = minimax(x,sigma(k1)*sigma(k1));
            b0      = b0+mu*T*x;
            b01 = b0           ;
        end
               
        %% figure, plot(e), pause
        
        %% b1(:,k2) = T*r0;
        b1(:,k2) = b0;
    end
    
    ber(k1) = mean(abs(sign(b1(1,:))-b(1,:)))/2;
end

figure, semilogy(snr,ber,'r')
xlim([snr(1) snr(end)]);
xlabel('SNR (dB)'), ylabel('BER')

% FUNCTIONS

function S = codematrix(N,U)

H = hadamard(N);
S = 1/sqrt(N)*H(:,1:U);

function n = impulsenoise(sigma,dim)

e  = 0.01;
k  = 100;
nu = sigma/sqrt((1-e)+e*k);

u = rand(1,dim(2)) < e;
v = [nu nu*sqrt(k)];
n = bsxfun(@times,v(u+1),randn(dim));

function [x,e] = minimax(x0,sigma2)

gamma = 1.5/sqrt(sigma2);

u = abs(x0) < gamma*sigma2;
x = u.*(x0/sigma2)+(1-u).*(gamma*sign(x0));
e = u.*(x0.*x0/(2*sigma2))+(1-u).*(gamma*abs(x0)-gamma*gamma*sigma2/2);
e = sum(e);


I'm supposed to get a smooth line,but what i have is jagged line.So i'm wondering what is wrong with this codes?

Comments

  • shwaipshwaip bluffin' with my muffin Icrontian
    edited August 2010
    sample your snr a bit finer.

    use snr = 0:0.1:20; instead of snr = 0:20;

    keep in mind that it'll take much longer to run.
Sign In or Register to comment.