aboutsummaryrefslogtreecommitdiffstats
path: root/lab2/scripts/gensin.m
blob: ae8b6d736d8aea1005fc3f254cdce6481fa25c73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
% Generates a discrete sine wave with the following properties

% A: Amplitude
% F0: frequency
% fs: sampling frequency
% theta: initial phase
% nstart: first sample index
% nend: last sample index
function x = gensin(A, F0, fs, theta, nstart, nend)

% zero the column vector to the right size
fullSeries = zeros(nend-nstart+1, 1);

% go through all the elements until the end
for i = 1:nend
    % apply the sine wave for every element
    fullSeries(i) = A*sin(2*pi*F0*i/fs + theta);
end

% set the result to the window that was passed in by the user
x = fullSeries(nstart:nend);

end