clc;
clear;

%% ================= STEP 1: INITIALIZATION =================
A = 1;                      % Maximum amplitude
L_values = 2:2:50;          % Quantization levels
SQNR_dB = zeros(size(L_values));

disp('Step 1: Parameters Initialized');

%% ================= STEP 2: SQNR CALCULATION =================
fprintf('\nL\tSQNR(dB)\n');
fprintf('----------------------\n');

for i = 1:length(L_values)
    
    L = L_values(i);
    delta = (2*A)/L;        % Step size
    
    % Signal power (Uniform)
    Ps = (A^2)/3;
    
    % Quantization noise power
    Pq = (delta^2)/12;
    
    % SQNR calculation
    SQNR_dB(i) = 10*log10(Ps/Pq);
    
    % Display output
    fprintf('%d\t%.2f\n', L, SQNR_dB(i));
end

disp('Step 2: SQNR Computation Completed');

%% ================= STEP 3: PLOT GRAPH =================
figure;
plot(L_values, SQNR_dB, 'b-o', 'LineWidth', 2);
grid on;

xlabel('Quantization Levels (L)');
ylabel('SQNR (dB)');
title('SQNR vs Quantization Levels (Uniform Input)');

disp('Step 3: Graph Plotted');

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: