From 50fb3f18d899cbb3f09716a3a9d9f9295db9fc5a Mon Sep 17 00:00:00 2001 From: Jason Liang <74435747+jaysunl@users.noreply.github.com> Date: Thu, 9 Dec 2021 01:10:08 -0800 Subject: [PATCH] Create distortion_filter.m --- src/distortion_filter.m | 26 ++++++++++++++++++++++++++ 1 file changed, 26 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..e60f7cd --- /dev/null +++ b/src/distortion_filter.m @@ -0,0 +1,26 @@ +% 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 + +function y = distortion_filter(x, HIGH) + len = length(X); + X = fft(x); + X = fftshift(X); + Y = zeros(1, len); + + 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); + y = ifft(Y); + y = real(y); + +end