LAB EXAM

Syed Ahsan Raza KAzmi
BEE6-D 32783

pathname] = uigetfile( .wav)'. X = wavread(strcat(pathname. ceil(n_coeffs_keep*window_size(j)). % wavplay(Xdecomp. coeff_n_bits = 10. hold on end Compress_dct. % % save -binary -z bach.*'. window_size(j). window. for j=1:4 comp = compress_dct(X.CODE: Main. 'Pick a file'. % Save comp structure in a binary format with extra gzip compression % so we can see how big it really is. ylabel('SNR'). coeff_n_bits. 44100). .wav'.75.. . 'MultiSelect'.% applies dct to each row .. % reshape so each window is a row Y = dct(temp).filename)).. coeff_bits..status) num_win = floor(length(X)/window). 'on'). PSNR = 10*log10(2*65535/MSE).PSNR).'Audio (*.. scatter(window_size(j). must be mono..m: function result = compress_dct(X. . % Load wav file. window. n_coeffs_keep = 0. [M. temp=X(1:num_win*(floor(length(X)/num_win))).. number of samples divisible by window size..m: window_size = [512 256 128 64]. {'*.. [filename. '*.status).*)'}. xlabel('N'). num_win=floor(length(X)/window_size(j)). title('Keeping dominant 75% coefficients').mp3'..N]=size(X). . % Compress wav status=1. num_components. 'All Files (*.mp3)'. '*. temp= reshape(temp. temp=X(1:num_win*(floor(length(X)/num_win))).^2))/(M*N).'wave-files (*.mat comp % Decompress and write back to wav for comparison. Xdecomp = decompress_dct(comp). num_win). MSE = sum(sum((temp-Xdecomp).

coeff_bits = coeff_bits.ind(:.coeff_bits-1)). 2^(coeff_bits_1)) result.1] % Construct full DCT windows from sparse.num_win). I] = sort(abs(Y). i)*2^(coeff_bits-1)).coeffs)/(2^(data.1]) as an integer mapped to range % (-2^(coeff_bits-1). 1).i). % Rescale coeffs to [- 1. 2). X = reshape(X. X = idct(Y).i).num_components. num_win*data. end % Inverse DCT each window. num_win)).coeffs = int16(zeros(num_components. for i=1:num_win I(:.window.i)=linspace(1. Y = zeros(data.m function X = decompress_dct(data) num_win = size(data.i) = int16(Y(I(:. 'descend').i) = coeffs(:. % Stitch windows into one long vector.window. result.i). I = I(1:num_components. end end Decompress_dct. elseif status==0 I=zeros(num_components.if status==1 % find top components and their indices [~.num_components). result. :).coeffs.ind = int16(I). for i = 1:floor(num_win) % store each coefficient (in [-1. num_win).window = window. result.coeffs(:. for i = 1:num_win Y(data. coeffs = double(data. end . end end % build struct result.

31 50 100 150 200 250 300 350 400 450 500 550 N .8 SNR 71.75 71.7 50 100 150 200 250 300 350 400 450 500 550 N Keeping first 25% coefficients 74.Graphs: Keeping first 10% coefficients 71.34 74.33 74.38 74.37 74.32 74.35 SNR 74.85 71.36 74.

6 99.65 50 100 150 200 250 300 350 400 450 500 550 N Keeping first 75% coefficients 100 99.85 82.8 99.9 82.7 82.4 50 100 150 200 250 300 350 400 450 500 550 N .6 98.8 SNR 82. Keeping first 50% coefficients 82.8 98.4 SNR 99.75 82.2 99 98.

5 80.6 74.4 50 100 150 200 250 300 350 400 450 500 550 N Keeping dominant 25% coefficients 81 80.4 80.9 74.7 74.7 80.8 80.6 SNR 80.2 80.9 80.8 SNR 74. Keeping dominant 10% coefficients 75 74.1 80 50 100 150 200 250 300 350 400 450 500 550 N .3 80.5 74.

5 107 50 100 150 200 250 300 350 400 450 500 550 N .6 91.5 109 108.8 91.5 111 110.6 90. Keeping dominant 50% coefficients 91.8 90.2 50 100 150 200 250 300 350 400 450 500 550 N Keeping dominant 75% coefficients 112 111.4 91.2 SNR 91 90.5 108 107.5 110 SNR 109.4 90.