0% found this document useful (0 votes)
12 views

Lab_01_Signal

The lab report details the manipulation of sinusoids using MATLAB, including generating time vectors, creating and plotting sinusoidal signals, and analyzing their statistics. It discusses the effects of sampling on the signals and provides theoretical calculations for phase and amplitude. The report concludes with a complex amplitude representation of the signals.

Uploaded by

azanetranclc17
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)
12 views

Lab_01_Signal

The lab report details the manipulation of sinusoids using MATLAB, including generating time vectors, creating and plotting sinusoidal signals, and analyzing their statistics. It discusses the effects of sampling on the signals and provides theoretical calculations for phase and amplitude. The report concludes with a complex amplitude representation of the signals.

Uploaded by

azanetranclc17
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/ 8

Lab Report 01: INTRODUCTION TO MATLAB

Tran Anh Vu - V202100569


Nguyen Nhat Minh - V202100
March 9, 2025

1 Manipulating Sinusoids with MATLAB


a
The following code is used to generate a time vector ( tt )

>> f = 4000
T = 1/f
st = T/25
tt = -T:st:T

1
b
A1 = 21; % My age
A2 = 1.2 * A1; % Given scaling factor
f = 4000; % Frequency in Hz
T = 1 / f; % Period
D = 17; % Day of birth
M = 9; % Month of birth
%% Compute time shifts
tm1 = (37.2 / M) * T;
tm2 = (-41.3 / D) * T;

%% Define time vector from -T to T


t = -T: 0.00001 :T;

%% Generate signals
x1t = A1 * cos(2 * pi * f * (t - tm1));
x2t = A2 * cos(2 * pi * f * (t - tm2));

%% Plot in subplots
figure;

subplot(3,1,1);
plot(t, x1t, ’b-’), grid on;
title(’Signal x_1(t)- Vu & Minh’);
xlabel(’Time (sec)’);
ylabel(’Amplitude’);

subplot(3,1,2);
plot(t, x2t, ’r--’), grid on;
title(’Signal x_2(t) - Vu & Minh’);
xlabel(’Time (sec)’);
ylabel(’Amplitude’);

%% Display both signals together in the third subplot


subplot(3,1,3);
plot(t, x1t, ’b-’, t, x2t, ’r--’), grid on;
title(’Comparison of x_1(t) and x_2(t) - Vu & Minh’);
xlabel(’Time (sec)’);
ylabel(’Amplitude’);
legend(’x_1(t)’, ’x_2(t)’);

2
c
x3t = x1t + x2t;

% Plot all signals using subplots


figure;

% Plot x1(t)
subplot(3,1,1);
plot(t, x1t, ’b-’), grid on;
title(’Signal x_1(t) - Vu & Minh’);
xlabel(’Time (sec)’);
ylabel(’Amplitude’);

% Plot x2(t)
subplot(3,1,2);
plot(t, x2t, ’r--’), grid on;
title(’Signal x_2(t) - Vu & Minh’);
xlabel(’Time (sec)’);
ylabel(’Amplitude’);

% Plot x3(t) = x1(t) + x2(t)


subplot(3,1,3);
plot(t, x3t, ’g-’), grid on;
title(’Sum of x_1(t) and x_2(t) - Vu & Minh’);
xlabel(’Time (sec)’);
ylabel(’Amplitude’);
legend(’x_3(t) = x_1(t) + x_2(t)’);

3
d
Ts = 0.5e-3; % Sampling interval = 0.5 ms = 0.0005 sec
fs = 1 / Ts;
t_sampled = -T:Ts:T;
x3_sampled = A1 * cos(2 * pi * f * (t_sampled - tm1)) +
A2 * cos(2 * pi * f * (t_sampled - tm2));

%% Plot both continuous and sampled signals


figure;
plot(t, x3t, ’b-’, ’LineWidth’, 1.5); % Continuous signal in blue
hold on;
stem(t_sampled, x3_sampled, ’ro’, ’MarkerSize’, 5, ’LineWidth’, 1.2);
% Sampled signal in red
grid on;
title(’Sampling Effect on x_3(t) - Vu & Minh’);
xlabel(’Time (sec)’);
ylabel(’Amplitude’);
legend(’Continuous x_3(t)’, ’Sampled x_3(t)’);
hold off;

4
e
% Compute statistics
max_x3 = max(x3t);
min_x3 = min(x3t);
mean_x3 = mean(x3t);
std_x3 = std(x3t);

%% Display results
fprintf(’Statistics of x3(t):\n’);
fprintf(’Maximum Value: %.4f\n’, max_x3);
fprintf(’Minimum Value: %.4f\n’, min_x3);
fprintf(’Mean Value: %.4f\n’, mean_x3);
fprintf(’Standard Deviation: %.4f\n’, std_x3);

The recorded results are:


1. Maximum Value: 9.8634
2. Minimum Value: -9.9414
3. Mean Value: -0.1708
4. Standard Deviation: 7.1346
From these results, we can see that:
• If max and min are close to A1 + A2 and −(A1 + A2 ), the two sinusoids are largely in-phase.
• If max is much less than A1 + A2 , the signals are partially out-of-phase.
• A near-zero mean confirms symmetry in the oscillation.
• Standard deviation gives a measure of energy distribution in the signal.

5
2 Theoretical Calcualtions
a
From the previous task, we got the result:
37.2 37.2 1
tm1 = ×T = × = 0.001033s
M 9 4000

−41.3 −41.3 1
tm2 = ×T = × = −0.000607s
D 17 4000
The phase of a signal xi (t) can be calculated by ϕ = 2πf tmi Therefore, by substituting tm1 and
tm2 into that equation, we found ϕ1 ≈ 8.267π; ϕ2 ≈ −4.859π, because ϕ is normally presented in range
[0, 2π] we can convert to ϕ1 ≈ 0.267π; ϕ2 ≈ 1.141π
Note that : ϕi here is in the formula xi (t) = Ai cos(2πf t − ϕi ) to avoid ambiguity in sign
of ϕ value

b
As we measured from the plot, the time-delay is t3 = 0.000105s, therefore the initial phase is ϕ3 =
2πf t3 = 2.6389π which has the similar meaning with ϕ3 = 0.6389π. Besides that, the amplitude of

6
x3 (t) is A3 ≈ 9.94

c
Consider two sinusoidal signals of the same angular frequency ω:

x1 (t) = A1 cos(ωt + ϕ1 )

x2 (t) = A2 cos(ωt + ϕ2 )
Using phasor representation, we express them as complex exponential:

X1 = A1 ejϕ1 , X2 = A2 ejϕ2
The total signal is:

x3 (t) = x1 (t) + x2 (t)


which corresponds to phasor addition:

X3 = X1 + X2 = A1 ejϕ1 + A2 ejϕ2
The resultant phasor X3 has magnitude and phase given by:
p
A3 = |X3 | = (A1 cos ϕ1 + A2 cos ϕ2 )2 + (A1 sin ϕ1 + A2 sin ϕ2 )2
 
−1 A1 sin ϕ1 + A2 sin ϕ2
ϕ3 = tan
A1 cos ϕ1 + A2 cos ϕ2
Substitute aforementioned values of A1 , A2 , ϕ1 , ϕ2 , we find A3 ≈ 9.974 and ϕ3 ≈ −0.8395π which
mean the time shift is t3calculated = ϕ3 /2πf ≈ 0.0001049s which is near the above observed result of
both amplitude and time-shift ( or phase).

7
3 Complex Amplitude
x1 (t) can be initialized by the following code:

x1t = real(21 * exp(1j * (2 * pi * 4000 * (tt - tm1))));

You might also like