MATLAB Assignment for ENG3104: MIMO System and Curve Fitting
VerifiedAdded on 2022/09/11
|21
|2613
|18
Homework Assignment
AI Summary
This MATLAB assignment addresses three key problems in engineering simulations and computations. The first question focuses on analyzing a MIMO Wi-Fi system, determining the correct transformation matrix using MATLAB code and matrix operations. The second problem involves curve fitting, specifically applying the exponential model to experimental data of vapor pressure at varying temperatures, and comparing theoretical and MATLAB-generated coefficients. The final part explores interpolation techniques (linear, spline, and pchip) to estimate dry-unit weight based on water content, with extrapolation methods also being used to determine the water content at a specific dry unit weight, all using MATLAB. The assignment includes detailed MATLAB code, outputs, and plots to illustrate the solutions and analysis.

Running head: MATLAB ASSIGNMENT
MATLAB ASSIGNMENT
Name of the Student
Name of the University
Author Note
MATLAB ASSIGNMENT
Name of the Student
Name of the University
Author Note
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

1MATLAB ASSIGNMENT
Question 1:
The MIMO Wi-Fi system is given by the following transformation method.
^X =WX
Here, X = original information.
W = transformation matrix
^X =¿ Transmitted signal
Now, given original first information and received signals are
X = [ 1
−1 ] and ^X = [ 0
−1+i ]
The potential transformation matrixes are
W 1 = 1
√ 2 [ 1 1
e0 −e0 ], W 2 = 1
√ 2 [ 1 1
e
iπ
4 −e
iπ
4 ], W 3 = 1
√2 [ 1 1
e
iπ
2 −e
iπ
2 ], W 4 = 1
√2 [ 1 1
e
3iπ
4 −e
3 iπ
4 ]
The second signal is
^X =
[ 3.56
−2.13+1.08 i ]
The first signal of ^X = [ 0
−1+i ]
Hence, [ 0
−1+i ]=W∗[ 1
−1 ]
Now, as the matrixes are not square matrix except W hence, matrix inversion cannot be
applied here. Thus the W is determined by multiplying W1, W2, W3 and W4 with X in
sequence.
Now, W1*X gives,
Question 1:
The MIMO Wi-Fi system is given by the following transformation method.
^X =WX
Here, X = original information.
W = transformation matrix
^X =¿ Transmitted signal
Now, given original first information and received signals are
X = [ 1
−1 ] and ^X = [ 0
−1+i ]
The potential transformation matrixes are
W 1 = 1
√ 2 [ 1 1
e0 −e0 ], W 2 = 1
√ 2 [ 1 1
e
iπ
4 −e
iπ
4 ], W 3 = 1
√2 [ 1 1
e
iπ
2 −e
iπ
2 ], W 4 = 1
√2 [ 1 1
e
3iπ
4 −e
3 iπ
4 ]
The second signal is
^X =
[ 3.56
−2.13+1.08 i ]
The first signal of ^X = [ 0
−1+i ]
Hence, [ 0
−1+i ]=W∗[ 1
−1 ]
Now, as the matrixes are not square matrix except W hence, matrix inversion cannot be
applied here. Thus the W is determined by multiplying W1, W2, W3 and W4 with X in
sequence.
Now, W1*X gives,

2MATLAB ASSIGNMENT
1
√2 [ 1 1
e0 −e0 ]∗[ 1
−1 ] = 1
√ 2 [ 0
1+1 ] = [ 0
√ 2 ]
Again, W2*X gives,
1
√ 2 [ 1 1
e
iπ
4 −e
iπ
4 ]∗
[ 1
−1 ] = 1
√ 2 [ 0
2 ei π
4 ]= [ 0
1+i ]
Now, W3*X gives,
1
√ 2 [ 1 1
e
iπ
2 −e
iπ
2 ]∗
[ 1
−1 ] = 1
√ 2 [ 0
2 ei π
2 ] = [ 0
0+ √ 2i ]
Again, W4*X gives,
1
√2 [ 1 1
e
3iπ
4 −e
3 iπ
4 ]∗
[ 1
−1 ]= 1
√2 [ 0
2e
3 iπ
4 ] = [ 0
−1+1i ]
Hence, the right transformation matrix that produces the correct X based on given ^X is
W 4= 1
√2 [ 1 1
e
3 iπ
4 −e
3 iπ
4 ]
Now, the second value of X for receiving a second signal ^X =
[ 3.56
−2.13+1.08 i ] is determined
by the following method.
Let, X = [ a
b ]
Hence, by equality
[ 3.56
−2.13+1.08 i ] = 1
√ 2 [ 1 1
e
3 iπ
4 −e
3 iπ
4 ] [ a
b ]
3.56 = a/ √ 2 + b/√2 (1)
1
√2 [ 1 1
e0 −e0 ]∗[ 1
−1 ] = 1
√ 2 [ 0
1+1 ] = [ 0
√ 2 ]
Again, W2*X gives,
1
√ 2 [ 1 1
e
iπ
4 −e
iπ
4 ]∗
[ 1
−1 ] = 1
√ 2 [ 0
2 ei π
4 ]= [ 0
1+i ]
Now, W3*X gives,
1
√ 2 [ 1 1
e
iπ
2 −e
iπ
2 ]∗
[ 1
−1 ] = 1
√ 2 [ 0
2 ei π
2 ] = [ 0
0+ √ 2i ]
Again, W4*X gives,
1
√2 [ 1 1
e
3iπ
4 −e
3 iπ
4 ]∗
[ 1
−1 ]= 1
√2 [ 0
2e
3 iπ
4 ] = [ 0
−1+1i ]
Hence, the right transformation matrix that produces the correct X based on given ^X is
W 4= 1
√2 [ 1 1
e
3 iπ
4 −e
3 iπ
4 ]
Now, the second value of X for receiving a second signal ^X =
[ 3.56
−2.13+1.08 i ] is determined
by the following method.
Let, X = [ a
b ]
Hence, by equality
[ 3.56
−2.13+1.08 i ] = 1
√ 2 [ 1 1
e
3 iπ
4 −e
3 iπ
4 ] [ a
b ]
3.56 = a/ √ 2 + b/√2 (1)
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

3MATLAB ASSIGNMENT
And −2.13+1.08 i = a
√ 2 e
3 iπ
4 - b e
3 iπ
4
√2
(2)
Now, solving equation (1) and (2) gives
a = 4.1223 + 0.525i
b = 0.9123 – 0.525i
Hence, X = [ 4.1223+0.525 i
0.9123 – 0.525 i ]
Now, the values of correct choice of W and second value of X is calculated in MATLAB as
given below.
MATLAB code:
% different transformaiton matrixes
W1 = (1/sqrt(2)).*[1,1;exp(0),-exp(0)];
W2 = (1/sqrt(2)).*[1,1;exp(1i*(pi/4)),-exp(1i*(pi/4))];
W3 = (1/sqrt(2)).*[1,1;exp(1i*(pi/2)),-exp(1i*(pi/2))];
W4 = (1/sqrt(2)).*[1,1;exp(1i*(3*pi/4)),-exp(1i*(3*pi/4))];
X = [1;-1];
% Transmitted signals for different W
Xhat1 = W1*X
Xhat2 = W2*X
Xhat3 = W3*X
Xhat4 = W4*X
And −2.13+1.08 i = a
√ 2 e
3 iπ
4 - b e
3 iπ
4
√2
(2)
Now, solving equation (1) and (2) gives
a = 4.1223 + 0.525i
b = 0.9123 – 0.525i
Hence, X = [ 4.1223+0.525 i
0.9123 – 0.525 i ]
Now, the values of correct choice of W and second value of X is calculated in MATLAB as
given below.
MATLAB code:
% different transformaiton matrixes
W1 = (1/sqrt(2)).*[1,1;exp(0),-exp(0)];
W2 = (1/sqrt(2)).*[1,1;exp(1i*(pi/4)),-exp(1i*(pi/4))];
W3 = (1/sqrt(2)).*[1,1;exp(1i*(pi/2)),-exp(1i*(pi/2))];
W4 = (1/sqrt(2)).*[1,1;exp(1i*(3*pi/4)),-exp(1i*(3*pi/4))];
X = [1;-1];
% Transmitted signals for different W
Xhat1 = W1*X
Xhat2 = W2*X
Xhat3 = W3*X
Xhat4 = W4*X
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

4MATLAB ASSIGNMENT
fprintf('Thus the correct choice of transformation matrix is:\n')
W4
% finding second signal
Xhat= [3.56;-2.13+1i*1.08];
X = W4\Xhat
Output:
Xhat1 =
0
1.4142
Xhat2 =
0.0000 + 0.0000i
1.0000 + 1.0000i
Xhat3 =
0.0000 + 0.0000i
0.0000 + 1.4142i
Xhat4 =
0.0000 + 0.0000i
-1.0000 + 1.0000i
Thus the correct choice of transformation matrix is:
W4 =
fprintf('Thus the correct choice of transformation matrix is:\n')
W4
% finding second signal
Xhat= [3.56;-2.13+1i*1.08];
X = W4\Xhat
Output:
Xhat1 =
0
1.4142
Xhat2 =
0.0000 + 0.0000i
1.0000 + 1.0000i
Xhat3 =
0.0000 + 0.0000i
0.0000 + 1.4142i
Xhat4 =
0.0000 + 0.0000i
-1.0000 + 1.0000i
Thus the correct choice of transformation matrix is:
W4 =

5MATLAB ASSIGNMENT
0.7071 + 0.0000i 0.7071 + 0.0000i
-0.5000 + 0.5000i 0.5000 - 0.5000i
X =
4.1223 + 0.5250i
0.9123 - 0.5250i
Question 2:
Now, the first two entries of temperature and pressure in the file ‘makeupass2q2_in.txt’ are
T1 = 273 K and P1 = 0.6 kPa.
T2 = 278 K and P2 = 0.9066 kPa.
Now, putting the values in the following equation
p= A∗e
B
T
0.6 = A* e
B
273
=> ln(0.6) = ln(A) + (B/273) (1)
0.9066 = A* e
B
278
=> ln(0.9066) = ln(A) + (B/278) (2)
Now, (1) – (2) gives
(B/273) - (B/278) = ln(0.6/0.9066)
6.588e-5B = -0.4128
B = -0.4128/6.588e-5 = -6265.4
Hence, A = exp(ln(0.6) + (6265.4/273)) = 1.9e8.
0.7071 + 0.0000i 0.7071 + 0.0000i
-0.5000 + 0.5000i 0.5000 - 0.5000i
X =
4.1223 + 0.5250i
0.9123 - 0.5250i
Question 2:
Now, the first two entries of temperature and pressure in the file ‘makeupass2q2_in.txt’ are
T1 = 273 K and P1 = 0.6 kPa.
T2 = 278 K and P2 = 0.9066 kPa.
Now, putting the values in the following equation
p= A∗e
B
T
0.6 = A* e
B
273
=> ln(0.6) = ln(A) + (B/273) (1)
0.9066 = A* e
B
278
=> ln(0.9066) = ln(A) + (B/278) (2)
Now, (1) – (2) gives
(B/273) - (B/278) = ln(0.6/0.9066)
6.588e-5B = -0.4128
B = -0.4128/6.588e-5 = -6265.4
Hence, A = exp(ln(0.6) + (6265.4/273)) = 1.9e8.
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

6MATLAB ASSIGNMENT
Now, in MATLAB all the data is used to find the coefficients A and B and the error is fitting is
reported. Further the curve fitting is performed with first two entries of given data and coefficients
obtained with the results of theoretical calculation.
MATLAB code:
%% Curving fitting with entire data of makeupass2q2_in.txt
load('makeupass2q2_in.txt')
% printing first 5 values
fprintf('The first 5 entries are: \n')
makeupass2q2_in(1:5,1:2)
temp = makeupass2q2_in(:,1);
vp = makeupass2q2_in(:,2);
x0 = [1 1];
fitfun = fittype('A*exp(B/x)');
[fitted_curve,gof] = fit(temp,vp,fitfun,'StartPoint',x0);
A = fitted_curve.A; B = fitted_curve.B;
figure(1)
scatter(temp, vp, 'r+')
hold on
grid on
plot(temp,fitted_curve(temp))
title('Curve fitted with all data entries')
Now, in MATLAB all the data is used to find the coefficients A and B and the error is fitting is
reported. Further the curve fitting is performed with first two entries of given data and coefficients
obtained with the results of theoretical calculation.
MATLAB code:
%% Curving fitting with entire data of makeupass2q2_in.txt
load('makeupass2q2_in.txt')
% printing first 5 values
fprintf('The first 5 entries are: \n')
makeupass2q2_in(1:5,1:2)
temp = makeupass2q2_in(:,1);
vp = makeupass2q2_in(:,2);
x0 = [1 1];
fitfun = fittype('A*exp(B/x)');
[fitted_curve,gof] = fit(temp,vp,fitfun,'StartPoint',x0);
A = fitted_curve.A; B = fitted_curve.B;
figure(1)
scatter(temp, vp, 'r+')
hold on
grid on
plot(temp,fitted_curve(temp))
title('Curve fitted with all data entries')
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

7MATLAB ASSIGNMENT
xlabel('Temperature in K')
ylabel('Vapour pressure in kPa')
hold off
fprintf('The fitted coefficients are A = %.2f and B = %.2f\n',A,B)
fprintf('%.2f percent of variation in the data is explained by the model p = A*exp(B/T) \
n',100*gof.rsquare)
fprintf('Root mean square error in the model = %.4f\n',gof.rmse)
%% Curve fitting with first two entries of makeupass2q2_in.txt
temp2 = temp(1:2);
vp2 = vp(1:2);
x0 = [1 1];
fitfun = fittype('A*exp(B/x)');
[fitted_curve,gof] = fit(temp2,vp2,fitfun,'StartPoint',x0);
A = fitted_curve.A; B = fitted_curve.B;
figure(2)
scatter(temp, vp, 'r+')
hold on
grid on
plot(temp,fitted_curve(temp))
title('Curve fitted with first two data entries')
xlabel('Temperature in K')
ylabel('Vapour pressure in kPa')
hold off
fprintf('The fitted coefficients are A = %.2f and B = %.2f\n',A,B)
fprintf('%.2f percent of variation in the data is explained by the model p = A*exp(B/T) \
n',100*gof.rsquare)
fprintf('Root mean square error in the model = %.4f\n',gof.rmse)
%% Curve fitting with first two entries of makeupass2q2_in.txt
temp2 = temp(1:2);
vp2 = vp(1:2);
x0 = [1 1];
fitfun = fittype('A*exp(B/x)');
[fitted_curve,gof] = fit(temp2,vp2,fitfun,'StartPoint',x0);
A = fitted_curve.A; B = fitted_curve.B;
figure(2)
scatter(temp, vp, 'r+')
hold on
grid on
plot(temp,fitted_curve(temp))
title('Curve fitted with first two data entries')

8MATLAB ASSIGNMENT
xlabel('Temperature in K')
ylabel('Vapour pressure in kPa')
fprintf('\n\nThe fitted coefficients are A = %.2f and B = %.2f\n',A,B)
fprintf('Required values of vapour pressure at given temperatures are: \n')
fitted_curve(temp)
Output:
The first 5 entries are:
ans =
273.0000 0.6000
278.0000 0.9066
283.0000 1.2132
288.0000 1.7332
293.0000 2.3198
The fitted coefficients are A = 199243738.55 and B = -5349.16
99.94 percent of variation in the data is explained by the model p = A*exp(B/T)
Root mean square error in the model = 0.0271
The fitted coefficients are A = 10156828.54 and B = -4523.61
Required values of vapour pressure at given temperatures are:
xlabel('Temperature in K')
ylabel('Vapour pressure in kPa')
fprintf('\n\nThe fitted coefficients are A = %.2f and B = %.2f\n',A,B)
fprintf('Required values of vapour pressure at given temperatures are: \n')
fitted_curve(temp)
Output:
The first 5 entries are:
ans =
273.0000 0.6000
278.0000 0.9066
283.0000 1.2132
288.0000 1.7332
293.0000 2.3198
The fitted coefficients are A = 199243738.55 and B = -5349.16
99.94 percent of variation in the data is explained by the model p = A*exp(B/T)
Root mean square error in the model = 0.0271
The fitted coefficients are A = 10156828.54 and B = -4523.61
Required values of vapour pressure at given temperatures are:
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

9MATLAB ASSIGNMENT
ans =
0.6464
0.8708
1.1609
1.5322
2.0031
2.5954
Plots:
270 275 280 285 290 295 300
Temperature in K
0.5
1
1.5
2
2.5
3
3.5
Vapour pressure in kPa
Curve fitted with all data entries
ans =
0.6464
0.8708
1.1609
1.5322
2.0031
2.5954
Plots:
270 275 280 285 290 295 300
Temperature in K
0.5
1
1.5
2
2.5
3
3.5
Vapour pressure in kPa
Curve fitted with all data entries
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

10MATLAB ASSIGNMENT
270 275 280 285 290 295 300
Temperature in K
0.5
1
1.5
2
2.5
3
3.5
Vapour pressure in kPa
Curve fitted with first two data entries
It can be seen that the value of A and B by curve fitting method in MATLAB with first two data
entries are approximately equal to the theoretical calculation. The small mismatch between values of
estimated coefficients A and B exists because of the approximation in theoretical calculation.
The required values of vapour pressure of water in kPa such that it follows exactly the model
A*exp(B/T) are given in the output of MATLAB as given above.
Question 3:
Part a)
In this task the optimum value of water content w that gives the largest value of dry-unit weight is
found by three interpolation methods in MATLAB.
The value (the value at w = 9.5%) can also be found by hand with linear interpolation as below.
Interpolation is performed between the points (8,110.7) and (10,117.06) as this contains the point w =
9.5%.
270 275 280 285 290 295 300
Temperature in K
0.5
1
1.5
2
2.5
3
3.5
Vapour pressure in kPa
Curve fitted with first two data entries
It can be seen that the value of A and B by curve fitting method in MATLAB with first two data
entries are approximately equal to the theoretical calculation. The small mismatch between values of
estimated coefficients A and B exists because of the approximation in theoretical calculation.
The required values of vapour pressure of water in kPa such that it follows exactly the model
A*exp(B/T) are given in the output of MATLAB as given above.
Question 3:
Part a)
In this task the optimum value of water content w that gives the largest value of dry-unit weight is
found by three interpolation methods in MATLAB.
The value (the value at w = 9.5%) can also be found by hand with linear interpolation as below.
Interpolation is performed between the points (8,110.7) and (10,117.06) as this contains the point w =
9.5%.

11MATLAB ASSIGNMENT
γd = y 0+ y 1− y 0
x 1−x 0 ∗(x−x 0)
γd =110.7+ (117.06−110.7)
(10−8) ∗(9.5−8) = 115.47 lb
f t3
Now, linear, spline and pchip interpolation is performed in MATLAB as given below.
MATLAB code:
w = [0,2,4,6,8,10,12,14];
gammad = [80.85,82.93,90.61,100.88,110.7,117.06,116.94,107.30];
%% verification of result at w = 9.5 percent
query = 9.5; % query point is 9.5
gammadquery = interp1(w,gammad,query); % gammad at weight w = 9.5
fprintf('The dry unit weight at water content w = %.2f percent is %.2f lb/ft^3 \n',query,gammadquery)
%% linear interpolation
query = min(w):0.1:max(w);
gammadquery = interp1(w,gammad,query);
maxgammad = max(gammadquery);
maxindex = find(gammadquery==maxgammad);
figure(1)
plot(query,gammadquery,'-',w,gammad,'.',query(maxindex),maxgammad,'o')
xlabel('Water content percent by weight')
ylabel('Dry unit weight in lb/ft^3')
γd = y 0+ y 1− y 0
x 1−x 0 ∗(x−x 0)
γd =110.7+ (117.06−110.7)
(10−8) ∗(9.5−8) = 115.47 lb
f t3
Now, linear, spline and pchip interpolation is performed in MATLAB as given below.
MATLAB code:
w = [0,2,4,6,8,10,12,14];
gammad = [80.85,82.93,90.61,100.88,110.7,117.06,116.94,107.30];
%% verification of result at w = 9.5 percent
query = 9.5; % query point is 9.5
gammadquery = interp1(w,gammad,query); % gammad at weight w = 9.5
fprintf('The dry unit weight at water content w = %.2f percent is %.2f lb/ft^3 \n',query,gammadquery)
%% linear interpolation
query = min(w):0.1:max(w);
gammadquery = interp1(w,gammad,query);
maxgammad = max(gammadquery);
maxindex = find(gammadquery==maxgammad);
figure(1)
plot(query,gammadquery,'-',w,gammad,'.',query(maxindex),maxgammad,'o')
xlabel('Water content percent by weight')
ylabel('Dry unit weight in lb/ft^3')
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide
1 out of 21
Your All-in-One AI-Powered Toolkit for Academic Success.
+13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
Copyright © 2020–2025 A2Z Services. All Rights Reserved. Developed and managed by ZUCOL.