Last active
October 30, 2017 02:07
-
-
Save sparksbat/c5c109891ef213fc596b20d3325cd715 to your computer and use it in GitHub Desktop.
ECE 306L Lab 4 MATLAB Files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clear variables | |
y = imread('moon.tif'); % Target Image File | |
z = double(y); | |
maximum = max(z(:)); | |
minimum = min(z(:)); | |
b = 7; % Quantiz Bits | |
N = 2^b; | |
Delta = (maximum - minimum)/(N-1); | |
ztemp = z - minimum; | |
ztemp = round(ztemp/Delta); | |
ztemp = ztemp.*Delta + minimum; | |
fig = image(ztemp); | |
colormap(gray(256)); | |
axis('image'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clear variables | |
audio = audioread('music.au'); | |
maximum = max(audio(:)); | |
minimum = min(audio(:)); | |
b = 7; % Some bits per px. Modify this. | |
N = 2^b; | |
Delta = (maximum - minimum)/(N-1); | |
codebook_a = minimum-Delta:Delta:maximum; | |
codebook_b = minimum-(Delta/2):Delta:maximum+(Delta/2); | |
partition = minimum:Delta:maximum; | |
[index_a, quantz_a] = quantiz(audio, partition, codebook_a); | |
[index_b, quantz_b] = quantiz(audio, partition, codebook_b); | |
q_a_e = transpose(quantz_a) - audio; | |
q_b_e = transpose(quantz_b) - audio; | |
figure('name',strcat(int2str(b), ' bits'),'pos',[10 10 500 900]) | |
subplot(4,2,1) | |
plot(quantz_a) | |
title('Quantized Audio A') | |
subplot(4,2,2) | |
plot(quantz_b) | |
title('Quantized Audio B') | |
subplot(4,2,3) | |
hist(q_a_e, 20); | |
title('Quantize Error A') | |
subplot(4,2,4) | |
hist(q_b_e, 20); | |
title('Quantize Error B') | |
[c_a,lags_a] = xcorr(q_a_e,audio,200,'unbiased'); | |
[c_b,lags_b] = xcorr(q_b_e,audio,200,'unbiased'); | |
[ca_a,lagsa_a] = xcorr(q_a_e,200,'unbiased'); | |
[ca_b,lagsa_b] = xcorr(q_b_e,200,'unbiased'); | |
subplot(4,2,5) | |
plot(lagsa_a,ca_a); | |
title('Auto-Correlation A') | |
subplot(4,2,6) | |
plot(lagsa_b,ca_b); | |
title('Auto-Correlation B') | |
subplot(4,2,7) | |
plot(lags_a,c_a); | |
title('Cross-Correlation A') | |
subplot(4,2,8) | |
plot(lags_b,c_b); | |
title('Cross-Correlation B') | |
[sz, ~] = size(q_a_e); | |
Pa = 1/sz * sum(q_a_e.^2); | |
Pb = 1/sz * sum(q_b_e.^2); | |
Po = 1/sz * sum(audio.^2); | |
PSNRa = Po/Pa; | |
PSNRb = Po/Pb; | |
Dista = 1/PSNRa; | |
Distb = 1/PSNRb; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clear variables | |
audio = audioread('music.au'); | |
maximum = max(audio(:)); | |
minimum = min(audio(:)); | |
Dista = zeros(1,7); | |
Distb = zeros(1,7); | |
PSNRa = zeros(1,7); | |
PSNRb = zeros(1,7); | |
r = 1:1:7; | |
for b = 1:1:7 | |
N = 2^b; | |
Delta = (maximum - minimum)/(N-1); | |
codebook_a = minimum-Delta:Delta:maximum; | |
codebook_b = minimum-(Delta/2):Delta:maximum+(Delta/2); | |
partition = minimum:Delta:maximum; | |
[index_a, quantz_a] = quantiz(audio, partition, codebook_a); | |
[index_b, quantz_b] = quantiz(audio, partition, codebook_b); | |
q_a_e = transpose(quantz_a) - audio; | |
q_b_e = transpose(quantz_b) - audio; | |
[sz, ~] = size(q_a_e); | |
Pa = 1/sz * sum(q_a_e.^2); | |
Pb = 1/sz * sum(q_b_e.^2); | |
Po = 1/sz * sum(audio.^2); | |
PSNRa(b) = Po/Pa; | |
PSNRb(b) = Po/Pb; | |
Dista(b) = 1/PSNRa(b); | |
Distb(b) = 1/PSNRb(b); | |
end | |
subplot(2,2,1) | |
plot(r, PSNRa); | |
title('PSNR A'); | |
xlabel('Bits'); | |
ylabel('PSNR'); | |
subplot(2,2,2) | |
plot(r, PSNRb); | |
title('PSNR B') | |
xlabel('Bits'); | |
ylabel('PSNR'); | |
subplot(2,2,3) | |
plot(r, Dista); | |
title('Distortion A') | |
xlabel('Bits'); | |
ylabel('Distortion'); | |
subplot(2,2,4) | |
plot(r, Distb); | |
title('Distortion B') | |
xlabel('Bits'); | |
ylabel('Distortion'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment