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

MATLAB Assignment-Fourier Series and Fourier Transforms

The document outlines an assignment for the course 21MAB201T – Transforms and Boundary Value Problems at SRM Institute of Science and Technology, requiring students to use MATLAB to find Fourier series and transforms for specified functions. Students must execute the problems, take outputs with their login details, and submit both soft and hard copies by 21.10.24. Specific instructions are provided for modifying the functions using the student's register number.

Uploaded by

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

MATLAB Assignment-Fourier Series and Fourier Transforms

The document outlines an assignment for the course 21MAB201T – Transforms and Boundary Value Problems at SRM Institute of Science and Technology, requiring students to use MATLAB to find Fourier series and transforms for specified functions. Students must execute the problems, take outputs with their login details, and submit both soft and hard copies by 21.10.24. Specific instructions are provided for modifying the functions using the student's register number.

Uploaded by

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

SRM Institute of Science and Technology

Tiruchirappalli Campus

Faculty of Engineering and Technology


School of Sciences, Division of Mathematics

21MAB201T – Transforms and Boundary Value Problems


16.10.2024
Assignment using MATLAB
Instruction: Execute the following problems in your MATLAB login and
take the output with your login details. Submit it on or before 21.10.24 as
Soft copy (Screen shot with your login name) and also submit a hard copy.
Example: 1
1.Find the Fourier series of 𝑓 (𝑥 ) = 𝑥 + 𝑥 2 in (– 𝜋, 𝜋) of periodicity 2𝜋, by using
MATLAB.
% Define the function and interval
syms x n;
f = x + x^2;

% Calculate a_0
a0 = (1/(2*pi)) * int(f, x, -pi, pi);

% Calculate a_n
an = (1/pi) * int(f * cos(n*x), x, -pi, pi);

% Calculate b_n
bn = (1/pi) * int(f * sin(n*x), x, -pi, pi);

% Display the results


disp('Fourier Coefficient a0:');
disp(a0);
disp('Fourier Coefficient an:');
disp(an);
disp('Fourier Coefficient bn:');
disp(bn);
% Compute the Fourier series (up to a finite number of terms)
N = 10; % Number of terms in the Fourier series
x_vals = linspace(-pi, pi, 1000);
fs = double(a0); % Start with a0

for k = 1:N
fs = fs + double(subs(an, n, k)) * cos(k*x_vals) + double(subs(bn, n, k)) *
sin(k*x_vals);
end

% Plotting the original function and its Fourier series approximation


figure;
hold on;
f_vals = double(subs(f, x, x_vals));
plot(x_vals, f_vals, 'r', 'DisplayName', 'Original Function f(x) = x + x^2');
plot(x_vals, fs, 'b--', 'DisplayName', 'Fourier Series Approximation');
legend;
title('Fourier Series Approximation of f(x) = x + x^2');
xlabel('x');
ylabel('Function Value');
grid on;

Solution & Output


Exercise Problems:

1.Find the Fourier series of 𝒇(𝒙) = 𝒙 + 𝒙 𝑹 in (– 𝜋, 𝜋) of periodicity 2𝜋, by using MATLAB.


2.Find the Fourier series of 𝒇(𝒙) = 𝑹 𝒙 + 𝒄𝒐𝒔(𝑹 𝒙) in (– 𝜋, 𝜋)of periodicity 2π, by using
MATLAB.

Note:
 In the place of R use your register number and submit the output.
 Only change the function in the respective places in the given MATLAB Code.
 You can login with your srmist mail id.
SRM Institute of Science and Technology
Tiruchirappalli Campus

Faculty of Engineering and Technology


School of Sciences, Division of Mathematics

21MAB201T – Transforms and Boundary Value Problems


16.10.2024
Assignment using MATLAB
Instruction: Execute the Problem 1 and 2 in your MATLAB login and take
the output with your login details. Submit it on or before 21.10.24 as Soft
copy (Screen shot with your login name) and also submit a hard copy.
Example: 1
Find the Fourier Transform for the function 𝑓(𝑡 ) = cos(2𝜋𝑓0 𝑡).
% Parameters
fs = 1000; % Sampling frequency
t = 0:1/fs:1; % Time vector
f0 = 5; % Frequency of sine wave
% Cos wave
f = cos (2 * pi * f0 * t);
% Number of samples
N = length(f);
% Compute the Fourier Transform with normalization
F = (1/sqrt(2*pi)) * fft(f);
f_shifted = fftshift(F); % Shift zero frequency component to center
frequencies = linspace(-fs/2, fs/2, N); % Frequency vector
% Plotting
figure;
subplot(2, 1, 1);
plot(t, f);
title('Time Domain Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(2, 1, 2);
plot(frequencies, abs(f_shifted));
title('Magnitude Spectrum (Normalized)');
xlabel('Frequency (Hz)');
ylabel('|F(f)|');
Solution & Output

Exercise Problems:
1. Find the Fourier Transform for the function f(t)= sin (R*pi*f0*t), by using MATLAB.

2. Find the Fourier Transform for the function f(t)=exp (R*pi*f0*t), by using MATLAB.

Note:
 In the place of R use your register number and submit the output.
 Only change the function in the respective places in the given MATLAB Code.

You might also like