You are on page 1of 9

4 Warmup: Complex Exponentials

4.1 M-file to Generate a Sinusoid

Write a function that will generate a single sinusoid, x(t) = Acos(!t+_), by using four input arguments: amplitude
(A), frequency (!), phase (_) and duration (dur). The function should return two outputs: the values of the
sinusoidal signal (x) and corresponding times (t) at which the sinusoid values are known. Make sure that the
function
generates 20 values of the sinusoid per period. Call this function one cos(). Hint: use goodcos() from part
(a) as a starting point.
Demonstrate that your one cos() function works by plotting the output for the following parameters: A = 95,
! = 200_ rad/sec, _ = _/5 radians, and dur = 0.025 seconds. Be prepared to explain to the lab instructor features
on the plot that indicate how the plot has the correct period and phase. What is the expected period in millisec?
Instructor Verification (separate page)

Sol:

function one_cos(f,A,dur,theta)
tt=-dur:1/(100*f):dur;
xx=A * cos (2*pi*f*tt+theta);
plot(tt,xx),grid on
end

In the Matlab bage


>> one cos (50,95,0.025, pi/5)

figure 2.1 the period is 0.02 and Amplitude is 95 and phase is pi/5 or tm equals -0.002 Generate wave

4.2.1 Write the Function of (syn_sin)

Testing:

[xx,tt]= syn_sin([0,100,250], [10,14*exp(-j*pi/3), 8*j], 10000, 0.1,0); period?

sol:

function [xx,tt]=syn_sin(fk,xk,fs,dur,tstart)
if nargin <5, tstart=0, end
if length (xk)~=length (fk)
error ('error', ' fk~=xk');
end
t= tstart: 1/(fs):dur;
x=xk(1)* exp(2*j*pi*fk(1)*t);
for k=2: length(fk);
x=xk(k) *exp(2*j*pi*fk(k)*t)+x;
end
plot(t,x),grid on

Write statement in the matlab page

>> syn_sin([0,100,250], [10,14*exp(-j*pi/3), 8*j], 10000, 0.1,0);

T= 0.057-0.037= 0.02 f=1/0.02= 50;

figure 2.2 the sum signals are nearly periodic

5 Lab Exercise: Representation of Sinusoids with Complex Exponentials

In MATLAB consult help on exp, real and imag. Be aware that you can also use the DSP First function zprint
to print the polar and rectangular forms of any vector of complex numbers.

(a) Generate the signal x(t) = Ɍe{2ej_t + 2ej_(t − 1.25) + (1 − j)ej_t} and make a plot versus t. Use the
syn_sin function and take a range for t that will cover three periods starting at t = −1 to 2 secs. Include
the MATLAB code with your report.

Sol:

Therefore f=0.5 , T=2, testart=-0.5, dur= 2*3+0.5=6.5 sec;


function [xx,tt]=syn_sin(fk,xk,fs,dur,tstart)
if nargin <5, tstart=0, end
if length (xk)~=length (fk)
error ('error', ' fk~=xk');
end
t= tstart: 1/(fs):dur;
x=xk(1)* exp(2*j*pi*fk(1)*t);
for k=2: length(fk);
x=xk(k) *exp(2*j*pi*fk(k)*t)+x;
end
plot(t,x),grid on

>>syn_sin([0.5, 0.5, 0.5, 0.5], [2,2*exp(-j*pi*1.25), 1, -1*exp(j*pi/2)], 1000, 6.5,-0.5);


figure 2.3 The sum signals will give f=0.5 , T=2, testart=-0.5, dur= 6.5 sec

(b)From the plot of x(t) versus t, measure the frequency, phase and amplitude of the sinusoidal signal by hand.
Show annotations on the plots to indicate how these measurements were made and what the values are.
Compare to the calculation in part (c).
Sol:

figure 2.4 this annotation by cosine wave

X(t)= 2*exp(j*pi*t)+ 2*exp( j*pi*t- j*pi*1.25 )+ exp( j*pi*t )- exp( j*pi*t + j*pi/2 )
X(t)=exp( j*pi*t ) [ 2 + 2*exp( -j*pi*1.25 )+1- exp(j*pi/2) ]
X(t)= [ 2+ 2<-225 +1 – j ]
X(t)= [ 3+1.4+j1.4-j]
= [1.6+j0.4]=1.6<14
X(t)= 1.6* cos(2*pi* 0.5 * t +7*pi/90 )

(c) Use the phasor addition theorem and MATLAB to determine the magnitude and phase of x(t).

>> x=2+2*exp(-j*pi*1.25)+1-exp(j*pi/2)

x =1.5858 + 0.4142i

>> abs(x)

ans =1.6390

>> angle(x)
ans = 0.2555 ( this phase in radian) (in degree 0.2555*180/pi=14)

>> zvect([2, 2*exp(-j*pi*1.25),1, -exp(j*pi/2)],'mag'),grid on

figure 2.5 Phaser addition by using[ zvect([2, 2*exp(-j*pi*1.25),1, -exp(j*pi/2)],'mag'),grid on]

figure 2.6 Phaser addition by using >>zcat([2, 2*exp(-j*pi*1.25),1, -exp(j*pi/2)],'mag'),grid on


phase Shift = 180o
Velocity of
Propagation = c
(velocity of light)
DIRECT PATH
REFLECTED PATH
(dxr,dyr)
signals from two sources: the transmitter and a reflector located at (dxr, dyr).
are themselves delayed versions of the transmitted signal, s(t).
(a) The amount of the delay (in seconds) can be computed for both propagation paths. First of all, consider the
direct path. The time delay is the distance divided by the speed of light (3 × 108 m/s). Write a mathematical
expression for the time delay in terms of the vehicle position xv and the transmitter location (0, dt). Call this
delay time t1 and express it as a function of xv, i.e., t1(xv).
Sol:

d1= sqrt(xv2+dt2)
t1=d1/c = (sqrt(xv2+dt2))/(3*108) sec

(b) Now write a mathematical formula for the time delay of the signal that travels the reflected path from the
transmitter at (0, dt) to the reflector at (dxr, dyr) and then to the vehicle at (xv, 0). Call this delay time t2 and make
sure that you also express it as a function of xv, i.e., t2(xv). In this case, you must add together two delays:
transmitter to reflector and then reflector to vehicle.
sol:

d2=sqrt [(dt-dyr)2+dxr2] + sqrt [(dxr-xv)2+dyr2].


t2= d2/c = (sqrt [(dt-dyr)2+dxr2] + sqrt[(dxr-xv)2+dyr2])/3*108.

(c) The received signal at the vehicle, rv(t), is the sum of the two delayed copies of the transmitter signal rv(t) = s(t
− t1) − s(t − t2)
where s(·) is the transmitted signal, and the minus sign accounts for fact that the reflection reverses the phase of
the reflected signal.3 Assume that the source signal s(t) is a zero-phase unit-amplitude sinusoid at frequency f0 =
150 MHz; and also assume that the transmitter is located at (0, 1500) meters and the reflector at (100, 900)
meters. Then the received signal is the sum of two sinusoids. Make a plot of rv(t) when the vehicle position is xv =
0 meters. Plot 3 periods of rv(t) and then measure its maximum amplitude.
sol:

dt=1500; dxr= 100; dyr= 900;


if xv=0;
d1=sqrt( (0)2 + (1500)2) = 1500;
t1=1500/(3*108 ) = 5*10-6 sec.
d2=sqrt[(1500-900)2+1002] - sqrt[(100-0)2+9002]= 608.28-905.5= -297.22 m
t2= d2/c= -297.22/3*108 = - 0.99*10-6 sec.
rv(t)= cos (2 pi f (t-5*10-6 ) ) - cos (2 pi f (t+0.99*10-6) )

rv(t)= cos (wt-1500 pi ) - cos (wt + 297 pi )

rv(t)= exp(-j*pi*1500)- exp( j*pi*297 )= 1.0000 + 0.0000i – (-1.0000 + 0.0000i) = 2.0000 + 0.0000i

f=150000000;
dur=0.00000002;
t=0:1/(1000000*f):dur;
subplot(311);
r=cos(2*pi*f*t-1500*pi)-cos(2*pi*f*t+297*pi);
plot(t,r), grid on
subplot(312);
k=cos(2*pi*f*t-1500*pi);
plot(t,k), grid on
subplot(313);
l=cos(2*pi*f*t+297*pi);
plot(t,l), grid on
(d) Repeat the work in part (c), but use the complex amplitudes instead. Explain how a single complex addition,
followed by a magnitude operation can be used to find the amplitude of rv(t).

sol:
rv(t)= cos (2 pi f (t-5*10-6 ) ) - cos (2 pi f (t+0.99*10-6) )

rv(t)= cos (wt-1500 pi ) - cos (wt + 297 pi )

rv(t)= exp(-j*pi*1500)- exp( j*pi*297 )= 1.0000 + 0.0000i – (-1.0000 + 0.0000i) = 2.0000 + 0.0000i

figure 2.9 this is the complex amplitudes phasor of receiver signal rv(t)

(e) Our aim in the rest of this lab is to make a plot of signal strength versus vehicle position (xv). One approach
would be to repeat the process in part (c) for every position, i.e., generate the resultant sinusoid and measure its
amplitude. However, that would be a huge waste of computation. Instead, the complex amplitude approach in
part (d) is a much more efficient method. Derive a mathematical expression for complex amplitudes of each
delayed sinusoid as a function of position xv. Then write a MATLAB program that will generate the time delays,
form the complex amplitudes, and then add
the complex amplitudes. Have the MATLAB program loop through the entire set of vehicle positions specified in
part (f) below. Include this MATLAB code in your report and explain how it works. Vectorization: It is likely that
your previous programming skills would lead you to write a loop to do this implementation. The loop would run
over all possible values of xv, and would add the two complex amplitudes calculated at each xv. However, there is
a much more efficient way in MATLAB, if you think in terms of vectors (which are really lists of numbers). In the
vector strategy, you would make a vector containing all the vehicle positions; then do the distance and time delay
calculations to generate a vector of time delays; next, a vector of complex amplitudes would be formed. In each of
these calculations, only one line of code is needed and no loops. You need two vectors of complex amplitudes
(one for the direct path and the other for the reflected path), so the whole process is done twice and then you can
perform a vector add of the two complex amplitudes.
sol:
function xx=dis(xv)
f=150000000;
c=300000000;
dt=1500;
dyr=900;
dxr=100;
t1(xv)= sqrt(xv^2+dt^2);
if xv>100
t2(xv)=[ sqrt((dt-dyr)^2+dxr^2)+sqrt((dxr-xv)^2+dyr^2)]/c;
else
t2(xv)=[ sqrt((dt-dyr)^2+dxr^2)-sqrt((dxr-xv)^2+dyr^2)]/c;
end
t=0:1/(f*1000000):0.00000002;
r=cos( 2*pi*f*t-2*pi*t1(xv))- cos ( 2*pi*f*t-2*pi*t2(xv));
plot(t,r),grid on
end

this is function allow any position of xv enter after that it will generate sinusoid and time delays. For example if I
write
>>dis (60)
it will give me sinusoid and the time delays for the receiver path signal.

figure 2.9 this diagram describe the receiver signal if the position of vehicle is 60 meters
(f) Utilize the MATLAB program from the previous part to generate a plot of signal strength versus vehicle
position, xv, over the interval from 0 meters to +300 meters. Assume that signal strength is defined to be the peak
value of the received sinusoid, rv(t). State how you get the peak value from the complex amplitude.
sol:
peak value is tm that can be calculated by w and theta.
tm = - theta / w.
>>dis(300)
this function generate signal if the distance 300 meters for vehicle so from the signal we can know the peak
value which is highest value that signal reach
figure 2.10 the recever signal when the xv 300 meters

(g) Explain your results from the previous part. In particular, what are the largest and smallest values of received
signal strength? Why do we get those values? Are there vehicle positions where we get complete signal
cancellation? If so, determine those vehicle positions.
sol:

the amplitude will be decreased when the position of the vehicle start increase. The strengths points vehicle will
be received at 0 till 100meters which this is reflected point after that the signal starts to become weak .

You might also like