-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunfilePCMA.m
More file actions
42 lines (37 loc) · 1.09 KB
/
Copy pathrunfilePCMA.m
File metadata and controls
42 lines (37 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
%Setup File
clc
clear all;
close all;
% source A
sourceA = randn(10000,1);
for n = 2:4
[xq, centers, D] = lloydMaxQuantizer(sourceA, n, -1, 1);
%convert digitized output
digitalSourceA = centers(xq);
digitalSourceA = digitalSourceA';
%Calculate SQNR
SQNR = (mean(sourceA.^2))/D(end);
%Calculate MSE
MSE = immse(digitalSourceA, sourceA);
fprintf('SQNR of %d-bit Lloyd-Max quantization is %f dBs\n', n, SQNR);
fprintf('MSE of %d-bit Lloyd-Max quantization is %f\n', n, MSE);
end
%plot if you want
%plot(sourceA, 'DisplayName', 'sourceA');
%hold on;
%plot(digitalSourceA, 'DisplayName', 'new_array');
%hold off;
for n = 2:4
[idx, C, sumd] = kmeans(sourceA, n);
%convert digitized output
C = C';
digitalSourceA = C(idx);
digitalSourceA = digitalSourceA';
%Calculate SQNR
Dist = min(sumd)/length(sourceA);
SQNR = (mean(sourceA.^2))/Dist;
%Calculate MSE
MSE = immse(digitalSourceA, sourceA);
fprintf('SQNR of %d-bit Kmeans quantization is %f dBs\n', n, SQNR);
fprintf('MSE of %d-bit kmeans quantization is %f\n', n, MSE);
end