From 9d72926d3876a18a4d3890689bc73437b16464ff Mon Sep 17 00:00:00 2001 From: MekhiTheKing <95403331+MekhiTheKing@users.noreply.github.com> Date: Thu, 9 Dec 2021 20:58:19 -0800 Subject: [PATCH] Add files via upload --- src/generate_cosine.m | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/generate_cosine.m diff --git a/src/generate_cosine.m b/src/generate_cosine.m new file mode 100644 index 0000000..8a013ed --- /dev/null +++ b/src/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