Heavy Side Function Programming
clc
clear
x0=0;
y0=0;
x00=1;
y00=0;
x=1;
y=1;
x1=2;
y1=1;
x2=2;
y2=0;
v1=[ x0 x00 ]
v2=[ y0 y00 ]
f=line(v1,v2)
v3=[ x x1 ]
v4=[ y y1 ]
f1=line(v3,v4)
v5=[ x00 x ]
v6=[ y00 y ]
f2=line(v5,v6)
v7=[ x1 x2 ]
v8=[ y1 y2 ]
f3=line(v7,v8)
grid on
figure(1)
title('Heavy side')
xlabel('x')
ylabel('y')
% for i=1:10;
% t=y00;
% t1=y;
% end
% plot(t);
% hold on
% plot(t1)
clear
x0=0;
y0=0;
x00=1;
y00=0;
x=1;
y=1;
x1=2;
y1=1;
x2=2;
y2=0;
v1=[ x0 x00 ]
v2=[ y0 y00 ]
f=line(v1,v2)
v3=[ x x1 ]
v4=[ y y1 ]
f1=line(v3,v4)
v5=[ x00 x ]
v6=[ y00 y ]
f2=line(v5,v6)
v7=[ x1 x2 ]
v8=[ y1 y2 ]
f3=line(v7,v8)
grid on
figure(1)
title('Heavy side')
xlabel('x')
ylabel('y')
% for i=1:10;
% t=y00;
% t1=y;
% end
% plot(t);
% hold on
% plot(t1)
Example of Coding a DFT (Discrete Fourier Transform)
This can form an introductory example for the student, you can use instead of a random generator for the used function an exponential or other types need to note that the loop range has to be modfied to N-1 to get it into the right form.
clc
clear
k=12;
N=10;
for i=1:N;
n=i
a(i)=cos((2*pi*k*n)/N)
b(i)=-sin((2*pi*k*n)/N)
c(i)=complex(a(i),b(i))
end
for i=1:N;
f(i)=randn(1,1)
end
for i=1:N;
XX(i)=f(i)*c(i)
abs(XX(i))
pause(1)
end
X=sum(XX)
clear
k=12;
N=10;
for i=1:N;
n=i
a(i)=cos((2*pi*k*n)/N)
b(i)=-sin((2*pi*k*n)/N)
c(i)=complex(a(i),b(i))
end
for i=1:N;
f(i)=randn(1,1)
end
for i=1:N;
XX(i)=f(i)*c(i)
abs(XX(i))
pause(1)
end
X=sum(XX)
The theory for writting the code was taken from the following link:
Fast Fourier Transforms
1- Link number 1, http://www.mathworks.co.uk/help/matlab/ref/fft.html
2- Link number 2, http://www.mathworks.co.uk/help/matlab/fourier-analysis-and-filtering.html
3- Link number 3, http://www.mathworks.co.uk/moler/fourier.pdf
4- Link number 4, http://chemwiki.ucdavis.edu/VV:_Mathematical_Concepts/Fourier_Analysis/Fourier_Analysis_in_Matlab
2- Link number 2, http://www.mathworks.co.uk/help/matlab/fourier-analysis-and-filtering.html
3- Link number 3, http://www.mathworks.co.uk/moler/fourier.pdf
4- Link number 4, http://chemwiki.ucdavis.edu/VV:_Mathematical_Concepts/Fourier_Analysis/Fourier_Analysis_in_Matlab
Under Construction.
Excellent video