Created 3 new functions, see in description

Created functions bandreject_filter(), fade_in(), and fade_out(). Should be in the standards asked, but if not please contact me
This commit is contained in:
SeaSponge 2021-12-08 14:50:40 -08:00 committed by GitHub
parent c01ea88b2c
commit a7af33ba25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 123 additions and 0 deletions

62
bandreject_filter.m Normal file
View File

@ -0,0 +1,62 @@
function output_y = bandreject_filter(Input, Fs, Low, High)
% A filter that lets through most frequencies unaltered
% but attentuates the frequencies in the specified range to
% very low levels
% (basically exliminates them)
% By Yalu Ouyang
% Input: the input signal in the time domain
% Fs: the sampling frequency
% Low: the lower limit of the specified range
% High: the upper limit of the specified range
% Returns Output: the filtered signal in the time domain
len = length(Input);
F = Fs * (-len/2 : (len/2 - 1)) / len ;
% modified signal in the frequency domain
% using Fourier Transform
mod_freq = fftshift(fft(Input));
len_f = length(mod_freq);
% use this array to record the frequencies
% that should pass through
% 0 indicates reject
% 1 indicates pass
multiplier = zeros([1,len_f]);
for index = 1 : len_f
% within range of band reject
% so elminate these frequencies
if ((Low < abs(F(index))) && (abs(F(index)) < High))
multiplier(index) = 0;
% outside of specified range
% so shoudln't be altered
else
multiplier(index) = 1;
end
end
% filtered signal in the frequency domain
filtered_mod_freq = fftshift(mod_freq .* multiplier);
% convert signal back to the time domain
Output = real(ifft(filtered_mod_freq));
end
% This function is useful for eliminating
% unwanted signals that have frequencies close to the
% median frequency of the original signal
% (consider overall frequencies as one part,
% this elminates the middle portion)
% Fourier transform is applied in this function
% to make it easier to eliminate specified
% frequencies of the signal
% (easier to do so in the frequency domain)

29
fade_in.m Normal file
View File

@ -0,0 +1,29 @@
function output = fade_in(input, time)
% Creates a fade-in sound effect that lasts a given
% time parameter of the input sound signal
% By Yalu Ouyang
% input: a 1D array that represents the sound signal in the time domain
% time: how long the fade in effect should last
% Shouldn't be longer than the input signal (in which case the function
% treats it as the duration of the signal)
% Returns modified signal in the time domain (output).
len = length(input);
% if time parameter longer than signal, treat time as
% the duration of original signal
if time > len
time = len
end
% set multiplier as 1D array
% fade in effect: from no volume to full volume of signal
multiplier = (1 : time) / time;
% the resulting fade-in output
output = input .* multiplier;
end
% This is useful for making videos, specifically the intro part

32
fade_out.m Normal file
View File

@ -0,0 +1,32 @@
function output = fade_out(input, time)
% Creates a fade-out sound effect that lasts a given
% time parameter of the input sound signal
% By Yalu Ouyang
% input: a 1D array that represents the sound signal in the time domain
% time: how long the fade out effect should last
% Shouldn't be longer than the input signal
% (in which case the function treats it as the duration of the signal)
% Returns modified signal in the time domain (output).
len = length(input);
% if time parameter longer than signal, treat time as
% the duration of original signal
if time > len
time = len
end
% set multiplier as 1D array
multiplier = (1 : time) / time;
% fade out effect: from full volume of signal to no volume
multiplier = flip(multiplier)
% the resulting fade-in output
output = input .* multiplier;
end
% This is useful for creating videos, specifically the outro part