1
7.17 Write a MATLAB user-defined function that samples a function that is given in an analytical form.
Name the function [t,f] = Sampling(Fun,tau,dt). The input argument Fun is a name for the function
that is being sampled (it is a dummy name for the function that is imported into Sampling), tau is the
time interval over which the continuous function is prescribed, where the starting time is 0 and the final
time equals the value tau, and dt is the spacing between the sampled points. The output arguments t and
f are vectors with the values of the independent and dependent variables of the sampled function, respec-
tively.
Use Sampling to sample the following function over an interval of 10 ms and spacing of 10 μ s.
5 2 5 2 4 2
– 10 ( t – 0.005 ) – 10 ( t – 0.005 ) – 10 ( t – 0.005 )
f ( t ) = 0.5 sin ( 2πνt )e + sin ( 4πνt )e + 0.2 sin ( 6πνt )e
4 2 4 2
– 10 ( t – 0.005 ) – 10 ( t – 0.005 )
+ 0.1 sin ( 8πνt )e + 0.1 sin ( 10πνt )e
where ν = 554.365 Hz. Make a plot of the sampled points.
Solution
The user-defined function Sampling:
function [t,f]=Sampling(Fun,tau,dt)
t=0:dt:tau;
for i=1:length(t)
f(i)=Fun(t(i));
end
A program in a script file that solves the problem:
clear, clc
v=554.365;
pv=pi*v;
ti=0.005;
foft= @ (t) 0.5*sin(2*pv*t)*exp(-1E5*(t-ti)^2)+sin(4*pv*t)*exp(-1E5*(t-
ti)^2)...
+0.2*sin(6*pv*t)*exp(-1E4*(t-ti)^2)+0.1*sin(8*pv*t)*exp(-1E4*(t-ti)^2)...
+0.1*sin(10*pv*t)*exp(-1E5*(t-ti)^2);
[t,f]=Sampling(foft,10E-3,10E-6);
plot(t,f)
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
xlabel('t')
ylabel('f(t)')
t=0:0.25:2;
fa=0:0.25:2;
Complex_DFT(t,fa);
When the file is executed the following figure is displaced:
1.5
0.5
f(t)
-0.5
-1
-1.5
0 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01
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.