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