This repository has been archived on 2023-12-21. You can view files and clone it, but cannot push or open issues or pull requests.
ece45-project/src/generate_sine.m

16 lines
415 B
Mathematica
Raw Normal View History

2021-12-01 23:17:58 +00:00
function x = generate_sine(amplitude, frequency, phase, fs, duration)
%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;
for i = 1:n
t = i * dt;
x(i) = A * sin(2 * pi * f * t - p);
end
end