function [y,n_firsty]=my_conv_skel(x,k_firstx,h,k_firsth);
%
% FUNCTION [y,n_firsty]=my_conv_skel(x,k_firstx,h,k_firsth);
%
% A skeleton of a function to compute convolution using the graphical method.
%
% INPUTS:
%
% x:        a vector containing the input sequence
% k_firstx: time index corresponding to first element of x
% h:        a vector containing the impulse response 
% k_firsth: time index corresponding to first element of h
%
% OUTPUTS:
%
% y:        a vector containing the output sequence 
% n_firsty: the time index corresponding to the first element of y.      
%
% The vector y contains the output sequence only for time indices
% n from k_firstx+k_firsth to k_firstx+length(x)-1 + k_firsth+length(h)-1.
% If the input and the impulse response are zero outside the elements
% given above, then the output is zero outside the range of time indices
% covered by the vector y.
%   


disp('This is only a skeleton program.  Please fill in the missing pieces');
disp('Press CTRL-C to abort, or Return to continue')
pause;
         %You can remove the above three lines when your program works.



Ly= ???
                % Detemine the length of the output y
                % Refer to slides from lectures
                % Hint: the "length" fuction may help here  

n_firsty = ???
                %Determine the time index of the first element of output
                %Refer to slides from lectures

x_padded=[x,zeros(1,Ly-length(x))];
                % Pad x with zeros so that it is defined for all k
                % that we will need; i.e., k_firstx <= k <= k_firstx +Ly-1

h_reversed=fliplr(h); %This function flips around h.  
                      %Type help fliplr for more information.

for count_ns=1:Ly,

   n=n_firsty+count_ns-1;
            % This is the time index of the output that we are computing. 

   no_elements_h=min(length(h),n -k_firsth-k_firstx+1);
            %This is the number of non-zero elements of h[n-k] that
            %overlap with x_padded

   no_zeros_padded_left=max(0,n- k_firsth-length(h)-k_firstx+1);
   no_zeros_padded_right=Ly-no_elements_h-no_zeros_padded_left;
            %These two commands determine the number of zeros to
            %be padded to the vector which represents h[n-k]

h_reversed_shifted = [zeros(1,no_zeros_padded_left),h_reversed(length(h)-no_elements_h+1:length(h)),zeros(1,no_zeros_padded_right)];  
            % This vector contains h[n-k] for the current value of n
            % for the same range of values of k that are in x_padded; 
            % i.e., k_firstx : k_firstx + Ly - 1,

    w= ??????
            %This line should form w_n[k] for the current value of n
            %for the range of values of k that are in x_padded;
            %i.e., k_firstx : k_firstx + Ly - 1.

 y(count_ns)=  ????? 
    % Find y for the current value of n, from w_n[k] at the current value of n.

end; % count_ns

