Programma matlab problema

di il
1 risposte

Programma matlab problema

Buongiorno,vorrei chiedervi una mano a risolvere il mio problema. Ho un codice matlab che si trova in rete sul sito di mathworks e che simula il comportamento di 3 utenti (ricevitori e trasmettitori) che devono regolare la loro potenza di trasmissione per ottenere un rapporto segnale rumore adeguato ai criteri di qualità del segnale.
Ora,il codice per tre utenti funziona benissimo,ed è il seguente.
clc, clear all, clf

K=3;%number of user(transmitter-receiver pairs)


%Next we randomly generate channel matrix H.
H=rand(K,K); %H contains channel all channel gains. Channels gains are assumed to be less then 1

% Next we specify required SIR levels at each receiver
Gamm=[0.1, 0.2, 0.3]; %target SIR at each receiver


P=[0.5 0.5 0.5]; % power available at each transmitter i.e Transmit Power

N=[0.01, 0.01, 0.01]; % Noise power at each receiver

SIR=[H(1)*P(1)/(H(3)*P(3)+H(2)*P(2)+N(1)),H(2)*P(2)/(H(3)*P(3)+H(1)*P(1)+N(2)),H(3)*P(3)/(H(2)*P(2)+H(1)*P(1)+N(3))];% initial SIR at each reciever




%algorithm starts here
iterations=1;
Err=1; %some initial error value 
while max(Err)>0.000001  % I choose maximum erro to be a divergence criteria
     
    P=(Gamm./SIR(iterations,:)).*P; % New power used by transmitters
    iterations=iterations+1;
    SIR(iterations,:)=[H(1)*P(1)/(H(3)*P(3)+H(2)*P(2)+N(1)),H(2)*P(2)/(H(3)*P(3)+H(1)*P(1)+N(2)),H(3)*P(3)/(H(2)*P(2)+H(1)*P(1)+N(3))]% new SIR
   
    Err=abs(Gamm- SIR(iterations,:)); %error
   
   
   
end
   
%ploting
plot(linspace(0,iterations,100),Gamm(1)*ones(1,100),'b-')
hold on
plot(linspace(0,iterations,100),Gamm(2)*ones(1,100),'g-')
plot(linspace(0,iterations,100),Gamm(3)*ones(1,100),'r-')

plot(1:iterations,SIR(:,1),'-.bo')
plot(1:iterations,SIR(:,2),'-.go')
plot(1:iterations,SIR(:,3),'-.ro')
xlabel('Iterations')
ylabel('SIR')
title('SIR vs number of Iterations')
     legend(' SIR of user 1',' SIR of user 2',' SIR of user 3')
Io sto cercando di modificarlo per più utenti ma sembra non andare bene...Non sono molto pratica di matlab..
Potreste guardare il codice e aiutarmi a capire cosa non va?
Questo è il mio codice :
clc, clear all  clf

K=4;%number of user(transmitter-receiver pairs)   

% We generate channel matrix H.
H =[1,0.1,0.2,0.3;0.2,1,0.1,0.1;0.2,0.1,1,0.1;0.1,0.1,0.1,1]; %H contains channel all channel gains. Channels gains are assumed to be less then 1

% Next we specify required SIR levels at each receiver
Gamm=[2.0, 2.5, 1.5,2.0]; %target SIR at each receiver


P=[1.0,1.0,1.0,1.0]; % power available at each transmitter i.e Transmit Power (mW)

N=[0.1, 0.1, 0.1,0.1]; % Noise power at each receiver (mW)

SIR= [H(1)*P(1)/(H(2)*P(2)+H(3)*P(3)+H(4)*P(4)+N(1)),H(2)*P(2)/(H(1)*P(1)+H(3)*P(3)+H(4)*P(4)+N(2)),H(3)*P(3)/(H(1)*P(1)+H(2)*P(2)+H(4)*P(4)+N(3)),H(4)*P(4)/(H(1)*P(1)+H(2)*P(2)+H(3)*P(3)+N(4))];

%algorithm starts here
iterations=1;
Err=1; %some initial error value 
while max(Err)>0.000001  % I choose maximum error to be a divergence criteria
     
    P=(Gamm./SIR(iterations,:)).*P; % New power used by transmitters
    iterations=iterations+1;

    SIR(iterations,:)=[H(1)*P(1)/(H(2)*P(2)+H(3)*P(3)+H(4)*P(4)+N(1)),H(2)*P(2)/(H(1)*P(1)+H(3)*P(3)+H(4)*P(4)+N(2)),H(3)*P(3)/(H(1)*P(1)+H(2)*P(2)+H(4)*P(4)+N(3)),H(4)*P(4)/(H(1)*P(1)+H(2)*P(2)+H(3)*P(3)+N(4))];
    Err=abs(Gamm- SIR(iterations,:)); %error
   
   
   
end
   
%ploting
plot(linspace(0,iterations,50),Gamm(1)*ones(1,50),'b')
hold on
plot(linspace(0,iterations,50),Gamm(2)*ones(1,50),'g')
plot(linspace(0,iterations,50),Gamm(3)*ones(1,50),'r')
plot(linspace(0,iterations,50),Gamm(4)*ones(1,50),'y')


plot(1:iterations,SIR(:,1),'-.')
plot(1:iterations,SIR(:,2),'-.g')
plot(1:iterations,SIR(:,3),'-.r')
plot(1:iterations,SIR(:,4),'-.y')
xlabel('Iterations')
ylabel('SIR')
title('SIR vs number of Iterations')
     legend(' SIR of user 1',' SIR of user 2',' SIR of user 3','SIR of user 4')
Il problema è che le curve di output dovrebbero convergere sulle rette parallele all'asse delle x,che sono i rapporti segnale rumore da raggiungere,tuttavia così non sembra,mentre nel programma a 3 utenti lo fa...
Grazie a chi risponderà!

1 Risposte

Devi accedere o registrarti per scrivere nel forum
1 risposte