From 2c4967633e56b26ec91aa3ff3939d1da1b09992a Mon Sep 17 00:00:00 2001 From: bliou000 <95387384+bliou000@users.noreply.github.com> Date: Sat, 4 Dec 2021 16:03:20 -0800 Subject: [PATCH 1/3] additive sine wave synthesizer second argument is a matrix of harmonics to be added --- addSynth.m | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 addSynth.m diff --git a/addSynth.m b/addSynth.m new file mode 100644 index 0000000..93fbbd1 --- /dev/null +++ b/addSynth.m @@ -0,0 +1,34 @@ +function x = addSynth(amplitude, fundamental, harmonics, fs, duration) +% ADDSYNTH: Additive sine wave synthesis + +%CONTRIBUTORS: +%Benjamin Liou: Original author + +% DOCUMENTATION: +% harmonics should ideally be a 1D matrix of: + % overtones: positive integers + % undertones: 1/ positive integers + % example: [1/2, 1, 2, 3] + % NOTE: pitch of the fundamental frequency will still be perceived even + % when the fundamental itself is missing. ex. [4,5,6] + +% NOTE: it seems like when MATLAB's built in sound() takes in values, + % magnitudes over 1 get distorted. + + + + % initialize local variables from input arguments + n = fs * duration; % number of samples (length of matrix) + + % initialize a one dimensional zero matrix to be populated + x = zeros(1, n); + + % populate matrix by adding sine waves + for harmonic = harmonics + x = x + generate_sine(1, fundamental * harmonic, 0, fs, duration); + end + + % scale to amplitude + scalar = max(abs(x)); + x = x / scalar * amplitude; +end \ No newline at end of file From 86f4d02bba124ab69e0908803c387dd9c8b6549a Mon Sep 17 00:00:00 2001 From: bliou000 <95387384+bliou000@users.noreply.github.com> Date: Sat, 4 Dec 2021 16:06:57 -0800 Subject: [PATCH 2/3] Delete addSynth.m --- addSynth.m | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 addSynth.m diff --git a/addSynth.m b/addSynth.m deleted file mode 100644 index 93fbbd1..0000000 --- a/addSynth.m +++ /dev/null @@ -1,34 +0,0 @@ -function x = addSynth(amplitude, fundamental, harmonics, fs, duration) -% ADDSYNTH: Additive sine wave synthesis - -%CONTRIBUTORS: -%Benjamin Liou: Original author - -% DOCUMENTATION: -% harmonics should ideally be a 1D matrix of: - % overtones: positive integers - % undertones: 1/ positive integers - % example: [1/2, 1, 2, 3] - % NOTE: pitch of the fundamental frequency will still be perceived even - % when the fundamental itself is missing. ex. [4,5,6] - -% NOTE: it seems like when MATLAB's built in sound() takes in values, - % magnitudes over 1 get distorted. - - - - % initialize local variables from input arguments - n = fs * duration; % number of samples (length of matrix) - - % initialize a one dimensional zero matrix to be populated - x = zeros(1, n); - - % populate matrix by adding sine waves - for harmonic = harmonics - x = x + generate_sine(1, fundamental * harmonic, 0, fs, duration); - end - - % scale to amplitude - scalar = max(abs(x)); - x = x / scalar * amplitude; -end \ No newline at end of file From 0bfffeed1ebc043ba24871c173b29d7b57db03a1 Mon Sep 17 00:00:00 2001 From: bliou000 <95387384+bliou000@users.noreply.github.com> Date: Sat, 4 Dec 2021 16:10:14 -0800 Subject: [PATCH 3/3] additive sine wave synthesis same as a previous pull request i made (i just gave it a better name instead of "addSynth") --- add_sine.m | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 add_sine.m diff --git a/add_sine.m b/add_sine.m new file mode 100644 index 0000000..e0354fe --- /dev/null +++ b/add_sine.m @@ -0,0 +1,34 @@ +function x = add_sine(amplitude, fundamental, harmonics, fs, duration) +% ADD_SINE: Additive sine wave synthesis + +%CONTRIBUTORS: +%Benjamin Liou: Original author + +% DOCUMENTATION: +% harmonics should ideally be a 1D matrix of: + % overtones: positive integers + % undertones: 1/ positive integers + % example: [1/2, 1, 2, 3] + % NOTE: pitch of the fundamental frequency will still be perceived even + % when the fundamental itself is missing. ex. [4,5,6] + +% NOTE: it seems like when MATLAB's built in sound() takes in values, + % magnitudes over 1 get distorted. + + + + % initialize local variables from input arguments + n = fs * duration; % number of samples (length of matrix) + + % initialize a one dimensional zero matrix to be populated + x = zeros(1, n); + + % populate matrix by adding sine waves + for harmonic = harmonics + x = x + generate_sine(1, fundamental * harmonic, 0, fs, duration); + end + + % scale to amplitude + scalar = max(abs(x)); + x = x / scalar * amplitude; +end \ No newline at end of file