This question follows from an answer to this other question: Conceptual question on FFT and chirp signal
I wrote a code starting from the spectrogram to compare it with the FFT result.
% Chirp generation
t = [0 0.5 1.0 1.5 2.0]; % time breakpoints
f = [0 200 100 150 300]; % instantaneous frequency breakpoints
p = polyfit(t,f,4);
dt = 0.001;
t = 0:dt:2;
y = chirp(t,p);
L = length(y);
% FFT
NFFT = 2^nextpow2(L);
Y = fft(y,NFFT)/L;
Fs = 1/dt;
f_plot = Fs/2*linspace(0,1,NFFT/2+1);
% Spectrogram
figure()
specgram(y,128,Fs,128,120); % 2D time-freqency display
[S,F,T,P]=spectrogram(y,128,120,128,1E3);
figure()
surf(T,F,10*log10(P),'edgecolor','none')
axis tight
This is what I obtain.
My qyestion is: shouldn't the spectrogram and the FFT have the same amplitude variation? Whereas the spectrogram does not seem to have amplitude variation (the red line is red at the same way everywhere).
Second question, why in the FFT I have high peaks at $100$ and $200 Hz$ only?