Hi,
I see that what I said about dividing your angles by a factor of 2*length(...) was incorrect because that factor was inside the argument of the angle function. So I will start over. [1] I believe your time array has one too many points. For true periodicity, the value of T_addition should not be the same at the end point as at the first point. Going with something like
N = 1000; dt = .01 Max_t = N*dt; df = 1/Max_t; t = (0:N-1)*dt f = (0:N-1)*df
gives single-point amplitudes at the desired frequencies, zero everywhere else. The extra time point messes that up. If you try plotting the fft either way you will see a significant difference. [2] Sometimes phase variations make good sense, such as with filters, but there is not exactly such a thing as a phase spectrum in all cases. If you have tiny amplitudes between peaks, down around 1e-10 or whatever, you will still get phase angles, which are basically meaningless. [3] Point 1 in the freq array is zero frequency, point 2 matches up with the end point, 3 with end-2 etc. Your code is close but in the last for loop the the -2 terms should be +2. [4] For the fourier transform or fft of a real function, the phase angle at negative frequency is minus the phase angle at positive frequency. So in the last line of the last for loop the = phase should be = - phase. Once those changes are made the plots are reasonably good. The phases from the fft look like noise but almost all those phases belong to minuscule amplitudes; I believe the phases at the actual signal points are correct.
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Explore similar technical troubleshooting questions and verified MATLAB solutions: