function [doppler_out] = Doppler_effect_total(signal_in, fs, vs);

%Doppler Function used to take an input file and apply a pitch shift for
%approach and recede and an intensity change as the source approaches the
%observer


% Pitch Shift
%converts an input signal to frequency domain with a fourier transform, applies the doppler equation 
%to each data point, then converts back to amplitude domain.
      

%splitting audio into two halves, one for approaching source, one for
%receding 

 signal_length = (length(signal_in));
 half = ceil(signal_length/2);
 signal_in_1 = signal_in(1:half);
 signal_in_2 = signal_in(half + 1 : end);

%signal_out_1 = zeros(length(signal_in_1),1); 
%signal_out_2 = zeros(length(signal_in_2),1); 
%--------------------------------------------------------------------------

% Output Data

%Approaching

Width = (vs/5000); 

Modfreq = 4.; % for sub-audio sine-wave modulation sigal

% [y MOD] = my_modulator(Input,FS,Modfreq,Width);
LEN=length(signal_in_1);

Mod_sig = make_sine_modulator(fs,Modfreq,LEN); % sub-audio modulation signal, sampled at the audio sampling rate
z_allterp_1=delay_mod(signal_in_1,fs,Mod_sig,Width);  % uses the modulation signal made by routine 'make_modulator'


%Receding

Width = (vs/10000); 

Modfreq = 4.; % for sub-audio sine-wave modulation sigal

% [y MOD] = my_modulator(Input,FS,Modfreq,Width);
LEN=length(signal_in_2);

Mod_sig = make_sine_modulator(fs,Modfreq,LEN); % sub-audio modulation signal, sampled at the audio sampling rate
z_allterp_2=delay_mod(signal_in_2,fs,Mod_sig,Width);  % uses the modulation signal made by routine 'make_modulator'





signal_out_pitch= cat(1, z_allterp_1, z_allterp_2); %combines the two split matrices back together


%Doppler Intensity 


%Used to create a triangular shape gain matrix the same size as
%the input signal which can be multiplied by the input signal to make
%intensity increase until half way through the sample, then decrease.

gainer_matrix_length = (size(signal_out_pitch, 1)/2); %define size of half the input signal

gainer_matrix_1= 0:(3/gainer_matrix_length):3; %Create matrix from 0 to 3 with same shape as input signal


gainer_matrix_2= fliplr(gainer_matrix_1); %reverse first curve


gainer_matrix_1= gainer_matrix_1(:);  %flip matrices to column vectors 
gainer_matrix_2= gainer_matrix_2(:);

gain_matrix_total= [gainer_matrix_1;gainer_matrix_2]; %Combine gain matrices


if length(signal_out_pitch) ~= length(gain_matrix_total)
    signal_out_pitch=  [signal_out_pitch; 0;]; % make matrices same size if no equal
    
end

if length(signal_out_pitch) ~= length(gain_matrix_total)
    signal_out_pitch=  [signal_out_pitch; 0;]; % make matrices same size if still no equal
    
end


doppler_out = signal_out_pitch(:,1) .* gain_matrix_total(:,1); %multiply gain matrix by input signal

end



