Triangle Approximation: Sum of Sinusoids Example
The following Matlab code provides an example of the fact that any signal can constructed using a sum of sinusoids.
clear all; %clear all variables
fs = 50; % sample freq
Ts=1/fs; % sample period
n=0:1*fs; % time window (fs=samples per second), 1 second
tn=n*Ts; % sample index
wave_1=sin(2*pi*5*tn);
wave_2=sin(-1/9*sin(6*pi*5*tn));
wave_3=sin(1/25*sin(10*pi*5*tn));
wave_4=sin(-1/49*sin(14*pi*5*tn));
wave_5=sin(1/81*sin(18*pi*5*tn));
wave_6=sin(-1/121*sin(22*pi*5*tn));
wave_7=sin(1/169*sin(26*pi*5*tn));
x = (8/(pi^2))*(wave_1+wave_2+wave_3+wave_4+wave_5+wave_6+wave_7);
% Time domain plot of x(t)=cos(2*pi*5*tn)
figure('Color',[1 1 1]);
h=plot(tn,wave_1,'--r',tn,wave_2,'--k',tn,x,'g','LineWidth',2);box off;hold on;
xlabel('Time(s)');
ylabel('Amplitude');
title('Square Wave Approximation');
axis([0 1 -1.5 1.5]);
1 comment:
Why does the above code has
x = ( 8 / (pi^2 ) ??????
Please if you could explain, would really appreciate it.
Thanks in advance,
Yatin
Post a Comment