This repository has been archived on 2021-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
scientificComputing/programmingstyle/code/calculateSines.m

33 lines
1.0 KiB
Matlab

function sines = calculateSines(times, amplitudes, frequencies)
% Function calculates sinewaves with all combinations of
% given amplitudes and frequencies.
%
% sines = calculateSines(times, amplitudes, frequencies)
%
% Arguments:
% times : vector of times as which the sines should be computed.
% amplitudes : vector with amplitudes.
% frequencies: vector with frequencies.
%
% Returns:
% a 3-D Matrix of sinewaves, 2nd dimension represents
% the amplitudes, 3rd the frequencies.
sines = zeros(length(times), length(amplitudes), length(frequencies));
for i = 1:length(amplitudes)
sines(:,i,:) = sinesWithFrequencies(times, amplitudes(i), frequencies);
end
end
function sines = sinesWithFrequencies(times, amplitude, frequencies)
sines = zeros(length(times), length(frequencies));
for i = 1:length(frequencies)
sines(:,i) = sineWave(times, amplitude, frequencies(i));
end
end
function sine = sineWave(times, amplitude, frequency)
sine = sin(2.0*pi.*times*frequency) .* amplitude;
end