Ss ia-3
1) Write a MATLAB script to create a transfer function representation of a
lineartime-invariant system and then plot its step response.
Program:
% Define the transfer function numerator and denominator coefficients
numerator_coefficients = [1]; % Adjust as needed
denominator_coefficients = [1, 2, 1]; % Adjust as needed
% Create the transfer function
sys = tf(numerator_coefficients, denominator_coefficients);
% Plot the step response
figure;
step(sys);
title('Step Response of the LTI System');
xlabel('Time');
ylabel('Amplitude');
grid on;
Output:
2)Find the trigonometric fourier series representation of a periodic square wave
x(t) = 1, for the interval (0 , pi). Write matlab program
% Parameters
T = pi; % Period of the square wave
t = linspace(0, T, 1000); % Time vector
% Square wave function for one period
x_t_periodic = ones(size(t));
% Fourier series coefficients
a_0 = (1/T) * trapz(t, x_t_periodic);
n_max = 10; % Number of harmonics
a_n = zeros(1, n_max);
b_n = zeros(1, n_max);
for n = 1:n_max
    % Compute coefficients
    a_n(n) = (2/T) * trapz(t, x_t_periodic .* cos(n * 2 * pi / T * t));
    b_n(n) = (2/T) * trapz(t, x_t_periodic .* sin(n * 2 * pi / T * t));
end
% Trigonometric Fourier series
x_t_fourier = a_0/2;
for n = 1:n_max
    x_t_fourier = x_t_fourier + a_n(n) * cos(n * 2 * pi / T * t) + b_n(n) * sin(n *
2 * pi / T * t);
end
% Plot the original square wave and its Fourier series approximation
figure;
plot(t, x_t_periodic, 'b', 'LineWidth', 2, 'DisplayName', 'Original Square Wave');
hold on;
plot(t, x_t_fourier, 'r--', 'LineWidth', 1.5, 'DisplayName', 'Fourier Series
Approximation');
title('Trigonometric Fourier Series of a Square Wave');
xlabel('Time (t)');
ylabel('Amplitude');
legend('show');
grid on;
Output:
3) Find the trigonometric fourier series for half wave rectified sine wave.
% Parameters
T = pi; % Period of the half-wave rectified sine wave
t = linspace(0, T, 1000); % Time vector
% Original sine wave
x_t_sine = sin(t);
% Half-wave rectification
x_t_rectified = x_t_sine .* (t >= 0 & t <= pi);
% Fourier series coefficients
a_0 = (2/T) * integral(@(t) sin(t), 0, pi);
n_max = 10; % Number of harmonics
a_n = zeros(1, n_max);
b_n = zeros(1, n_max);
for n = 1:n_max
    a_n(n) = (2/T) * integral(@(t) sin(t) .* cos(n * t), 0, pi);
    b_n(n) = (2/T) * integral(@(t) sin(t) .* sin(n * t), 0, pi);
end
% Trigonometric Fourier series
x_t_fourier = a_0/2;
for n = 1:n_max
    x_t_fourier = x_t_fourier + a_n(n) * cos(n * t) + b_n(n) * sin(n * t);
end
% Plot the original sine wave, half-wave rectified wave, and Fourier series
figure;
subplot(2,1,1);
plot(t, x_t_sine, 'b', 'LineWidth', 2, 'DisplayName', 'Original Sine Wave');
title('Original Sine Wave');
xlabel('Time (t)');
ylabel('Amplitude');
grid on;
subplot(2,1,2);
plot(t, x_t_rectified, 'r', 'LineWidth', 2, 'DisplayName', 'Half-Wave Rectified
Sine Wave');
hold on;
plot(t, x_t_fourier, 'g--', 'LineWidth', 1.5, 'DisplayName', 'Fourier Series
Approximation');
title('Half-Wave Rectified Sine Wave and Fourier Series');
xlabel('Time (t)');
ylabel('Amplitude');
legend('show');
grid on;
Output: