add wave genration functions

This commit is contained in:
Arthur Lu
2021-12-01 15:17:58 -08:00
parent 13c52f8c7a
commit 2ce7e6a7a4
5 changed files with 67 additions and 0 deletions

15
src/generate_sine.m Normal file
View File

@@ -0,0 +1,15 @@
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