function [ square_error, amplitude, phase ] = estimate_amplitude_phase ( time, signal, frequency )
% 振幅と位相差を推定（周波数は既知）
    S = [ sin(2*pi*frequency*time), -cos(2*pi*frequency*time) ];
    b = (S'*S)\(S'*signal);
    P = b(1); Q = b(2);
    amplitude = sqrt(P*P+Q*Q);
    phase = atan2(Q,P);
    est_signal = amplitude*sin(2*pi*frequency*time - phase);
    sz = size(time);
    square_error = sum((signal - est_signal).^2)/sz(1);
end
