MATLAB: Signal processing, fft, adding two cosine waves

adding two cosine wavesdigital signal processingfft

Hi, I can individually retrieve the magnitude and frequency of two cosine waves (say 10*cos(w*t) and 30*cos(w*t)). Suppose the signal is 10*cos(w*t)+30*cos(w*t) how to retrieve the magnitudes (i.e, 10 and 30) from the fft. All suggestions welcome.

Best Answer

Then the magnitude will be 40 in this case if the frequencies and phases are the same. And there is no way to extract the 10 and the 30 separately.
n = 0:199;
x = 10*cos(pi/4*n)+30*cos(pi/4*n);
xdft = fft(x);
xdft = xdft(1:length(x)/2+1)/length(x);
xdft(2:end-1) = 2*xdft(2:end-1);
plot(abs(xdft))
abs(xdft(26))