Answer and Explanation:
clear all; close all;
N=512;
t=(1:N)/N;
fs=1000;
f=(1:N)*fs/N;
x= sin(2*pi*200*t) + sin(2*pi*400*t);
y= sin(2*pi*200*t) + sin(2*pi*900*t);
for n = 1:20
a(n) = (2/N)*sum(x.*(cos(2*pi*n*t)))
b(n) = (2/N)*sum(x.*(sin(2*pi*n*t)))
c(n) = sqrt(a(n).^2+b(n).^2)
theta(n) =-(360/(2*pi))*atan(b(n)./a(n));
end
plot(f(1:20),c(1:20),'rd');
disp([a(1:4),b(1:4),c(1:4),theta(1:4)])