Professional Documents
Culture Documents
X = wavread(strcat(pathname,filename));
% Compress wav
status=1;
for j=1:4
comp = compress_dct(X, window_size(j), ceil(n_coeffs_keep*window_size(j)),
coeff_n_bits,status);
% Save comp structure in a binary format with extra gzip compression
% so we can see how big it really is.
% % save -binary -z bach.mat comp
% Decompress and write back to wav for comparison.
Xdecomp = decompress_dct(comp);
% wavplay(Xdecomp, 44100);
[M,N]=size(X);
num_win=floor(length(X)/window_size(j));
temp=X(1:num_win*(floor(length(X)/num_win)));
MSE = sum(sum((temp-Xdecomp).^2))/(M*N);
PSNR = 10*log10(2*65535/MSE);
scatter(window_size(j),PSNR);
xlabel('N');
ylabel('SNR');
title('Keeping dominant 75% coefficients');
hold on
end
Compress_dct.m:
I = I(1:num_components, :);
elseif status==0
I=zeros(num_components,num_win);
for i=1:num_win
I(:,i)=linspace(1,num_components,num_components);
end
end
% build struct
result.coeffs = int16(zeros(num_components, num_win));
result.ind = int16(I);
result.window = window;
result.coeff_bits = coeff_bits;
for i = 1:floor(num_win)
% store each coefficient (in [-1,1]) as an integer mapped to range
% (-2^(coeff_bits-1), 2^(coeff_bits_1))
result.coeffs(:,i) = int16(Y(I(:,i), i)*2^(coeff_bits-1));
end
end
Decompress_dct.m
function X = decompress_dct(data)
num_win = size(data.coeffs, 2);
coeffs = double(data.coeffs)/(2^(data.coeff_bits-1)); % Rescale coeffs to [-
1,1]
% Construct full DCT windows from sparse.
Y = zeros(data.window, num_win);
for i = 1:num_win
Y(data.ind(:,i),i) = coeffs(:,i);
end
71.8
SNR
71.75
71.7
50 100 150 200 250 300 350 400 450 500 550
N
74.37
74.36
74.35
SNR
74.34
74.33
74.32
74.31
50 100 150 200 250 300 350 400 450 500 550
N
Keeping first 50% coefficients
82.9
82.85
82.8
SNR
82.75
82.7
82.65
50 100 150 200 250 300 350 400 450 500 550
N
99.8
99.6
99.4
SNR
99.2
99
98.8
98.6
98.4
50 100 150 200 250 300 350 400 450 500 550
N
Keeping dominant 10% coefficients
75
74.9
74.8
SNR
74.7
74.6
74.5
74.4
50 100 150 200 250 300 350 400 450 500 550
N
80.9
80.8
80.7
80.6
SNR
80.5
80.4
80.3
80.2
80.1
80
50 100 150 200 250 300 350 400 450 500 550
N
Keeping dominant 50% coefficients
91.8
91.6
91.4
91.2
SNR
91
90.8
90.6
90.4
90.2
50 100 150 200 250 300 350 400 450 500 550
N
111.5
111
110.5
110
SNR
109.5
109
108.5
108
107.5
107
50 100 150 200 250 300 350 400 450 500 550
N