title: basic FFT normalization questions
body: <p>I'm using Matlab to take FFTs of signals, and I'm getting stuck on the normalization. Specifically, how to normalize the spectrum into units of dBm. I know that 0.316228 is the correct normalization factor, but my questions are related to how to normalize the bins correctly. </p>
  
  <p>I created the following program to raise my questions. Just cut and paste it into Matlab and it'll run itself. See questions in-line. </p>
  
  <p>In particular, I'm confused how to normalize the bins. For example, if the FFT has indices 1:end, where end is even, when I calculate the FFT magnitude spectrum, should I multiply by (2/N) for indices 2:(end/2)? Similarly, does the bin at the Nyquist frequency (located at index end/2+1) get normalized to (1/N)? I know there's a bunch of ways to normalize depending on one's interest. Let's say the signal I'm using (St below) are voltages captured from an ADC. </p>
  
  <p>Any feedback is greatly appreciated. Thanks in advance!</p>
  
  <pre><code>%% 1. Create an Example Signal
  N = 2^21 ;                   % N = number of points in time-domain signal (St)
  St = 1 + rand(N,1,'single'); % St = example broadband signal (e.g. random noise)
  
  % take FFT
  Sf = fft(St, N);                    
  Sf_mag = (2/N)*abs(Sf(1: N/2 + 1));
  Sf_dBm = 20*log10(Sf_mag / 0.316228); % 0.316338 is peak voltage of 1 mW into 50 Ohms
  
  % Q: Are Sf_mag and Sf_dBm normalized correctly? (assume 0.316338 is correct 
  %    peak voltage to get 1mW in 50 Ohms)
  % Q: Should Sf_mag(fftpoints/2 + 1) = (1/N)*abs(Sf(fftpoints/2 + 1) for correct normalization 
  %    of Nyquist frequency? (since Nyquist frequency is not folded in frequency 
  %    like the others are)                         
  
  %% 2. Plot Result
  
  % create FFT spectrum x-axis
  samplerate = 20e9;  % 20 Gsamples/sec 
  fft_xaxis = single(0 : 1 : N/2)';    
  fft_xaxis = fft_xaxis * single(samplerate/N); 
  
  semilogx(fft_xaxis, Sf_dBm, 'b-')
  xlabel('Frequency (Hz)');
  ylabel('FFT Magnitude (dBm)');
  title('Spectrum of Signal (Blue) vs Frequency (Hz)');
  xlim([1e4 1e10]);
  grid on;
  </code></pre>