Amplitude and Phase of FFT gives messy results - Matlab [closed]

I'm trying to calculate the spectrum magnitude and phase of a signal, but when I plot them I get pretty messy results:

The signal is displayed on the right, then I have the magnitude and phase of the fft in the centre and to the left accordingly.

I would have expected to see just few peaks in both the spectrums but instead there are a lot of peaks and it gets really messy.

This is my code:

T = mean(diff(t))
fs = 1/T

figure;
subplot(1,3,1)

plot(1000*t,sig);
title ('Time domain');
xlabel('Time(ms)')
subplot(1,3,2)
plot((0:9999)/10,abs(fft(sig))); % magnitude spectrum
title('Spectrum');legend({'Magnitude'});
xlabel('Frequency (Hz)')
subplot(1,3,3)
plot((0:9999)/10,angle(fft(sig))); % phase spectrum
title('Spectrum');legend({'Phase'});
xlabel('Frequency (Hz)')


Am I missing something or is it supposed to be like this?

I tried already rounding off to zero values that are close to zero, but that did not change anything.

closed as unclear what you're asking by Marcus Müller, MBaz, lennon310, Stanley Pawlukiewicz, Matt L.Apr 9 at 10:23

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• We can't really tell without having access to your actual signal. In general this looks like two sine waves with some pink or brown noise added. Perfectly normal. What do you expect to be different here? – Hilmar Mar 24 at 12:41
• since matlab hasn't had an FFT bug that I've ever heard of: this is your signal's phase and magnitude spectrum! It's just what it is, no matter whether you consider that messy or not. – Marcus Müller Mar 24 at 13:36
• if you look at your fft magnitude, you might notice that the values are symmetric around the center. this implies that your data is real and you are plotting negative and positive frequencies. if so, phase often needs to be unwrap – Stanley Pawlukiewicz Mar 24 at 13:37