In order to plot the amplitude of a spectrum in matlab, here's what you can do.
y is the signal
fs is the samplig frquency
spectrum = 10*log(abs(fftshift(fft(y))) / length(y)); %compute the FFT
precision = fs/length(y);
f = linspace(-fs/2+precision/2, fs/2-precision/2, length(y)); % Create the frequency axis and put the measure in the middle of the bin.
A little more explanation :
fft(y) : yields the complex spectrum (amplitude and phase in complex numbers). The fft function puts the negative part of the spectrum on the right.
fftshift(fft(y)) : brings the negative part of the spectrum at the beggining of your data so it can be displayed on the left of your spectrum.
abs( fftshift(fft(y)) ) : extract the amplitude of your values, thus remove the phase and yields real numbers.
abs( fftshift(fft(y)) ) /length(y) : Normalize your spectrum. Since the DFT or FFT is an integral, the bigger the dataset, the bigger the amplitude. By dividing by the number of sample, we get an amplitude that is not dependant on the acquisition length. Doing length(y) is the same as fs*T (where T the length of the acquisition in time).
10*log( abs( fftshift(fft(y)) ) /length(y) ) : Will scale the spectrum on a logarithmic scale. We often do that to be able to see a bigger range of values. If your noise floor is at -80dB and your signal at 0dB. That means an amplitude of 1 and a noise level of 0.00000001. You can't really see both on a linear plot.
In your question, you asked :
Why do we normalize with
I explained the division. As for multiplying by 2, I am not sure where you took this information but my guess would be that you looked at an example that was meant to display a single-sided spectrum. A double sided spectrum goes up tu A/2. If you are measuring a real signal (no complex values at the input), the spectrum is symmetrical, therefore looking at the positive side of it makes more sense.
Finally, you said :
I just read:
A = abs(X_total) * 2/(f_s*T) should yield the amplitude
f = linspace(0,f_s,length(X_total)) should yield the corresponding frequency.
Amplitude part is correct.
f = linspace(0,f_s,length(X_total)) is wrong
Your spectrum will go up to fs/2 (Nyquist frequency).
And as for y_envelope, your script doesn't show what the values are of theta and Phi. Are they scalars or vectors ?