Q:

FFT of triangular wave

I am new in dsp.. so please bear with me.
I want to plot FFT of a triangular wave. I am using the code below to first generate the triangular wave and then take its FFT

Fs=50e6;
Ts=1/Fs;
NFFT=2^14;
Runtime=(NFFT-1)*Ts;
t=0:Ts:Runtime;

fin=5*1e6;

factor=Fs/NFFT;
bin=round(fin/factor);
fin=bin*factor;

fin_MHz=fin/1e6;

y_in=sawtooth(2*pi*fin*t,0.5);

% Calculate Spectrum
Y = fft(y_in,NFFT)/NFFT;
f = (Fs/1e6)*linspace(0,1,NFFT);

Ydb = 20*log10(abs(Y(1:NFFT))) + 6.02;

% % Plot amplitude spectrum.

plot(f,Ydb)
hold on
grid on
ylim([-150 5])
xlim([-5 55])
xlabel('Frequency (MHz)')
ylabel('dB')
set(gca,'YTick',-150:25:0)
refline(0,-78)

The response when input is 5 MHz is as follows : 

The response when input is 5.5 MHz is as follows : 

My questions are :

Do i have any mistakes in my code ?
The response should have been sinc^2 .. i dont see it 
Why the difference between two plots.. i mean more spurs when ip is 5.5 mhz
The amp peak should be in 1 in fft .. it -1.825 dbfs .. ? why ?

Thankyou so much.

A:

Do i have any mistakes in my code ?

Probably OK.

The response should have been sinc^2 .. i dont see it

Fourier Series of Triangle Wave

Why the difference between two plots.. i mean more spurs when ip is 5.5 mhz

Because of spectral aliasing. For 5MHz triangular wave, the harmonics are:
5, 15, 25, 35(-15), 45(-5), 55(5), ...

For 5.5MHz triangular wave, the harmonics are:
5.5, 16.5, 27.5(-22.5), 38.5(-11.5), 49.5(-0.5), 60.5(10.5), ...

On 5MHz triangular wave, the spectral aliasing is hidden because it coincides with non-aliasing spectrum. But, it seems that your code changes the frequency to be multiple of Fs/NFFT, so it is not perfectly hidden.
For perfectly hidden spectral aliasing here, the frequency should be power of two multiple of Fs/NFFT. For example: 3.125 MHz.

The amp peak should be in 1 in fft .. it -1.825 dbfs .. ? why ?

Based on the fourier series, it is $ \frac{8}{\pi^2} $

