From a7af33ba252dd040330525edf2174d8940293f97 Mon Sep 17 00:00:00 2001 From: SeaSponge <61109988+Squidwarder@users.noreply.github.com> Date: Wed, 8 Dec 2021 14:50:40 -0800 Subject: [PATCH 1/4] 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 --- bandreject_filter.m | 62 +++++++++++++++++++++++++++++++++++++++++++++ fade_in.m | 29 +++++++++++++++++++++ fade_out.m | 32 +++++++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 bandreject_filter.m create mode 100644 fade_in.m create mode 100644 fade_out.m diff --git a/bandreject_filter.m b/bandreject_filter.m new file mode 100644 index 0000000..c5155f7 --- /dev/null +++ b/bandreject_filter.m @@ -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) \ No newline at end of file diff --git a/fade_in.m b/fade_in.m new file mode 100644 index 0000000..a09798c --- /dev/null +++ b/fade_in.m @@ -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 \ No newline at end of file diff --git a/fade_out.m b/fade_out.m new file mode 100644 index 0000000..4f21a1b --- /dev/null +++ b/fade_out.m @@ -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 \ No newline at end of file From 45acae9f753a015a9a8cfc4ddb77d64a1f7fd8dd Mon Sep 17 00:00:00 2001 From: SeaSponge <61109988+Squidwarder@users.noreply.github.com> Date: Wed, 8 Dec 2021 14:53:19 -0800 Subject: [PATCH 2/4] Moved fade_out() to be in src folder --- fade_out.m => src/fade_out.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename fade_out.m => src/fade_out.m (99%) diff --git a/fade_out.m b/src/fade_out.m similarity index 99% rename from fade_out.m rename to src/fade_out.m index 4f21a1b..f50812b 100644 --- a/fade_out.m +++ b/src/fade_out.m @@ -29,4 +29,4 @@ function output = fade_out(input, time) end -% This is useful for creating videos, specifically the outro part \ No newline at end of file +% This is useful for creating videos, specifically the outro part From 4b0273fc65297297b2e5e9a8ce17039ee0ce921a Mon Sep 17 00:00:00 2001 From: SeaSponge <61109988+Squidwarder@users.noreply.github.com> Date: Wed, 8 Dec 2021 14:54:11 -0800 Subject: [PATCH 3/4] moved bandreject_filter() to src folder --- bandreject_filter.m => src/bandreject_filter.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename bandreject_filter.m => src/bandreject_filter.m (97%) diff --git a/bandreject_filter.m b/src/bandreject_filter.m similarity index 97% rename from bandreject_filter.m rename to src/bandreject_filter.m index c5155f7..8073a9e 100644 --- a/bandreject_filter.m +++ b/src/bandreject_filter.m @@ -59,4 +59,4 @@ end % 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) \ No newline at end of file +% (easier to do so in the frequency domain) From 472ca761c21f654a7fd900869ae1b1d6c868104c Mon Sep 17 00:00:00 2001 From: SeaSponge <61109988+Squidwarder@users.noreply.github.com> Date: Wed, 8 Dec 2021 14:54:32 -0800 Subject: [PATCH 4/4] moved fade_in() to src folder --- fade_in.m => src/fade_in.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename fade_in.m => src/fade_in.m (99%) diff --git a/fade_in.m b/src/fade_in.m similarity index 99% rename from fade_in.m rename to src/fade_in.m index a09798c..22bef76 100644 --- a/fade_in.m +++ b/src/fade_in.m @@ -26,4 +26,4 @@ function output = fade_in(input, time) output = input .* multiplier; end -% This is useful for making videos, specifically the intro part \ No newline at end of file +% This is useful for making videos, specifically the intro part