0% found this document useful (0 votes)
21 views5 pages

Chapter7 Prob16

The document describes a MATLAB user-defined function, Complex_DFT, that calculates the complex Discrete Fourier Transform (DFT) of a function based on given data points. It includes checks for even number of input values and equal spacing of data points, and generates stem plots for the real and imaginary parts of the coefficients. Two example datasets are provided to demonstrate the function's execution and output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views5 pages

Chapter7 Prob16

The document describes a MATLAB user-defined function, Complex_DFT, that calculates the complex Discrete Fourier Transform (DFT) of a function based on given data points. It includes checks for even number of input values and equal spacing of data points, and generates stem plots for the real and imaginary parts of the coefficients. Two example datasets are provided to demonstrate the function's execution and output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

1

7.16 Write a MATLAB user-defined function that calculates the complex Discrete Fourier Transform
(DFT), according to Eq. (7.50), of a function given by a finite number of points. Name the function
Complex_DFT(t,f) where the input arguments t and f are vectors with the values of the independent and
dependent variables of the data points, respectively. The program should have the following features.
(i) Check to make sure that the user has entered even number, 2N, values (where N is an integer), and if
not, modify the input data by adding a zero entry at the end for f so that there are 2N values.
(ii) Check to make sure that the data points are equally spaced. If not, the program should output an error
message.
(iii) Display stem plots of ReC k and ImC k as a function of frequency ν k = k ⁄ τ .
Execute this program for the following data:
(a)
t 0 0.25 0.5 0.75 1.0 1.25 1.5 1.75 2.0
f(t) 0 0.25 0.5 0.75 1.0 1.25 1.5 1.75 2.0

(b)
t 0 0.25 0.5 0.75 1.0 1.25 1.5 1.75 2.0
f(t) 0 0.4375 0.75 0.9375 1.0 0.9375 0.75 0.4375 2.0

Solution
The user-defined function Complex_DET:

function Complex_DET(t,f)
% DisFourTrans determines the complex discrete Fourier Transform of a
% function given by a finite number of points by using Eqs. (7.50).
% Input variables:
% t A vector with the values of the independent variable.
% f A vector with the values of the dependent variable.
% Output:
% A stem plot of the real and imaginary parts of the coefficients Ck
% as a function of frequncy.

N2=length(t);

Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis
for testing or instructional purposes only to students enrolled in courses for which the textbook
has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the
copyright owner is unlawful.
2

N=N2/2;
dt=t(2)-t(1);
Flag=0;
for n=3:N2
if t(n)-t(n-1) ~=dt
Flag=1;
break
end
end
if Flag == 1
disp(' ERROR: The data points are not equally spaced')
else
if N-fix(N) ~= 0
t(N2+1)=t(N2)+dt;
f(N2+1)=0;
N=(N2+1)/2;
end
kp=[0:N];
nuk=kp/(2*N*dt);
Ck(1)=sum(f(1:2*N))/(2*N);
for k=2:N
CkI(k)=0; CkR(k)=0;
for j=1:2*N
CkI(k)=CkI(k)+f(j)*sin(pi*(k-1)*t(j)/(dt*N));
CkR(k)=CkR(k)+f(j)*cos(pi*(k-1)*t(j)/(dt*N));
end
Ck(k)=(CkR(k)-CkI(k)*i)/(2*N);
R=real(Ck(k));
Im=imag(Ck(k));
end
Ck(N+1)=0;

Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis
for testing or instructional purposes only to students enrolled in courses for which the textbook
has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the
copyright owner is unlawful.
3

for j=1:2*N
Ck(N+1)=Ck(N+1)+f(j)*cos(pi*N*t(j)/(dt*N));
end
Ck(N+1)=Ck(N+1)/(4*N);
subplot(2,1,1)
stem(nuk,real(Ck),'oc')
xlabel('Frequency')
ylabel('Re(Ck)')
subplot(2,1,2)
stem(nuk,imag(Ck),'oc')
xlabel('Frequency')
ylabel('Im(Ck)')
end

(a) A program in a script file that solves the problem:

clear, clc
t=0:0.25:2;
fa=0:0.25:2;
Complex_DFT(t,fa);

When the file is executed the following figure is displaced:

Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis
for testing or instructional purposes only to students enrolled in courses for which the textbook
has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the
copyright owner is unlawful.
4

0.8

0.6
Re(Ck)

0.4

0.2

-0.2

-0.4
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Frequency

0.3

0.2

0.1
Im(Ck)

-0.1

-0.2
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Frequency

(b) A program in a script file that solves the problem:

clear, clc
t=0:0.25:2;
fb=[0 0.4375 0.75 0.9375 1 0.9375 0.75 0.4375];
Complex_DFT(t,fb);

When the file is executed the following figure is displaced:

Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis
for testing or instructional purposes only to students enrolled in courses for which the textbook
has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the
copyright owner is unlawful.
5

0.6

0.4
Re(Ck)

0.2

-0.2

-0.4
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Frequency

0.05

-0.05
Im(Ck)

-0.1

-0.15

-0.2
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Frequency

Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis
for testing or instructional purposes only to students enrolled in courses for which the textbook
has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the
copyright owner is unlawful.

You might also like