additional comments for :

generate_sine,
generate_square,
generate_triangle,
from Benjamin Liou
This commit is contained in:
Arthur Lu
2021-12-03 20:05:38 -08:00
parent c550b0d28e
commit 23eaa67d25
3 changed files with 91 additions and 33 deletions

View File

@@ -1,15 +1,28 @@
function x = generate_sine(amplitude, frequency, phase, fs, duration, duty)
%GENERATE_SINE:Arthur Lu returns a matrix of sampled sine wave, where the
%phase shift is in number of periods
x = zeros(1, fs * duration);
A = amplitude;
f = frequency;
p = phase;
n = fs * duration;
dt = 1 / fs;
% GENERATE_SINE: returns a matrix of sampled sine wave
% CONTRIBUTORS:
% Arthur Lu: Original author
% Benjamin Liou: refactoring and annotations
% 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 does not apply for sinusoids
% 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) = A * sin(2 * pi * f * t - p);
t = i * dt; % time at the i'th sample
x(i) = amplitude * sin(2 * pi * frequency * t - phase);
end
end