0% found this document useful (0 votes)
39 views

Exercise 3 Triangular

This document discusses calculating the total harmonic distortion (THD) of a triangular signal using Fourier analysis in MATLAB. It provides code to calculate the Fourier coefficients of the triangular function and use them to build up the Fourier series for different numbers of harmonics. Taking larger values of N (the number of harmonics) causes the Fourier series to better approximate the original triangular signal. The THD of the triangular signal is calculated and compared to the THD of a square wave, with an explanation of how the Fourier coefficients relate to the expected results.
Copyright
© © All Rights Reserved
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)
39 views

Exercise 3 Triangular

This document discusses calculating the total harmonic distortion (THD) of a triangular signal using Fourier analysis in MATLAB. It provides code to calculate the Fourier coefficients of the triangular function and use them to build up the Fourier series for different numbers of harmonics. Taking larger values of N (the number of harmonics) causes the Fourier series to better approximate the original triangular signal. The THD of the triangular signal is calculated and compared to the THD of a square wave, with an explanation of how the Fourier coefficients relate to the expected results.
Copyright
© © All Rights Reserved
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/ 3

Name: Daniel Criollo

Triangle signal In this second part of the exercise, we are studying the THD associated
with a triangular signal. We re considering the following periodic function of period 2:

() [, [
+ [, [

1. With pen and paper, calculate the coecients of the Fourier series of g.
PDF attached
2. Using the coecient calculated above, write a Matlab code that calculate the value
of the Fourier series of g for a given number of harmonics, noted n.

Here is a part of the code where the calculation of the coefficients of the Fourier Series
clc, clear all, close all;
% Calculate Coefficient aO;an;bn
syms x n;
T=2;
bn=0;
an=0;
a0=0;
f=0;
fun1=x;
a0=a0+(2/T*int(fun1,x,0,1));
bn=bn+(2/T*int(fun1*sin(x*2*pi*n/T),x,0,1));
an=an+(2/T*int(fun1*cos(x*2*pi*n/T),x,0,1));
fun2=-x+2;
bn=bn+(2/T*int(fun2*sin(x*2*pi*n/T),x,1,2));
a0=a0+(2/T*int(fun2,x,1,2));
an=an+(2/T*int(fun2*cos(x*2*pi*n/T),x,1,2));
bn;
N=1;
% Harmonic Number Values
for m=1:3
sumatoria=0;
total=0;
% Fourier Series
for i=1:N
n=i;
sumab=subs(bn);
sumac=subs(an);

sumatoria=sumatoria+sumac*cos(2*n*pi*x/T)+sumab*sin(2*n*pi*x/T);
espectro(i)=-sumac;
equis(i)=n
end
% Harmonics to be displayed
dato=['N=',num2str(N)];
N=N+2;
sumaa=subs(a0);
total=sumaa/2+sumatoria;
kk=1
for k=0:0.01:2
toteval(kk)=vpa(subs(total,k));
postot(kk)=k;
kk=kk+1;
end
% Calculate maximus and minimous
maxb(m)=vpa(max(toteval))
posmx(:,m)=find(toteval==max(toteval));
posmax(m)=postot(posmx(1,m))
minb(m)=vpa(min(toteval))
posmn(:,m)=find(toteval==min(toteval));
posmin(m)=postot(posmn(1,m))
subplot(1,3,m)
hold on
strmin=strcat('MIN=',char(vpa(posmin(m),4)),',',char(vpa(minb(m),4)));
strmax=strcat('MAX=',char(vpa(posmax(m),4)),',',char(vpa(maxb(m),4)));
text(double(posmin(m)),double(minb(m)),strmin)
text(double(posmax(m)),double(maxb(m)),strmax)
ezplot(total,[0 2]);
grid on;
title(dato)
hold on;
te=0:0.001:2;
y=zeros(length(te));
% Original Function
for i=1:length(te)
if te(i)>=0 & te(i)<1
y(i)=te(i);
end
if te(i)>=1 & te(i)<=2
y(i)=2-te(i);
end
end
% Graph
plot(te,y(:,1),'-b');
hold on;
end
figure(2)
stem(equis,espectro)

3. Increase the value of n and check that the Fourier series converge towards g.
The function is periodic with a total of N samples per period. This discrete form of the Fourier
transform is appropriate for numerical evaluation by digital calculation. In this exercise take
differents values of N=1, N=3, N=5 whit (n=n+2), It can be observed that while the variable N
is varied, this variable is adjusted the original signal while growing in a Fourier series, the larger
the N, the closer to the desired signal.

The code made in matlab takes 3 values with (N = N + 2)

dato=['N=',num2str(N)];
N=N+2;
sumaa=subs(a0);
total=sumaa/2+sumatoria;
kk=1

We work with small values to be able to observe the harmonics superimposed on the original
signal
In the graph the maximum and minimum values can be observed in each of the harmonics
calculated for N = 1, N = 3 and N = 5.

The frequency of a signal requires amplitude and phase values of each of the partial values to
construct the wave. The set of these values is called expectro

4. Based on the denition of THD, calculate the THD of g. How does it compare with
the THD of the square signal in section 1? Could we have expected such a result
from the Fourier coecients expression?
PDF attached

You might also like