Fourier approximation of periodic function, plot not as expected.

I have made a periodic function and would like to plot a fourier approximation on the function I have plotted but am struggling to plot the fourier approximation. This is a normal sine wave which has been passed to a half wave rectifier. This is the fourier approximation below fN (t) = 1/π+1/2sin(t) −2/π cos(2nt)/4n^2 − 1
if true
M=1000; %Data points
NCycle=5; %5 cycles of wave
l=linspace(0,NCycle,M);
f=1/2/pi; %Define frequency
Period=1/f; %Period is 1/frequency
sig=sin(2*pi*f*l*Period); %Orginal signal
subplot(211) %Plot orginal signal
plot(sig); %Plot
ax = gca;
ax.XTickLabel = [0,pi,2*pi,3*pi,4*pi,5*pi,6*pi,7*pi,8*pi,9*pi,10*pi];
grid %Grid on
for t=1:M %Start for loop time=1 to 1000
if sin(2*pi*f*l(t)*Period)<=0 %If signal is less than or equals 0, next step
sig(t)=0; %set to 0 if above true
else
sig(t) = sin(2*pi*f*l(t)*Period); %If not less 0 plot sin(t)
end
end
forapp = sig + 1/pi + 1/2*sin(t) - 2/pi *(cos(2*t)/(4-1));
subplot(212)
plot(sig);
ylim ([-0.25 2.00])
ax = gca;
ax.XTickLabel = [0,pi,2*pi,3*pi,4*pi,5*pi,6*pi,7*pi,8*pi,9*pi,10*pi];
grid
figure;
plot(l,forapp);
% code
end

Réponses (0)

Catégories

En savoir plus sur Fourier Analysis and Filtering dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by