0% found this document useful (0 votes)
91 views15 pages

Rectangular Function Generator

The document contains code to generate rectangular and triangular functions, calculate their Fourier coefficients, reconstruct signals from a given number of coefficients, and perform operations like delaying and differentiating on the reconstructed signals. Sections of code generate the basic rectangular and triangular waveforms, calculate Fourier coefficients for different values of N, reconstruct signals for various N and plot the results, and define functions to delay or differentiate reconstructed signals.

Uploaded by

ozlemtugfedemir
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views15 pages

Rectangular Function Generator

The document contains code to generate rectangular and triangular functions, calculate their Fourier coefficients, reconstruct signals from a given number of coefficients, and perform operations like delaying and differentiating on the reconstructed signals. Sections of code generate the basic rectangular and triangular waveforms, calculate Fourier coefficients for different values of N, reconstruct signals for various N and plot the results, and define functions to delay or differentiate reconstructed signals.

Uploaded by

ozlemtugfedemir
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Rectangular function generator

y=[];
for x=-T:T/1000:T
z=(-T/2<x&x<T/2);
y=[y z];
end
x=-T:T/1000:T;
plot(x,y)

Triangular function generator


y=[];
for x=-T:T/1000:T
z=(-T/2<x&x<0)*(2/T*x+1)+(0<x&x<T/2)*(-
2/T*x+1)+(x==0);
y=[y z];
end
x=-T:T/1000:T;
plot(x,y)
Finding fourier coefficients of rectangular pulse train
x=[];
for v=-(N-1)/2:(N-1)/2
a=1/T*int(exp(-i*v*2*pi/T*b),b,-T/4,T/4);
x=[x a];
end
x

Finding fourier coefficients of triangular pulse train

x=[];
for v=-(N-1)/2:(N-1)/2
a=1/T*(int((2/T*b+1)*exp(-i*v*2*pi/T*b),b,-
T/2,0)+int((-2/T*b+1)*exp(-i*v*2*pi/T*b),b,0,T/2));
x=[x a];
end
x
Plotting reconstructed signal for a given number of
Fourier coefficients

function z=time(x,T);
y=0;
g=[];
n=(length(x)-1)/2;
for t=-T:T/1000:T;
y=0;
for k=1:(2*n+1);
m=x(k)*exp(j*(k-n-1)*2*pi/T*t);
y=y+m;
end
g=[g y];
end
t=-T:T/1000:T;
plot(t,g)
Part 2 (N=7)

Part 2(N=9)
Part 2 (N=11)
Part2(N=21)
Part 2(N=51)
Part1(N=7)
Part1(N=9)
Part1(N=11)
Part 1(N=21)
Part 3(N=11)
Part 3(N=21)

function z=delay(x)
y=[];
for n=1:length(x)
g=x(n)*exp(-j*2*pi/5*2.5*(n-1-(length(x)-1)/2))
y=[y g];
end
y
Part4 (N=51)

function z=diff(x)
y=[];
for n=1:length(x)
g=x(n)*(j*2*pi/5*(n-1-(length(x)-1)/2))
y=[y g];
end
y

You might also like