function [outsig] = Tremolo(x,fs,D,R)

% x = input signal
% fs = sampling frequency
% R = Tremolo rate (cycles per second)
% D = Tremolo depth (as a percentage, 0 < D le 1)

% The tremolo signal needs to be the same length as the input signal
% x_Length is the length of the input signal x
x_Length = length(x);

%Create modulation signal (TremSig) to apply to insig using F and D
    for x = 1:x_Length;
        TremSig(x) = (1-D) + D .* ((1 + cos((2.*pi.* R .* x) ./ fs)) ./ 2);
    end

% Convolve TremSig with input signal to create TremOut
TremOut = x .* TremSig;
outsig(:,1) = TremOut(1,:);

end