Matlab code for Delta function generation from cosine signal
MATLAB Program:
figure
pause(2);
t=-1:0.01:1;
A=2*pi;
a=1/(pi);
y=0;
n=1;
y=a*cos(i*t);
z=(a/2)+y;
plot(t,z);
pause(2);
clf
t=-1:0.01:1;
A=2*pi;
a=1/(pi);
y=0;
n=2;
for i=1:n
y=y+a*cos(i*t);
i=i+1;
end
z=(a/2)+y;
plot(t,z);
pause(2);
clf
t=-1:0.01:1;
A=2*pi;
a=1/(pi);
y=0;
n=5;
for i=1:n
y=y+a*cos(i*t);
i=i+1;
end
z=(a/2)+y;
plot(t,z);
pause(2);
clf
t=-1:0.01:1;
A=2*pi;
a=1/(pi);
y=0;
n=10;
for i=1:n
y=y+a*cos(i*t);
i=i+1;
end
z=(a/2)+y;
plot(t,z);
pause(2);
clf
t=-1:0.01:1;
A=2*pi;
a=1/(pi);
y=0;
n=20;
for i=1:n
y=y+a*cos(i*t);
i=i+1;
end
z=(a/2)+y;
plot(t,z);
pause(2);
clf
t=-1:0.01:1;
A=2*pi;
a=1/(pi);
y=0;
n=50;
for i=1:n
y=y+a*cos(i*t);
i=i+1;
end
z=(a/2)+y;
plot(t,z);
pause(2);
clf;
t=-1:0.01:1;
A=2*pi;
a=1/(pi);
y=0;
n=100;
for i=1:n
y=y+a*cos(i*t);
i=i+1;
end
z=(a/2)+y;
plot(t,z);
t=-1:0.01:1;
A=2*pi;
a=1/(pi);
y=0;
n=500;
for i=1:n
y=y+a*cos(i*t);
i=i+1;
end
z=(a/2)+y;
plot(t,z);
pause(2);
clf
t=-1:0.01:1;
A=2*pi;
a=1/(pi);
y=0;
n=1000;
for i=1:n
y=y+a*cos(i*t);
i=i+1;
end
z=(a/2)+y;
plot(t,z);
t=-1:0.01:1;
A=2*pi;
a=1/(pi);
y=0;
n=20000;
for i=1:n
y=y+a*cos(i*t);
i=i+1;
end
z=(a/2)+y;
plot(t,z);
Output:
No comments