0% found this document useful (0 votes)
4 views2 pages

SN SLab 4 A1

The document outlines a MATLAB code for finding the trigonometric Fourier series coefficients (a0, an, bn) for the function y(t) = exp(t/2) over the interval [-pi, pi]. It includes instructions to plot the synthesized signal using the first 50 harmonics and to visualize the signal's buildup by adding each harmonic sequentially. The code computes the Fourier coefficients and generates plots to demonstrate the synthesis process.

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)
4 views2 pages

SN SLab 4 A1

The document outlines a MATLAB code for finding the trigonometric Fourier series coefficients (a0, an, bn) for the function y(t) = exp(t/2) over the interval [-pi, pi]. It includes instructions to plot the synthesized signal using the first 50 harmonics and to visualize the signal's buildup by adding each harmonic sequentially. The code computes the Fourier coefficients and generates plots to demonstrate the synthesis process.

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/ 2

Activity-1 (First Method):

Find the trigonometric Fourier series for y(t) shown below i.e. find ao, an, and bn and
substitute these Fourier coefficients in the synthesis expression of y(t).

a) Write a MATLAB code to plot that synthesis equation of y(t) by adding


first 50 harmonically related sinusoids.
b) You are also required to observe the synthesized signal by adding each simple
sinusoid harmonic starting from 1 till 50.

% Fourier Synthesis of y(t) = exp(t/2) in [-pi, pi] (numerical version)

clear; clc; close all;

% Parameters

T = 2*pi;

t_vals = linspace(-2*pi, 2*pi, 1000);

N = 50; % Total number of harmonics

% Compute a0

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

% Precompute an and bn

an_vals = zeros(1, N);

bn_vals = zeros(1, N);

for n = 1:N

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

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

end
%% a) Plot the synthesized y(t) using 50 harmonics

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

for n = 1:N

y_approx = y_approx + an_vals(n) * cos(n*t_vals) + bn_vals(n) * sin(n*t_vals);

end

figure;

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

title('Synthesized y(t) Using 50 Harmonics');

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

%% b) Show how signal builds up from 1 to 50 harmonics

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

figure;

for n = 1:N

y_step = y_step + an_vals(n) * cos(n*t_vals) + bn_vals(n) * sin(n*t_vals);

plot(t_vals, y_step, 'LineWidth', 1.2);

title(['y(t) synthesized with first ', num2str(n), ' harmonics']);

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

grid on;

pause(0.1); % Pause to observe each step

end

You might also like