Hello everyone. I found a lot of ways to achieve Fourier synthesis in MATLAB but they all use sine. I thought the plot of sine and cosine waves we're almost the same but the waveform formed differ drastically. The waveform of the former (sine) almost looks like a square wave but the latter (cosine) didn't even look like it. Is there any possible way to do this using cosine?
Sample code(by user: Youssef Khmou) that I found:
Fs=150; t=0:1/Fs:4-1/Fs; f=2; x=square(2*pi*f*t); figure; plot(t,x); axis([0 1 -2 2]); % Approximation with Fourier decomposition
y=0; N=11; for r=1:2:N y=y+sin(2*pi*f*t*r)/r; end hold on; plot(t,y,'r'); xlabel('t'); ylabel('magnitude'); hold off;
Best Answer