From f9cdd4c503886e655025a3e8a88cf4d285949aba Mon Sep 17 00:00:00 2001 From: MekhiTheKing <95403331+MekhiTheKing@users.noreply.github.com> Date: Thu, 9 Dec 2021 21:13:56 -0800 Subject: [PATCH] Added Comments and Changed Formatting --- src/distortion_filter.m | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/distortion_filter.m diff --git a/src/distortion_filter.m b/src/distortion_filter.m new file mode 100644 index 0000000..869aab7 --- /dev/null +++ b/src/distortion_filter.m @@ -0,0 +1,30 @@ +% An audio is distorted based on the value of HIGH. Nothing of a certain +% threshold should be played above this constant, or they are simply clipped to this +% value. Inspired from Meghaj_Echo.m and epic_effect_schluep.m. +% Author: Jason Liang +% Mekhi Ellington: Added some comments and editted formatting + +function y = distortion_filter(x, HIGH) + len = length(X); %Storing length of X. + X = fft(x); %X is the Fourier Transform of x. + X = fftshift(X); %Shifts X. + Y = zeros(1, len); %Matrix of length containing zeros. + + for ind = 1:len + if (X(ind) > HIGH) + Y(ind) = HIGH; + + elseif (X(ind) < -HIGH) + Y(ind) = -HIGH; + + else + Y(ind) = X(ind); + + end + end + + Y = fftshift(Y); %Shifts Y. + y = ifft(Y); %Inverse Fourier Transform of Y. + y = real(y); %Stores only the real part of the complex y. + +end \ No newline at end of file