%%% T8 Lab for DAS
%%% 1. Tapped Delay
function [y, b, a] = tapped_delay_line(x, n, g, d)
% A tapped delay function
% Inputs:
% x: input signal
% n: number of taps (reflections)
% g: vector of gains of each tap
% d: vector of delay lengths of each tap
% Outputs:
% y: Output signal
% b: numerator coefficients of the transfer function
% a: denominator coefficients of the transfer function

% find maximum delay length of delay
max_delay = max(d);

% set dominator a = 1
a = 1;

%create nominator vector b
b = [1,zeros(1,max_delay)];

% use a for loop to assign the correct gain values to their corresponding
% delay length values + 1 for the numerator vector.
for i=1:n
    b(d(i)+1) = b(d(i)+1)+g(i);
end
    
% create an impulse response
impulse_response = impz(b,a);

for i=1:2
    y(:,i) = conv(x(:,i),impulse_response);
end


