enter image description here Since I'm freshman of MATLAB, I'm not quite familiar with the functions of MATLAB and I wonder how to compute the fourier coeffiecients of these two periodic functions in MATLAB.
I tried to ask GPT but its code wasn't correct and didn't output the expected answers. I wanna get the correct answers like the attached photo.enter image description here
Check this:
Here,
t,xis the original signalf,gis the FFT signal,dt=0.05is the sampling time,F=10is the Nyquist frequency,T=2is the total time andf0=2is the frequency of the cosine.Note that
f0<F, as you already heard about, which is evident by looking theFrange of the frequency plot.Note here, that if you change
absbyreal, the result is the same, since this cosine is perfectly even. Change just one parameter, and you may lost this property.Note
fftshiftis required to do the symmetrical shift magic, which is nothing more than shifting the middle or the array in the beginning.Finally, what EVERYBODY MISSES, is the little
g0=sqrt(dt/F)factor, which enables bothxandg, as calculated before, to satisfy the fabulous Parseval Identity, which means no other thing that the squared integrals of both signalssum(x.^2*dt)andsum(g.^2*df)are the same.From here, you finally confirm that the FFT has units of
x/tand the Fourier Transformghas units ofxt.Check the parameters and enjoy yourself from here.