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

Signals and Systems Lab - Assignment2

lab assignment for signals and system

Uploaded by

hajermmjaber55
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Signals and Systems Lab - Assignment2

lab assignment for signals and system

Uploaded by

hajermmjaber55
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

ELEC 351 Signals and Systems

Lab Exercise # 2
Date 23.11.202

Name Student ID Participation


Percentage
Alya Yousef 202106180 [50 %]
Hajer Jaber 201708749 [50 %]

Grading Rubric
Completeness of the report Grading
scheme
Organization of the report 10%
Clear PDF, with cover sheet, answers are in the same order
as questions in the assignment, copies of the questions
Quality of figures 10%
Correctly labeled with title, x-axis, y-axis, and name(s)
Understanding of the questions and provide a complete 80%
answers

Note: solve the following questions using either MATLAB or python.


1- Given the following periodic signal: (2.5 Marks)

1
A) Calculate the Fourier series coefficients 𝐶𝑘 for the given signal mathematically then write down
the Fourier series expansion 𝑥(𝑡).

2
3
B) Verify your solution using Matlab by showing the magnitude and phase plots.

clear ,clc;
figure(1);
n=10; %Number of Terms of FS
k=-n:n; %Summation from -n to n
ck=((exp(2)-1)./(2*(1-(k.*pi.*1i))));
ak(n+1)=((exp(2)/2)-(1/2))-1;
subplot 121
stem(k,abs(ck),"LineWidth",1.5);grid;xlabel('t');ylabel('x(t)');%plot ampletude
title('The magnitude Spectrum','FontSize',11)
xlabel('frequency')
ylabel('|Ck|')
subplot 122
P=angle(ck);stem(k,P,'LineWidth',1.5);grid;xlabel('t');ylabel('x(t)');%plot Phase
title('The Phase Spectrum','FontSize',11)
xlabel('frequency')
ylabel('theata')

4
2- Given the following periodic signal with a period T: (2.5 Marks)
𝑓(𝑡) = 2𝑗 − 4sin (100𝜋𝑡 − 40) − 10 cos (60𝜋𝑡 + 𝜋 − 70)
a) Find the period 𝑇 and the fundamental frequency 𝑓𝑜

Solve the problem mathematically to find the exponential Fourier series then:

5
b) Use Matlab to plot the one sided spectrum.

clear ,clc;
figure(1);
f=[0 30 50];
A=[2 5 2];
subplot 121
stem(f,A,"LineWidth",2);%plot ampletude
title('The magnitude Spectrum','FontSize',11)
xlabel('frequency')
ylabel('Magnitude')
subplot 122
angle=[90 -70 50];
stem(f,angle,'LineWidth',1.5);%plot Phase
title('The Phase Spectrum','FontSize',11)
xlabel('frequency')
ylabel('theata')

c) Use Matlab to plot the double sided spectrum.

clear ,clc;
figure(1);
f=[-50 -30 0 30 50];
A=[2 5 2 5 2];
subplot 121
stem(f,A,"LineWidth",2);%plot ampletude
title('The magnitude Spectrum','FontSize',11)
xlabel('frequency')
ylabel('Magnitude')

6
subplot 122
angle=[-50 70 90 -70 50];
stem(f,angle,'LineWidth',1.5);%plot Phase
title('The Phase Spectrum','FontSize',11)
xlabel('frequency')
ylabel('theata')

d) Find the power of the signal.

7
3- Suppose that a signal 𝑥(𝑡)is given by 𝑥(𝑡) = 𝑡𝑒 −3𝑡 𝑢(𝑡). Compute the Fourier Transform 𝑋(𝜔) of
the signal and plot for X-axis is −20 ≤ 𝜔 ≤ 20 𝑟𝑎𝑑/𝑠𝑒𝑐. (2.5 Marks)
a- The Magnitude of 𝑋(𝜔)
b- The Phase of 𝑋(𝜔)
c- Calculate the inverse Fourier transform of 𝑋(𝜔)

% Define time and sampling parameters


t = -2:0.01:2-0.01; % Time vector from -2 to 2 seconds, step size of 0.01
fs = 400; % Sampling frequency of 400 Hz
x = sinc(t); % Signal x(t) = sinc(t)

% Compute the FFT of the signal and normalize by L


L = length(x); % Length of the signal
X = fft(x) / L; % Fourier transform (normalized)

% Shift the zero frequency component to the center


X_shifted = fftshift(X);

% Define the frequency axis


frequency_axis = fs * (-L/2 : L/2 - 1) / L;

% Compute the inverse FFT to recover the original signal


X_inverse = ifft(X, 'symmetric') * fs; % Correct syntax for inverse FFT

% Plotting the results


figure;

% Plot the original signal x(t)


subplot(3,1,1);
plot(t, x);
title('x(t)');
xlabel('t (s)');
grid on;

% Plot the magnitude of X(w)


subplot(3,1,2);
plot(frequency_axis, abs(X_shifted));
title('Magnitude of X(\omega)');
xlabel('f (Hz)');
grid on;

% Plot the phase of X(w)


subplot(3,1,3);
plot(frequency_axis, angle(X_shifted));
title('Phase of X(\omega)');
xlabel('f (Hz)');
grid on;

8
9
4- Use Matlab to plot the spectrum of the following two signals: (2.5 Marks)
sin(𝜋𝑡)
a- 𝑥(𝑡) = 𝜋𝑡
1 −1≤𝑡 ≤1
b- 𝑦(𝑡) = {
0 𝑒𝑙𝑠𝑒

a)
% Define time and sampling parameters
t = -2:0.01:2-0.01; % Time vector from -2 to 2 seconds, step size of 0.01
fs = 400; % Sampling frequency of 400 Hz
x = sinc(t); % Signal x(t) = sinc(t)

% Compute the FFT of the signal and normalize by L


L = length(x); % Length of the signal
X = fft(x) / L; % Fourier transform (normalized)

% Shift the zero frequency component to the center


X_shifted = fftshift(X);

% Define the frequency axis


frequency_axis = fs * (-L/2 : L/2 - 1) / L;

% Compute the inverse FFT to recover the original signal


X_inverse = ifft(X, 'symmetric') * fs; % Correct syntax for inverse FFT

% Plotting the results


figure;

% Plot the original signal x(t)


subplot(3,1,1);
plot(t, x);
title('x(t)');
xlabel('t (s)');
grid on;

% Plot the magnitude of X(w)


subplot(3,1,2);
plot(frequency_axis, abs(X_shifted));
10
title('Magnitude of X(\omega)');
xlabel('f (Hz)');
grid on;

% Plot the phase of X(w)


subplot(3,1,3);
plot(frequency_axis, angle(X_shifted));
title('Phase of X(\omega)');
xlabel('f (Hz)');
grid on;

% Define time and sampling parameters


t = -2:0.01:2-0.01; % Time vector from -2 to 2 seconds
fs = 400; % Sampling frequency (Hz)

% Define the rectangular pulse signal y(t)


y = 1 * (t >= -1 & t <= 1); % Pulse from -1 to 1

% Compute the FFT of the signal and normalize by L


L = length(y); % Length of the signal
Y = fft(y) / L; % Fourier transform (normalized)

% Shift the zero frequency component to the center


Y_shifted = fftshift(Y);

% Define the frequency axis


frequency_axis = fs * (-L/2 : L/2 - 1) /L;

% Plotting the results


11
figure;

% Plot the original signal y(t)


subplot(3,1,1);
plot(t, y);
title('y(t)');
xlabel('t (s)');
grid on;

% Plot the magnitude of Y(w)


subplot(3,1,2);
plot(frequency_axis, abs(Y_shifted));
title('Magnitude of Y(\omega)');
xlabel('f (Hz)');
grid on;

% Plot the phase of Y(w)


subplot(3,1,3);
plot(frequency_axis, angle(Y_shifted));
title('Phase of Y(\omega)');
xlabel('f (Hz)');
grid on;

12

You might also like