Contents
Question 1 part a
fs = 44100;
h = readhrtf(0,15,'H');
h = h';
M = length(h);
noise = randn(1,4*fs);
input = [noise' noise'];
N = 5*128;
iterations = ceil(length(input)/N);
azimuth = linspace(0,360/5,iterations/2);
azimuth = round(azimuth);
azimuth = azimuth*5;
azimuth = [azimuth azimuth];
y = zeros(length(input),2);
for r=0:(iterations-2)
if (azimuth(r+1) > 180)
h = readhrtf(0,(360 - azimuth(r+1)),'H')';
y((r*N+1):(r*N+1 + N+M-2),1) = y((r*N+1):(r*N+1 + N+M-2),1)+ conv(input((r*N+1):(r*N+N),1),h(:,2));
y((r*N+1):(r*N+1 +N+M-2),2) = y((r*N+1):(r*N+1 +N+M-2),2) + conv(input((r*N+1):(r*N+N),2),h(:,1));
else
h = readhrtf(0,azimuth(r+1),'H')';
y((r*N+1):(r*N+1 + N+M-2),1) = y((r*N+1):(r*N+1 + N+M-2),1)+ conv(input((r*N+1):(r*N+N),1),h(:,1));
y((r*N+1):(r*N+1 +N+M-2),2) = y((r*N+1):(r*N+1 +N+M-2),2) + conv(input((r*N+1):(r*N+N),2),h(:,2));
end
end
y = 0.97*y/max(max(abs(y)));
soundsc(y,fs)
wavwrite(y,fs,'Prob1partA');
Question 1 Part b
fs = 44100;
h = readhrtf(0,15,'H');
h = h';
M = length(h);
noise = randn(1,2*fs);
input = [noise' noise'];
N = 5*128;
iterations = ceil(length(input)/N);
azimuth = linspace(0,360/5,iterations/2);
azimuth = round(azimuth);
azimuth = azimuth*5;
azimuth = [azimuth azimuth];
y = zeros(length(input),2);
for r=0:(iterations-2)
if (azimuth(r+1) <= 180)
h = readhrtf(0,azimuth(r+1),'H')';
y((r*N+1):(r*N+1 + N+M-2),1) = y((r*N+1):(r*N+1 + N+M-2),1)+ conv(input((r*N+1):(r*N+N),1),h(:,2));
y((r*N+1):(r*N+1 +N+M-2),2) = y((r*N+1):(r*N+1 +N+M-2),2) + conv(input((r*N+1):(r*N+N),2),h(:,1));
else
h = readhrtf(0,360-azimuth(r+1),'H')';
y((r*N+1):(r*N+1 + N+M-2),1) = y((r*N+1):(r*N+1 + N+M-2),1)+ conv(input((r*N+1):(r*N+N),1),h(:,1));
y((r*N+1):(r*N+1 +N+M-2),2) = y((r*N+1):(r*N+1 +N+M-2),2) + conv(input((r*N+1):(r*N+N),2),h(:,2));
end
end
y = 0.97*y/max(max(abs(y)));
soundsc(y,fs)
wavwrite(y,fs,'Prob1partB');
Question 1 part c
fs = 44100;
h = readhrtf(0,15,'H');
h = h';
M = length(h);
noise = randn(1,4*fs);
input = [noise' noise'];
N = 5*128;
iterations = ceil(length(input)/N);
azimuth = linspace(0,360/5,iterations/2);
azimuth = round(azimuth);
azimuth = azimuth*5;
azimuth = [azimuth azimuth];
azimuth2 = linspace(0,360/5,iterations/4);
azimuth2 = round(azimuth2);
azimuth2 = azimuth2*5;
azimuth2 = [azimuth2 azimuth2 azimuth2 azimuth2];
y = zeros(length(input),2);
for r=0:(iterations-2)
if (azimuth(r+1) > 180)
h = readhrtf(0,(360 - azimuth(r+1)),'H')';
y((r*N+1):(r*N+1 + N+M-2),1) = y((r*N+1):(r*N+1 + N+M-2),1)+ conv(input((r*N+1):(r*N+N),1),h(:,2));
y((r*N+1):(r*N+1 +N+M-2),2) = y((r*N+1):(r*N+1 +N+M-2),2) + conv(input((r*N+1):(r*N+N),2),h(:,1));
else
h = readhrtf(0,azimuth(r+1),'H')';
y((r*N+1):(r*N+1 + N+M-2),1) = y((r*N+1):(r*N+1 + N+M-2),1)+ conv(input((r*N+1):(r*N+N),1),h(:,1));
y((r*N+1):(r*N+1 +N+M-2),2) = y((r*N+1):(r*N+1 +N+M-2),2) + conv(input((r*N+1):(r*N+N),2),h(:,2));
end
end
y2 = zeros(length(input),2);
for r=0:(iterations-2)
if (azimuth2(r+1) <= 180)
h = readhrtf(0,azimuth2(r+1),'H')';
y2((r*N+1):(r*N+1 + N+M-2),1) = y2((r*N+1):(r*N+1 + N+M-2),1)+ conv(input((r*N+1):(r*N+N),1),h(:,2));
y2((r*N+1):(r*N+1 +N+M-2),2) = y2((r*N+1):(r*N+1 +N+M-2),2) + conv(input((r*N+1):(r*N+N),2),h(:,1));
else
h = readhrtf(0,360-azimuth2(r+1),'H')';
y2((r*N+1):(r*N+1 + N+M-2),1) = y2((r*N+1):(r*N+1 + N+M-2),1)+ conv(input((r*N+1):(r*N+N),1),h(:,1));
y2((r*N+1):(r*N+1 +N+M-2),2) = y2((r*N+1):(r*N+1 +N+M-2),2) + conv(input((r*N+1):(r*N+N),2),h(:,2));
end
end
y_total = (y+y2)/2;
y_total = 0.97*y_total/max(max(abs(y_total)));
soundsc(y_total,fs)
wavwrite(y_total,fs,'Prob1partC');