This commit is contained in:
Darell Chua Yun Da 2021-12-13 09:09:16 +08:00
commit c821b89523
2 changed files with 22 additions and 29 deletions

View File

@ -1,30 +1,23 @@
% An audio is distorted based on the value of HIGH. Nothing of a certain function y = distortion_filter(input, fs, LOW, MED, HIGH)
% threshold should be played above this constant, or they are simply clipped to this %Author: Jason Liang
% value. Inspired from Meghaj_Echo.m and epic_effect_schluep.m. %input: 1D array representing the sound signal in the time domain
% Author: Jason Liang %fs: sampling frequency
% Mekhi Ellington: Added some comments and editted formatting %low: lower bound of frequencies
%med: median of all frequencies
%high: upper bound of frequencies
%y: output signal
%This function distorts a signal based on the constant LOW; all
%frequencies in between the specified range are clipped by the constant
%LOW.
function y = distortion_filter(x, HIGH) len = length(input);
len = length(X); %Storing length of X. f = fs*(-len/2:len/2-1)/len;
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);
outputW = fftshift(fft(input));
for i = 1:length(outputW)
if ((LOW < abs(F(n))) && HIGH > abs(F(n)))
outputW(i) = outputW(i) / LOW;
end end
end end
y = real(ifft(fftshift(outputW)));
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 end