From 74e088c403d3d42d00e5d866078a57f9ddfdc1c5 Mon Sep 17 00:00:00 2001 From: Alex Nguyen Date: Mon, 6 Dec 2021 11:17:55 -0800 Subject: [PATCH 1/5] Cleaned links to useful websites --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 1807172..65d2e76 100644 --- a/README.md +++ b/README.md @@ -57,10 +57,10 @@ where LOW, MED, HIGH are user-selected variables of any value. ## Useful websites - - https://learningsynths.ableton.com - - https://learningsynths.ableton.com/en/playground - - https://blog.demofox.org/diy-synthesizer/ - - http://portaudio.com/ - - https://ccrma.stanford.edu/software/stk/ - - https://cycling74.com/products/max - - http://msp.ucsd.edu/software.html + - [Learning Synths](https://learningsynths.ableton.com) + - [Learning Synths Playground](https://learningsynths.ableton.com/en/playground) + - [DIY Synthesisers](https://blog.demofox.org/diy-synthesizer/) + - [Port Audio (audio I/O library)](http://portaudio.com/) + - [Synthesis ToolKit in C++](https://ccrma.stanford.edu/software/stk/) + - [Max](https://cycling74.com/products/max) + - [Software by Miller Puckette](http://msp.ucsd.edu/software.html) From 03f7c5f0e5b71928d551225f85b589fa1d8b7fea Mon Sep 17 00:00:00 2001 From: Alex Nguyen Date: Wed, 8 Dec 2021 17:05:52 -0800 Subject: [PATCH 2/5] Added first draft of generating heart monitor wave --- src/generate_heart_monitor.m | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/generate_heart_monitor.m diff --git a/src/generate_heart_monitor.m b/src/generate_heart_monitor.m new file mode 100644 index 0000000..3511faa --- /dev/null +++ b/src/generate_heart_monitor.m @@ -0,0 +1,42 @@ +function x = generate_heart_monitor(amplitude, frequency, phase, fs, duration, duty) +% GENERATE_SINE: returns a matrix of sampled heart monitor wave + +% CONTRIBUTORS: +% Alex Nguyen: Original 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 or less would return -amplitude for all sample points + % duty of 0.25 would return +amplitude for first quarter of each cycle + % then return -amplitude for the remaining three-fourths + % duty of 1 would return all +amplitude + + + % 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; % time at the i'th sample + st = mod(frequency * t - phase, 1); + + if (duty-0.1 < st && st < duty) + slope = amplitude / duty; + intercept = -0.5 * amplitude; + x(i) = slope * st + intercept; + elseif (duty < st && st < duty+0.1) + slope = -amplitude / duty; + intercept = amplitude * (duty/(1-duty) + 0.5); + x(i) = slope * st + intercept; + else + x(i) = 0; + end +end + From 44d53234e99603bc0ed2095cd694d64468a802fb Mon Sep 17 00:00:00 2001 From: Alex Nguyen Date: Wed, 8 Dec 2021 19:46:28 -0800 Subject: [PATCH 3/5] Polished function to look like a heart beat kinda --- src/generate_heart_monitor.m | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/generate_heart_monitor.m b/src/generate_heart_monitor.m index 3511faa..6a6d530 100644 --- a/src/generate_heart_monitor.m +++ b/src/generate_heart_monitor.m @@ -19,6 +19,7 @@ function x = generate_heart_monitor(amplitude, frequency, phase, fs, duration, d 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); @@ -27,16 +28,15 @@ function x = generate_heart_monitor(amplitude, frequency, phase, fs, duration, d t = i * dt; % time at the i'th sample st = mod(frequency * t - phase, 1); - if (duty-0.1 < st && st < duty) + if (duty-0.25 < st && st < duty) slope = amplitude / duty; intercept = -0.5 * amplitude; x(i) = slope * st + intercept; - elseif (duty < st && st < duty+0.1) - slope = -amplitude / duty; - intercept = amplitude * (duty/(1-duty) + 0.5); - x(i) = slope * st + intercept; + elseif (duty < st && st < duty+0.25) + slope = amplitude / duty; + intercept = -amplitude; + x(i) = slope * st + (1.5 * intercept); else x(i) = 0; end -end - +end \ No newline at end of file From f241f1d616ff287bc952fc8ba10f2fea6ca9d7fa Mon Sep 17 00:00:00 2001 From: Alex Nguyen Date: Wed, 8 Dec 2021 19:47:51 -0800 Subject: [PATCH 4/5] Renamed function --- src/{generate_heart_monitor.m => generate_heartbeat.m} | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) rename src/{generate_heart_monitor.m => generate_heartbeat.m} (90%) diff --git a/src/generate_heart_monitor.m b/src/generate_heartbeat.m similarity index 90% rename from src/generate_heart_monitor.m rename to src/generate_heartbeat.m index 6a6d530..4173468 100644 --- a/src/generate_heart_monitor.m +++ b/src/generate_heartbeat.m @@ -1,8 +1,9 @@ -function x = generate_heart_monitor(amplitude, frequency, phase, fs, duration, duty) +function x = generate_heartbeat(amplitude, frequency, phase, fs, duration, duty) % GENERATE_SINE: returns a matrix of sampled heart monitor wave % CONTRIBUTORS: % Alex Nguyen: Original Author +% Conner Hsu: Reviewed Code and Assisted in polishing % DOCUMENTATION: % phase shift is in number of periods From 9d49868c0db5548b5087bb5889894202e7712f04 Mon Sep 17 00:00:00 2001 From: AlexNguyenJJ Date: Thu, 9 Dec 2021 14:29:25 -0800 Subject: [PATCH 5/5] Added comments --- src/generate_heartbeat.m | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/generate_heartbeat.m b/src/generate_heartbeat.m index 4173468..40230d6 100644 --- a/src/generate_heartbeat.m +++ b/src/generate_heartbeat.m @@ -9,11 +9,14 @@ function x = generate_heartbeat(amplitude, frequency, phase, fs, duration, duty) % 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 or less would return -amplitude for all sample points - % duty of 0.25 would return +amplitude for first quarter of each cycle - % then return -amplitude for the remaining three-fourths - % duty of 1 would return all +amplitude +% duty cycle should be a number between 0 and 0.5. + % duty of 0 or less would return 0 for all sample points + % duty of 0.5 or less would return a heartbeat signal since there would be + % equal amount of space within 1 period to have the right and left sides be equal + % duty of greater than 0.5 but less than 1 would return a slope starting at that duty i.e. + % the left side but leaving little room to the right side + % duty of between 1 and 2 would give a sawtooth wave in the +amplitude. + % duty greater than 2 would return 0 for all sample points % initialize local variables from input arguments @@ -29,11 +32,11 @@ function x = generate_heartbeat(amplitude, frequency, phase, fs, duration, duty) t = i * dt; % time at the i'th sample st = mod(frequency * t - phase, 1); - if (duty-0.25 < st && st < duty) + if (duty-(duty / 2) < st && st < duty) slope = amplitude / duty; intercept = -0.5 * amplitude; x(i) = slope * st + intercept; - elseif (duty < st && st < duty+0.25) + elseif (duty < st && st < duty+(duty / 2)) slope = amplitude / duty; intercept = -amplitude; x(i) = slope * st + (1.5 * intercept);