Untitled
% Signal to Quantization Ratio (SQNR) vs. Quantization Levels % Define the signal Fs = 1000; % Sampling frequency t = 0:1/Fs:1; % Time vector f = 5; % Frequency of the signal x = sin(2*pi*f*t); % Signal (sinusoid) % Quantization Parameters bits = 4:12; % Number of quantization bits levels = 2.^bits; % Quantization levels % Initialize arrays to store SQNR values SQNR = zeros(size(levels)); % Compute SQNR for each quantization level for i = 1:length(levels) % Quantize the signal quantized_signal = round(x * (levels(i) - 1)) / (levels(i) - 1); % Compute quantization error quantization_error = x - quantized_signal; % Compute Signal Power and Quantization Noise Power signal_power = mean(x.^2); quantization_noise_power = mean(quantization_error.^2); % Compute SQNR SQNR(i) = 10*log10(signal_power / quantization_noise_power); end % Plot SQNR vs. Quantization Levels figure; plot(bits, SQNR, '-o'); xlabel('Quantization Bits'); ylabel('SQNR (dB)'); title('SQNR vs. Quantization Levels'); grid on;
Leave a Comment