0% found this document useful (0 votes)
3 views4 pages

SN SLab 4 A2

The document outlines a MATLAB procedure for calculating Fourier coefficients and synthesizing a signal using symbolic math. It details the integration process to find coefficients a0, an, and bn, and describes how to plot the synthesized signal using the first 50 harmonics. Additionally, it includes steps to compute and visualize the first 15 Fourier coefficients along with a table displaying their values.

Uploaded by

shaheer0ii70s
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)
3 views4 pages

SN SLab 4 A2

The document outlines a MATLAB procedure for calculating Fourier coefficients and synthesizing a signal using symbolic math. It details the integration process to find coefficients a0, an, and bn, and describes how to plot the synthesized signal using the first 50 harmonics. Additionally, it includes steps to compute and visualize the first 15 Fourier coefficients along with a table displaying their values.

Uploaded by

shaheer0ii70s
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/ 4

Activity-2 (Second Method):

a) Use symbolic math of MATLAB, perform integration to find ao, an, and bn.
b) Plot the synthesized signal y(t) by adding first 50 sinusoidal harmonics.
c) Also compute and plot the first 15 Fourier coefficients an, bn, Cn, and 𝜽𝒏 in a single
Figure window. Make a table of 5 columns n, an, bn, Cn, and 𝜽𝒏 to show the
computed values.

a) Use MATLAB symbolic toolbox:

syms t n real

y = exp(t/2);

T = 2*pi;

% a0 coefficient

a0 = (1/T) * int(y, t, -pi, pi);

b) an
% Plot synthesized signal using first 50 harmonics
coefficient
We=can
an numerically
(1/pi) compute
* int(y * cos(n*t), thepi);
t, -pi, harmonics and sum them:

% Define time vector


% bn coefficient
t_vals = linspace(-2*pi, 2*pi, 1000);
bn = (1/pi)=*zeros(size(t_vals));
y_approx int(y * sin(n*t), t, -pi, pi);

T = 2*pi;

N = 50;
% Compute a0 numerically

a0_val = double((1/T) * integral(@(t) exp(t/2), -pi, pi));

% Initialize y(t)

y_approx = a0_val / 2 * ones(size(t_vals));

% Add harmonics

for n = 1:N

an_val = (1/pi) * integral(@(t) exp(t/2) .* cos(n*t), -pi, pi);

bn_val = (1/pi) * integral(@(t) exp(t/2) .* sin(n*t), -pi, pi);

y_approx = y_approx + an_val * cos(n*t_vals) + bn_val * sin(n*t_vals);

end

% Plot synthesized signal

figure;

plot(t_vals, y_approx, 'LineWidth', 1.5);

title('Synthesized Signal y(t) with 50 Harmonics');

xlabel('t'); ylabel('y(t)');

grid on;

c) Compute and plot first 15 coefficients: an, bn, Cn, θn

N_coeff = 15;

a_n = zeros(1, N_coeff);

b_n = zeros(1, N_coeff);

C_n = zeros(1, N_coeff);

theta_n = zeros(1, N_coeff);


for n = 1:N_coeff

a_n(n) = (1/pi) * integral(@(t) exp(t/2) .* cos(n*t), -pi, pi);

b_n(n) = (1/pi) * integral(@(t) exp(t/2) .* sin(n*t), -pi, pi);

C_n(n) = sqrt(a_n(n)^2 + b_n(n)^2);

theta_n(n) = atan2(-b_n(n), a_n(n));

end

n_vals = 1:N_coeff;

% Plotting

figure;

subplot(2,2,1); stem(n_vals, a_n, 'filled'); title('a_n'); xlabel('n'); ylabel('a_n'); grid on;

subplot(2,2,2); stem(n_vals, b_n, 'filled'); title('b_n'); xlabel('n'); ylabel('b_n'); grid on;

subplot(2,2,3); stem(n_vals, C_n, 'filled'); title('C_n'); xlabel('n'); ylabel('C_n'); grid on;

subplot(2,2,4); stem(n_vals, theta_n, 'filled'); title('\theta_n'); xlabel('n'); ylabel('\theta_n


(rad)'); grid on;

d) Table of First 15 Coefficients

T_data = table((1:N_coeff)', a_n', b_n', C_n', theta_n', ...

'VariableNames', {'n', 'a_n', 'b_n', 'C_n', 'theta_n'});

disp(T_data);

You might also like