MATLAB with comments

1 answer below »
MATLAB with comments


ECE 3300 MATLAB Assignment 2 This assignment (1) demonstrates how to work with complex-valued signals and periodic signals in MATLAB, and (2) shows how to obtain energy, power, correlation, and mean-square error. Complex Numbers and Complex-Valued Lists a=3+4j sets a to the complex number 3 + 4j. Complex numbers can be used in lists; an example is b=[3-4j,3j,-4]. abs(x) computes the magnitude, angle(x) finds the phase (in radians), conj(x) takes the complex conjugate, real(x) determines the real part, and imag(x) obtains the imaginary part (excluding the j). Each of these commands can be used on lists; for example, if b is as defined above, abs(b) equals [5,3,4], angle(b) equals [-0.9273 1.5708 3.1416], conj(b) equals [3+4j,-3j,-4], real(b) equals [3,0,-4], and imag(b) equals [-4,3,0]. Rounding Numbers The command round(t) rounds t to the nearest integer. If t is exactly between two integers, it rounds up to the higher integer. round can be used on lists; for example, if t=[-2 -1.4 -0.8 -0.2 0.4 1.0 1.6 2.2], round(t)=[-2 -1 -1 0 0 1 2 2]. Similarly, the command ceil(t) rounds t up to the next higher integer, and the command floor(t) rounds t down to the next lower integer. Both of these commands can also be used on lists. For the example of t above, ceil(t)=[-2 -1 0 0 1 1 2 3] and floor(t)=[-2 -2 -1 -1 0 1 1 2]. Periodic Signals Suppose x̃(t) is a periodic signal with fundamental period T0 and fundamental cycle x(t) and define y(t) = x(t − T0r(t/T0)), where r(·) is the function round(·). Then we claim that y(t) equals x̃(t). To prove this result we need to show two facts: (1) y(t) has fundamental cycle x(t). (2) y(t) is periodic with fundamental period T0. To prove (1), we note that −T0/2 ≤ t < t0/2="" implies="" that="" −="" 12="" ≤="" t/t0="">< 1="" 2="" ;="" simply="" divide="" each="" term="" in="" the="" first="" inequality="" by="" t0="" to="" see="" this.="" it="" follows="" that="" r(t/t0)="0," and="" thus,="" for="" −t0/2="" ≤="" t="">< t0/2,="" y(t)="x(t" −="" t0r(t/t0))="x(t)." to="" prove="" (2),="" we="" first="" note="" that="" r(t−="" 1)="r(t)−" 1.="" (to="" see="" this,="" note="" that="" r(5.8−="" 1)="r(4.8)" =="" 5="6−" 1="r(5.8)−" 1.)="" it="" follows="" that="" y(t−="" t0)="x(t−" t0="" −="" t0r(="" t−t0t0="" ))="x(t−" t0="" −="" t0(r(="" tt0="" −="" 1)))="x(t−" t0="" −="" t0(r(="" tt0="" )−="" 1))="x(t−" t0="" −="" t0r(="" tt0="" )="" +="" t0)="x(t−" t0r(="" tt0="" ))="y(t)" thus="" we="" conclude="" that="" x̃(t)="x(t" −="" t0r(t/t0)).="" we="" can="" write="" this="" as="" x̃(t)="x(tper)" where="" tper="t−" t0r(t/t0).="" to="" apply="" this="" result="" to="" matlab,="" suppose="" we="" wish="" to="" implement="" a="" periodic="" signal="" x̃(t)="" with="" t0="2" and="" fundamental="" cycle="" x(t)="t" 2(u(t)−u(t−1))="" using="" a="" sampling="" time="" of="" 0.01.="" further="" sup-="" pose="" we="" wish="" to="" represent="" x̃(t)="" over="" ten="" periods,="" from="" t="−10" to="" 10.="" we="" first="" set="" t="-10:0.01:10" and="" t="" per="t-2.*round(t./2)." next="" we="" set="" x="t" per.^2.*((t="" per="">=0)&(t per<1)). the="" peri-="" odic="" signal="" from="" t="−10" to="" t="10" is="" represented="" by="" t="" and="" x.="" to="" prevent="" roundoff="" issues,="" t0="" should="" be="" an="" integer="" multiple="" of="" the="" sampling="" time.="" discrete-time="" periodic="" signals="" are="" defined="" similarly="" except="" the="" the="" time="" values="" are="" integers.="" for="" example,="" suppose="" n0="7" and="" x[n]="n+3" 2="" (u[n="" +="" 2]="" −="" u[n="" −="" 3]),="" and="" we="" wish="" to="" repre-="" sent="" x̃[n]="" from="" n="−50" to="" n="50." we="" use="" the="" following="" matlab="" commands:="" n="-50:50," n="" per="n-7.*round(n./7)," and="" x="(n" per+3)./2.*((n="" per="">=-2)&(n per<=2)); the signal is rep- 1 resented from n = −50 to n = 50 by n and x. problem statement: part one consider (1) the periodic signals x̃(t) and ỹ(t), each with fundamental period t0 = 10, and with fundamental cycles x(t) = (9− t2) sin(πt)(u(t+ 3)− u(t− 3)) and y(t) = (9− t2) cos(πt)(u(t+ 3)− u(t− 3)). also consider the non-periodic signal z(t) = x(t) + jy(t) where x(t) and y(t) are as defined in the previous sentence. in everything below use a sampling time of 0.01. 1. plot x̃(t) from t = −15 to t = 15. 2. plot ddt ỹ(t) from t = −15 to t = 15. 3. plot |z(t)| from t = −15 to t = 15. 4. plot ∠z(t) from t = −15 to t = 15. energy of discrete-time signals suppose the signal x[n] is defined over the range a ≤ n ≤ c. then the energy is given by ex = ∑c n=a |x[n]|2. if x[n] is represented in matlab via n=a:c and x, the energy can be determined via sum(abs(x).^2). correlation and mean-square error of discrete-time signals suppose the signals x[n] and y[n] are both defined over the range a ≤ n ≤ c. then the cor- relation is given by rx,y = ∑c n=a x[n]y ∗[n] and the mean-square error is given by msex,y =∑c n=a |x[n]− y[n]|2. if x[n] and y[n] are represented in matlab via n=a:c, x, and y, the cor- relation can be determined via sum(x.*conj(y)), and the mean-square error can be obtained via sum(abs(x-y).^2). energy of continuous-time signals suppose the signal x(t) is defined over the range a ≤ t ≤ c. then the energy is given by ex = ∫ c a |x(t)|2dt. we can approximate the integral as the sum of the areas of a bunch of rectangles; the ith such rectangle has width b and height |x(a+ (i− 1)b)|2. because the area of a rectangle is the product of its width and height, it follows that, if c = a+ kb, ex = ∫ c a |x(t)|2dt = ∫ a+kb a |x(t)|2dt ≈ k∑ i=1 |x(a+ (i− 1)b)|2b thus, if the sampling time is b, and if x(t) is represented in matlab by t=a:b:c and x, then ex can be approximated by sum(abs(x).^2).*b. correlation and mean-square error of continuous-time signals suppose the signals x(t) and y(t) are defined over the range a ≤ t ≤ c. then the correlation and mean-square error are given by rx,y = ∫ c a x(t)y∗(t)dt and msex,y = ∫ c a |x(t) − y(t)|2dt. approximating the integrals as the sum of the areas of rectangles, we have rx,y = ∫ c a x(t)y∗(t)dt = ∫ a+kb a x(t)y∗(t)dt ≈ k∑ i=1 x(a+ (i− 1)b)y∗(a+ (i− 1)b)b and msex,y = ∫ c a |x(t)− y(t)|2dt = ∫ a+kb a |x(t)− y(t)|2dt ≈ k∑ i=1 |x(a+ (i− 1)b)− y(a+ (i− 1)b)|2b 2 thus, if the sampling time is b, and if x(t) and y(t) are represented in matlab by t=a:b:c, x, and y, then rx,y can be approximated by sum(x.*conj(y)).*b and msex,y can be approxi- mated by sum(abs(x-y).^2).*b. periodic signals for periodic signals, the power, correlation, and mean-square error can be obtained from the energy, correlation, and mean-square error of the signals’ corresponding fundamental cycles by simply dividing the quantity by the fundamental period. the following table summarizes the results assuming the starting signal is implemented via n=a:c (if discrete time) or t=a:b:c (if continuous time) and x. quantity equation t or n matlab ex ∑∞ n=−∞ |x[n]|2 n=a:c sum(abs(x).^2) ex ∫∞ −∞ |x(t)| 2dt t=a:b:c sum(abs(x).^2).*b rx,y ∑∞ n=−∞ x[n]y ∗[n] n=a:c sum(x.*conj(y)) rx,y ∫∞ −∞ x(t)y ∗(t)dt t=a:b:c sum(x.*conj(y)).*b msex,y ∑∞ n=−∞ |x[n]− y[n]|2 n=a:c sum(abs(x-y).^2) msex,y ∫∞ −∞ |x(t)− y(t)| 2dt t=a:b:c sum(abs(x-y).^2).*b problem statement: part two consider the non-periodic signals x(t) = (9−t2) sin(πt)(u(t+3)−u(t−3)) and y(t) = sin(πt)(u(t+ 3) − u(t − 3)). in everything below use a sampling time of 0.01. for each part, print out the value of the indicated quantities, including the name of each quantity with the corresponding value. 1. determine ex, ey, rx,y, and ρx,y. 2. determine msex,y two ways – by the direct formula, and by using the equation ex +ey− 2re{rx,y}. 3. determine the percentage of energy in x(t) in the time interval −1 ≤ t ≤ 1. also determine the percentage of energy in y(t) in this same time interval. 3 the="" signal="" is="" rep-="" 1="" resented="" from="" n="−50" to="" n="50" by="" n="" and="" x.="" problem="" statement:="" part="" one="" consider="" (1)="" the="" periodic="" signals="" x̃(t)="" and="" ỹ(t),="" each="" with="" fundamental="" period="" t0="10," and="" with="" fundamental="" cycles="" x(t)="(9−" t2)="" sin(πt)(u(t+="" 3)−="" u(t−="" 3))="" and="" y(t)="(9−" t2)="" cos(πt)(u(t+="" 3)−="" u(t−="" 3)).="" also="" consider="" the="" non-periodic="" signal="" z(t)="x(t)" +="" jy(t)="" where="" x(t)="" and="" y(t)="" are="" as="" defined="" in="" the="" previous="" sentence.="" in="" everything="" below="" use="" a="" sampling="" time="" of="" 0.01.="" 1.="" plot="" x̃(t)="" from="" t="−15" to="" t="15." 2.="" plot="" ddt="" ỹ(t)="" from="" t="−15" to="" t="15." 3.="" plot="" |z(t)|="" from="" t="−15" to="" t="15." 4.="" plot="" ∠z(t)="" from="" t="−15" to="" t="15." energy="" of="" discrete-time="" signals="" suppose="" the="" signal="" x[n]="" is="" defined="" over="" the="" range="" a="" ≤="" n="" ≤="" c.="" then="" the="" energy="" is="" given="" by="" ex="∑c" n="a" |x[n]|2.="" if="" x[n]="" is="" represented="" in="" matlab="" via="" n="a:c" and="" x,="" the="" energy="" can="" be="" determined="" via="" sum(abs(x).^2).="" correlation="" and="" mean-square="" error="" of="" discrete-time="" signals="" suppose="" the="" signals="" x[n]="" and="" y[n]="" are="" both="" defined="" over="" the="" range="" a="" ≤="" n="" ≤="" c.="" then="" the="" cor-="" relation="" is="" given="" by="" rx,y="∑c" n="a" x[n]y="" ∗[n]="" and="" the="" mean-square="" error="" is="" given="" by="" msex,y="∑c" n="a" |x[n]−="" y[n]|2.="" if="" x[n]="" and="" y[n]="" are="" represented="" in="" matlab="" via="" n="a:c," x,="" and="" y,="" the="" cor-="" relation="" can="" be="" determined="" via="" sum(x.*conj(y)),="" and="" the="" mean-square="" error="" can="" be="" obtained="" via="" sum(abs(x-y).^2).="" energy="" of="" continuous-time="" signals="" suppose="" the="" signal="" x(t)="" is="" defined="" over="" the="" range="" a="" ≤="" t="" ≤="" c.="" then="" the="" energy="" is="" given="" by="" ex="∫" c="" a="" |x(t)|2dt.="" we="" can="" approximate="" the="" integral="" as="" the="" sum="" of="" the="" areas="" of="" a="" bunch="" of="" rectangles;="" the="" ith="" such="" rectangle="" has="" width="" b="" and="" height="" |x(a+="" (i−="" 1)b)|2.="" because="" the="" area="" of="" a="" rectangle="" is="" the="" product="" of="" its="" width="" and="" height,="" it="" follows="" that,="" if="" c="a+" kb,="" ex="∫" c="" a="" |x(t)|2dt="∫" a+kb="" a="" |x(t)|2dt="" ≈="" k∑="" i="1" |x(a+="" (i−="" 1)b)|2b="" thus,="" if="" the="" sampling="" time="" is="" b,="" and="" if="" x(t)="" is="" represented="" in="" matlab="" by="" t="a:b:c" and="" x,="" then="" ex="" can="" be="" approximated="" by="" sum(abs(x).^2).*b.="" correlation="" and="" mean-square="" error="" of="" continuous-time="" signals="" suppose="" the="" signals="" x(t)="" and="" y(t)="" are="" defined="" over="" the="" range="" a="" ≤="" t="" ≤="" c.="" then="" the="" correlation="" and="" mean-square="" error="" are="" given="" by="" rx,y="∫" c="" a="" x(t)y∗(t)dt="" and="" msex,y="∫" c="" a="" |x(t)="" −="" y(t)|2dt.="" approximating="" the="" integrals="" as="" the="" sum="" of="" the="" areas="" of="" rectangles,="" we="" have="" rx,y="∫" c="" a="" x(t)y∗(t)dt="∫" a+kb="" a="" x(t)y∗(t)dt="" ≈="" k∑="" i="1" x(a+="" (i−="" 1)b)y∗(a+="" (i−="" 1)b)b="" and="" msex,y="∫" c="" a="" |x(t)−="" y(t)|2dt="∫" a+kb="" a="" |x(t)−="" y(t)|2dt="" ≈="" k∑="" i="1" |x(a+="" (i−="" 1)b)−="" y(a+="" (i−="" 1)b)|2b="" 2="" thus,="" if="" the="" sampling="" time="" is="" b,="" and="" if="" x(t)="" and="" y(t)="" are="" represented="" in="" matlab="" by="" t="a:b:c," x,="" and="" y,="" then="" rx,y="" can="" be="" approximated="" by="" sum(x.*conj(y)).*b="" and="" msex,y="" can="" be="" approxi-="" mated="" by="" sum(abs(x-y).^2).*b.="" periodic="" signals="" for="" periodic="" signals,="" the="" power,="" correlation,="" and="" mean-square="" error="" can="" be="" obtained="" from="" the="" energy,="" correlation,="" and="" mean-square="" error="" of="" the="" signals’="" corresponding="" fundamental="" cycles="" by="" simply="" dividing="" the="" quantity="" by="" the="" fundamental="" period.="" the="" following="" table="" summarizes="" the="" results="" assuming="" the="" starting="" signal="" is="" implemented="" via="" n="a:c" (if="" discrete="" time)="" or="" t="a:b:c" (if="" continuous="" time)="" and="" x.="" quantity="" equation="" t="" or="" n="" matlab="" ex="" ∑∞="" n="−∞" |x[n]|2="" n="a:c" sum(abs(x).^2)="" ex="" ∫∞="" −∞="" |x(t)|="" 2dt="" t="a:b:c" sum(abs(x).^2).*b="" rx,y="" ∑∞="" n="−∞" x[n]y="" ∗[n]="" n="a:c" sum(x.*conj(y))="" rx,y="" ∫∞="" −∞="" x(t)y="" ∗(t)dt="" t="a:b:c" sum(x.*conj(y)).*b="" msex,y="" ∑∞="" n="−∞" |x[n]−="" y[n]|2="" n="a:c" sum(abs(x-y).^2)="" msex,y="" ∫∞="" −∞="" |x(t)−="" y(t)|="" 2dt="" t="a:b:c" sum(abs(x-y).^2).*b="" problem="" statement:="" part="" two="" consider="" the="" non-periodic="" signals="" x(t)="(9−t2)" sin(πt)(u(t+3)−u(t−3))="" and="" y(t)="sin(πt)(u(t+" 3)="" −="" u(t="" −="" 3)).="" in="" everything="" below="" use="" a="" sampling="" time="" of="" 0.01.="" for="" each="" part,="" print="" out="" the="" value="" of="" the="" indicated="" quantities,="" including="" the="" name="" of="" each="" quantity="" with="" the="" corresponding="" value.="" 1.="" determine="" ex,="" ey,="" rx,y,="" and="" ρx,y.="" 2.="" determine="" msex,y="" two="" ways="" –="" by="" the="" direct="" formula,="" and="" by="" using="" the="" equation="" ex="" +ey−="" 2re{rx,y}.="" 3.="" determine="" the="" percentage="" of="" energy="" in="" x(t)="" in="" the="" time="" interval="" −1="" ≤="" t="" ≤="" 1.="" also="" determine="" the="" percentage="" of="" energy="" in="" y(t)="" in="" this="" same="" time="" interval.="">
Answered 1 days AfterSep 26, 2022

Answer To: MATLAB with comments

Baljit answered on Sep 27 2022
19 Votes
Part one
1. Plot (t) from t = −15 to t = 15
Matlab Code:-
%part-1
clc
clear all
close all
t=-15
:0.01:15; % t=-15 to 15
t_per=t-10.*round(t./10) %T=10
x=(9-t_per.^2).*sin(pi.*t_per).*((t_pe
=-3)&( t_pe
=3)); %x(t_per)
plot(t_per,x) %to plot x(t_per)
title('x')
ylabel('x')
xlabel('t')
Plot:-
2. Plot from t = −15 to t = 15
Matlab Code:-
%part 2
clc
clear all
close all
t=-15:0.01:15; %t=-15 to 15
t_per=t-10.*round(t./10) %T=10
y=(9-t_per.^2).*cos(pi.*t_per).*((t_pe
=-3)&( t_pe
=3)); %y(t_per)
Y=diff(y); %derivative of y(t)
plot(Y)
title('dy/dt')
ylabel('dy/dt')
xlabel(' ')
title('dy/dt')
ylabel('dy/dt')
xlabel(' ')
Plot:-
3. Plot |z(t)| from t = −15 to t = 15
Matlab Code:-
%part 3
clc
clear all
close all
t=-15:0.01:15;
z=(9-t.^2).*sin(pi.*t).*((t>=-3)&(t<=3))+1i*((9-t.^2).*cos(pi.*t).*((t>=-3)&(t<=3)))%z(t)
plot(t,abs(z)) %plot magnitude of z with time t
title('Magnitude of z(t)')
ylabel('|z(t)|')
xlabel('t')
Plot:-
4. Plot ∠z(t) from t = −15 to t = 15
Matlab...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here