clear all;
close all;

amplituda = 230.123
offset = 22.33
uhel = 34.56
N = 512;

t = linspace(0, 0.02-0.02/N, N);	% Přesně jedna perioda
x1 = sqrt(2)*amplituda*sin(2*pi*51*t+uhel*pi/180) + offset;
suma = sum(x1);	% Suma
sumasq = x1*x1';	% Suma druhých mocnin
avg = suma/N
rms = sqrt(sumasq/N);
rmsac = sqrt(sumasq/N-avg^2)	% stejné jako sqrt(rms^2-avg^2)

ph = 2*pi*50*t;
c = cos(ph)';
s = sin(ph)';

re = x1*c/N;
im = x1*s/N;

phase = atan2(re, im)/pi*180

plot(t, x1);

ErrAmplituda = rmsac - amplituda
ErrOffset = avg - offset
ErrUhel = phase - uhel