From 95a079e224204e68ebb55fca60497ab46f685d6d Mon Sep 17 00:00:00 2001 From: TurtleEmperorx Date: Thu, 9 Dec 2021 18:26:28 -0800 Subject: [PATCH 1/7] Added two Filters that enhance and dampen around a target range Filter format matches readme. Can handle dual channel audio --- src/AnuragDampenTarget.m | 4 +++- src/AnuragEnchanceTarget.m | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/AnuragDampenTarget.m b/src/AnuragDampenTarget.m index 29d3576..41b529b 100644 --- a/src/AnuragDampenTarget.m +++ b/src/AnuragDampenTarget.m @@ -1,4 +1,4 @@ -function output_x = AnuragDampenTarget(x, Fs,TARGET, AreaPercentage) +function output_x = AnuragDampenTarget(x, Fs,LOW, MID, HIGH) %Dampen a range of frequencies a percentage around the target frequency %Also maintain the other frequencies so that the target is muted %percentage is expressed as a number between 0 and 1. @@ -8,6 +8,8 @@ function output_x = AnuragDampenTarget(x, Fs,TARGET, AreaPercentage) % Anurag Jadhav: function creator % Detailed explanation goes here + TARGET = MID; + AreaPercentage = 0.15; [dim,len] = size(x); %get length of the input F = Fs * ((-len/2) : ((len/2) - 1)) / len; lenf = length(F); diff --git a/src/AnuragEnchanceTarget.m b/src/AnuragEnchanceTarget.m index 33923ce..9a348b0 100644 --- a/src/AnuragEnchanceTarget.m +++ b/src/AnuragEnchanceTarget.m @@ -1,4 +1,4 @@ -function output_x = AnuragEnchanceTarget(x, Fs,TARGET, AreaPercentage) +function output_x = AnuragEnchanceTarget(x, Fs,LOW, MID, HIGH) %Amplify a range of frequencies a percentage around the target frequency %Also damnpen the other frequencies so that the target is easier to hear %percentage is expressed as a number between 0 and 1. @@ -8,6 +8,8 @@ function output_x = AnuragEnchanceTarget(x, Fs,TARGET, AreaPercentage) % Anurag Jadhav: function creator % Detailed explanation goes here + TARGET = MID; + AreaPercentage = 0.15; [dim,len] = size(x); %get length of the input F = Fs * ((-len/2) : ((len/2) - 1)) / len; lenf = length(F); From eebe4150c64e26a3f8ffa62c5a4adf238741ba65 Mon Sep 17 00:00:00 2001 From: TurtleEmperorx Date: Thu, 9 Dec 2021 18:28:02 -0800 Subject: [PATCH 2/7] relocated --- src/{ => Filter}/AnuragDampenTarget.m | 0 src/{ => Filter}/AnuragEnchanceTarget.m | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/{ => Filter}/AnuragDampenTarget.m (100%) rename src/{ => Filter}/AnuragEnchanceTarget.m (100%) diff --git a/src/AnuragDampenTarget.m b/src/Filter/AnuragDampenTarget.m similarity index 100% rename from src/AnuragDampenTarget.m rename to src/Filter/AnuragDampenTarget.m diff --git a/src/AnuragEnchanceTarget.m b/src/Filter/AnuragEnchanceTarget.m similarity index 100% rename from src/AnuragEnchanceTarget.m rename to src/Filter/AnuragEnchanceTarget.m From 215d9e2b9f467257d5118c3db883735d41888395 Mon Sep 17 00:00:00 2001 From: TurtleEmperorx Date: Thu, 9 Dec 2021 18:56:30 -0800 Subject: [PATCH 3/7] updated FilterSelect --- src/AnuragEnchanceTarget.m | 54 +++++++++++++++++++ ...EnchanceTarget.m => AnuragEnhanceTarget.m} | 0 src/Select/FilterSelect.m | 4 ++ 3 files changed, 58 insertions(+) create mode 100644 src/AnuragEnchanceTarget.m rename src/Filter/{AnuragEnchanceTarget.m => AnuragEnhanceTarget.m} (100%) diff --git a/src/AnuragEnchanceTarget.m b/src/AnuragEnchanceTarget.m new file mode 100644 index 0000000..a43ebfe --- /dev/null +++ b/src/AnuragEnchanceTarget.m @@ -0,0 +1,54 @@ +function output_x = AnuragEnhanceTarget(x, Fs,LOW, MID, HIGH) +%Amplify a range of frequencies a percentage around the target frequency +%Also damnpen the other frequencies so that the target is easier to hear +%percentage is expressed as a number between 0 and 1. +%target is the midpoint of the frequency range to amplify +%x and Fs are the signal and frequency +% CONTRIBUTORS: +% Anurag Jadhav: function creator + +% Detailed explanation goes here + TARGET = MID; + AreaPercentage = 0.15; + [dim,len] = size(x); %get length of the input + F = Fs * ((-len/2) : ((len/2) - 1)) / len; + lenf = length(F); + Mod_Freq = ifft(fft(x)); %Fourier Transform of the input signal + output = zeros([1,lenf]); % zero array of size Mod_freq + if(dim == 2) %check for dual channel audio + F = [F;F]; + output = [output;output]; + end + %set the bounds + lowerBound = (1-AreaPercentage) * TARGET; + upperBound = (1+AreaPercentage) * TARGET; +%% Amplify the target frequencies and dampen the others + if(dim == 2) %iterate through both channels if track is dual channel + for n = 1:lenf + if ((lowerBound < abs(F(1,n))) && abs(F(1,n)) < upperBound) + output(1,n) = 2; + else + output(1,n) = 0.75; + end + end + for n = 1:lenf + if ((lowerBound < abs(F(2,n))) && abs(F(2,n)) < upperBound) + output(2,n) = 2; + else + output(2,n) = 0.75; + end + end + else %iterate onnly once for monochannel + for n = 1:lenf + if ((lowerBound < abs(F(n))) && abs(F(n)) < upperBound) + output(n) = 2; + else + output(n) = 0.75; + end + end + end +%%Filter the original signal and transform + filtered_Mod_Freq = fftshift(Mod_Freq .* output); + output_x = real(ifft(filtered_Mod_Freq)); + +end \ No newline at end of file diff --git a/src/Filter/AnuragEnchanceTarget.m b/src/Filter/AnuragEnhanceTarget.m similarity index 100% rename from src/Filter/AnuragEnchanceTarget.m rename to src/Filter/AnuragEnhanceTarget.m diff --git a/src/Select/FilterSelect.m b/src/Select/FilterSelect.m index 659a0d1..6e5c61c 100644 --- a/src/Select/FilterSelect.m +++ b/src/Select/FilterSelect.m @@ -19,6 +19,10 @@ function output = FilterSelect(input,Fs,LOW,MED,HIGH,number) output = seperate_prevalent_schluep(input, Fs, LOW, MED, HIGH); elseif(number == "Option 6") output = bandreject_filter(input, Fs, LOW, HIGH); + elseif(number == "Option 7") + output = AnuragEnhanceTarget(input, Fs, LOW,MID, HIGH); + elseif(number == "Option 8") + output = AnuragDampenTarget(input, Fs, LOW,MID, HIGH); else output = input; end From 8bc3ad3b855558eea9cacbf2df0b60f8743b0f30 Mon Sep 17 00:00:00 2001 From: TurtleEmperorx Date: Fri, 10 Dec 2021 13:55:36 -0800 Subject: [PATCH 4/7] moved filters out of subfolder --- src/{Filter => }/AnuragDampenTarget.m | 0 src/AnuragEnchanceTarget.m | 54 -------------------------- src/{Filter => }/AnuragEnhanceTarget.m | 0 3 files changed, 54 deletions(-) rename src/{Filter => }/AnuragDampenTarget.m (100%) delete mode 100644 src/AnuragEnchanceTarget.m rename src/{Filter => }/AnuragEnhanceTarget.m (100%) diff --git a/src/Filter/AnuragDampenTarget.m b/src/AnuragDampenTarget.m similarity index 100% rename from src/Filter/AnuragDampenTarget.m rename to src/AnuragDampenTarget.m diff --git a/src/AnuragEnchanceTarget.m b/src/AnuragEnchanceTarget.m deleted file mode 100644 index a43ebfe..0000000 --- a/src/AnuragEnchanceTarget.m +++ /dev/null @@ -1,54 +0,0 @@ -function output_x = AnuragEnhanceTarget(x, Fs,LOW, MID, HIGH) -%Amplify a range of frequencies a percentage around the target frequency -%Also damnpen the other frequencies so that the target is easier to hear -%percentage is expressed as a number between 0 and 1. -%target is the midpoint of the frequency range to amplify -%x and Fs are the signal and frequency -% CONTRIBUTORS: -% Anurag Jadhav: function creator - -% Detailed explanation goes here - TARGET = MID; - AreaPercentage = 0.15; - [dim,len] = size(x); %get length of the input - F = Fs * ((-len/2) : ((len/2) - 1)) / len; - lenf = length(F); - Mod_Freq = ifft(fft(x)); %Fourier Transform of the input signal - output = zeros([1,lenf]); % zero array of size Mod_freq - if(dim == 2) %check for dual channel audio - F = [F;F]; - output = [output;output]; - end - %set the bounds - lowerBound = (1-AreaPercentage) * TARGET; - upperBound = (1+AreaPercentage) * TARGET; -%% Amplify the target frequencies and dampen the others - if(dim == 2) %iterate through both channels if track is dual channel - for n = 1:lenf - if ((lowerBound < abs(F(1,n))) && abs(F(1,n)) < upperBound) - output(1,n) = 2; - else - output(1,n) = 0.75; - end - end - for n = 1:lenf - if ((lowerBound < abs(F(2,n))) && abs(F(2,n)) < upperBound) - output(2,n) = 2; - else - output(2,n) = 0.75; - end - end - else %iterate onnly once for monochannel - for n = 1:lenf - if ((lowerBound < abs(F(n))) && abs(F(n)) < upperBound) - output(n) = 2; - else - output(n) = 0.75; - end - end - end -%%Filter the original signal and transform - filtered_Mod_Freq = fftshift(Mod_Freq .* output); - output_x = real(ifft(filtered_Mod_Freq)); - -end \ No newline at end of file diff --git a/src/Filter/AnuragEnhanceTarget.m b/src/AnuragEnhanceTarget.m similarity index 100% rename from src/Filter/AnuragEnhanceTarget.m rename to src/AnuragEnhanceTarget.m From a96cdbb84ff7d3e00a52fabfa61f7694019cf7b8 Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Fri, 10 Dec 2021 14:02:34 -0800 Subject: [PATCH 5/7] move new generate functions to NotWorking --- src/NotWorking/generate_cosine.m | 25 +++++++++++++ src/NotWorking/generate_pulse.m | 33 +++++++++++++++++ src/NotWorking/generate_trapezoid.m | 55 +++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 src/NotWorking/generate_cosine.m create mode 100644 src/NotWorking/generate_pulse.m create mode 100644 src/NotWorking/generate_trapezoid.m diff --git a/src/NotWorking/generate_cosine.m b/src/NotWorking/generate_cosine.m new file mode 100644 index 0000000..8a013ed --- /dev/null +++ b/src/NotWorking/generate_cosine.m @@ -0,0 +1,25 @@ +function x = generate_cosine(amplitude, frequency, phase, fs, duration, duty) +% GENERATE_WAVENAME: returns a matrix of sampled WAVENAME wave + +% CONTRIBUTORS: +% Mekhi Ellington: Original Creator + +% DOCUMENTATION: +% phase shift is in number of periods +% fs is the sampling frequency: how many sample points per second +% duration is time in seconds +% duty is a number between 0 and 1 + + % initialize local variables from input arguments + n = fs * duration; % number of samples (length of matrix) + dt = 1 / fs; % sampling period: time between two sample points + + % initialize a one dimensional zero matrix to be populated + x = zeros(1, n); + + % populate the matrix + for i = 1:n + t = i * dt; + x(i) = amplitude * cos(2*pi*frequency*t-phase); + end +end \ No newline at end of file diff --git a/src/NotWorking/generate_pulse.m b/src/NotWorking/generate_pulse.m new file mode 100644 index 0000000..2f9c316 --- /dev/null +++ b/src/NotWorking/generate_pulse.m @@ -0,0 +1,33 @@ +function x = generate_pulse(amplitude, frequency, phase, fs, duration, duty) +% GENERATE_puse: returns a matrix of sampled pulse wave + +% CONTRIBUTORS: +% Brian Tran: Created the wave + +% DOCUMENTATION: +% phase shift is in number of periods +% fs is the sampling frequency: how many sample points per second +% duration is time in seconds +% duty is a number between 0 and 1 + + % initialize local variables from input arguments + n = fs * duration; % number of samples (length of matrix) + dt = 1 / fs; % sampling period: time between two sample points + % initialize a one dimensional zero matrix to be populated + x = zeros(1, n); + f0=1e+6; % 1MHz + Fs=3e+6; + Tf=0.001; % 1 millisecond + t=0:1/Fs:Tf-1/Fs; + td=0.1; % duty cycle + A0=10; % 10 Volts + F=0; + N=1000; % Number of points + + % populate the matrix + for n = 1:N + F=F+(1/n)*cos(n*2*pi*f0*t).*sin(n*pi*td); + end + F=F*(2*A0/pi); + F=F+A0*td; +end \ No newline at end of file diff --git a/src/NotWorking/generate_trapezoid.m b/src/NotWorking/generate_trapezoid.m new file mode 100644 index 0000000..69ce591 --- /dev/null +++ b/src/NotWorking/generate_trapezoid.m @@ -0,0 +1,55 @@ +function x = generate_trapezoid(amplitude, frequency, phase, fs, duration, duty) +% GENERATE_TRAPEZOID: returns a matrix of sampled square wave + +% CONTRIBUTORS: +% Daniel Doan: Author + +% DOCUMENTATION: +% phase shift is in number of periods +% fs is the sampling frequency: how many sample points per second +% duration is time in seconds +% duty cycle should be a number between 0 and 1. + % duty of 0.5 would have 2 trapezoids in first half of each cycle + % example of wave with duty of 0.5, where the peaks are amplitude/2: + % + % ____ + % / \ + % / \ ________________ + % \ / + % \____/ + % + + + +% initialize local variables from input arguments + n = fs * duration; % number of samples (length of matrix) + dt = 1 / fs; % sampling period: time between two sample points + + % initialize a one dimensional zero matrix to be populated + x = zeros(1, n); + + % populate the matrix + for i = 1:n + t = i * dt; + + % periodic ramp from 0 to 1 + % progression through a cycle + st = mod(frequency * t - phase, 1); + slope = (amplitude/2) / (duty/8); + if(st < duty) + if(st < duty/8 || st > 7*duty/8) + x(i) = slope * st; + else + if(st < 5*duty/8) + x(i) = amplitude/2 - slope * (st-(3*duty/8)); + end + if(st < 3*duty/8) + x(i) = amplitude/2; + end + if(st > 5*duty/8) + x(i) = -amplitude/2; + end + end + end + end +end \ No newline at end of file From 5bbf592611ede34cab0a7d0d0cd475583db21cf3 Mon Sep 17 00:00:00 2001 From: SeaSponge <61109988+Squidwarder@users.noreply.github.com> Date: Fri, 10 Dec 2021 14:18:56 -0800 Subject: [PATCH 6/7] Fixed issue with the naming of the function result The return value is now renamed "Output". Should be working now. --- src/Filter/bandreject_filter.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Filter/bandreject_filter.m b/src/Filter/bandreject_filter.m index 8073a9e..9d089b9 100644 --- a/src/Filter/bandreject_filter.m +++ b/src/Filter/bandreject_filter.m @@ -1,4 +1,4 @@ -function output_y = bandreject_filter(Input, Fs, Low, High) +function Output = 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 From ebc18b5b1ddb8c5b2e38f9478f5681edc160493d Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Fri, 10 Dec 2021 14:21:45 -0800 Subject: [PATCH 7/7] moved non functional Filters to NotWorking --- src/{Filter => NotWorking}/epic_effect_schluep.m | 0 src/{Filter => NotWorking}/muffled_effect_schluep.m | 0 src/{Filter => NotWorking}/seperate_prevalent_schluep.m | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename src/{Filter => NotWorking}/epic_effect_schluep.m (100%) rename src/{Filter => NotWorking}/muffled_effect_schluep.m (100%) rename src/{Filter => NotWorking}/seperate_prevalent_schluep.m (100%) diff --git a/src/Filter/epic_effect_schluep.m b/src/NotWorking/epic_effect_schluep.m similarity index 100% rename from src/Filter/epic_effect_schluep.m rename to src/NotWorking/epic_effect_schluep.m diff --git a/src/Filter/muffled_effect_schluep.m b/src/NotWorking/muffled_effect_schluep.m similarity index 100% rename from src/Filter/muffled_effect_schluep.m rename to src/NotWorking/muffled_effect_schluep.m diff --git a/src/Filter/seperate_prevalent_schluep.m b/src/NotWorking/seperate_prevalent_schluep.m similarity index 100% rename from src/Filter/seperate_prevalent_schluep.m rename to src/NotWorking/seperate_prevalent_schluep.m