Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.0 kB
2
Indexable
Never
function user_centric_ap_clustering()
    p = 100; % define data power
    % Parameters
    m = 5; % Number of APs
    k = 10; % Number of users
    QoS_threshold = 0.001;
    noise_variance = 1;
    % Step 1: Form Channel Gain Matrix
    C = rand(m,k); % Random channel gains
    max_channel_gain = max(C(:));
    C_normalized = C; % max_channel_gain; % Normalize channel gains
    
    % Initialize SINR matrix
    SINR = zeros(1, k);
    delta = zeros(m,k);
    B = zeros(k,k);
    
    % Iterate for different values of alpha
    for alpha = 0:0.05:1
        % Set delta matrix
        delta = (C_normalized > alpha); % Thresholding
        
        % Calculate SINRs and check QoS constraint
        for j = 1:k
            % Calculate cumulative SINR for each user
            interference = 0;
            for i = 1:k
                if i~=j
                    
                    for x = 1:m
                        if delta(x,i)>0
                           interference = interference + (C_normalized(x,j)'*C_normalized(x,i))^2*p;
                        end
                    end
                end
            end
           
           SINR(j) = sum(p*(abs(C_normalized(delta(:, j) > 0, j)).^4)) / (noise_variance + interference);
            
            
            % Check QoS constraint
            if SINR(j) < QoS_threshold
                disp(['QoS constraint not satisfied for user ', num2str(j)]);
            end
        end

         % Plot cumulative SINR vs. user number
         figure;
         plot(1:k, SINR, '-o');
         title(['SINR vs. User Number for alpha = ', num2str(alpha)]);
         xlabel('User Number');
         ylabel('Cumulative SINR');
         ylim([0, max(SINR)*1.1]); % Adjust ylim to fit the SINR range
        
        % Display B matrix
        B = delta' * delta > 0;
        disp(['For alpha = ', num2str(alpha)]);
        disp('B Matrix:');
        disp(B);
    end
    disp(C_normalized);

end
Leave a Comment