How to define this function?

8 visualizaciones (últimos 30 días)
Niloufar
Niloufar el 5 de Nov. de 2022
Respondida: Divyam el 30 de Oct. de 2024 a las 6:39
How can I define the second periodic function(x2(t))?
here is the definition of the first function that I defined.
close all;clear;clc;
Fs = 50;
T = 1/Fs;
t = -2*pi:T:2*pi;
L = length(t);
%peroid 2*pi first function
X1 = 1/2*(1+square(2/3*(t+pi),200/3));
Y1 = fft(X1);
f = Fs*(0:(L-1))/L;
subplot(1,2,1);
plot(t,X1);
subplot(1,2,2);
plot(f,abs(Y1));
  1 comentario
John D'Errico
John D'Errico el 5 de Nov. de 2022
x2 is NOT a function of t. Period. As an integral, t goes away.

Iniciar sesión para comentar.

Respuestas (1)

Divyam
Divyam el 30 de Oct. de 2024 a las 6:39
You can create the following function handle for and calculate using the "integral" function:
% Sample values for T and t
T = 2;
t = 0;
% Function handle for x1(t)
x1_func = @(t) double(abs(t) <= T/2);
% Calculating x2(t)
x2_func = integral(@(t) x1_func(t), -inf, inf);
% Printing out the values
fprintf("Value of x1(t) at t = %.2f is: %.2f\n", t, x1_func(t));
Value of x1(t) at t = 0.00 is: 1.00
fprintf("Value of x2(t) at t = %.2f is: %.2f\n", t, x2_func);
Value of x2(t) at t = 0.00 is: 2.00
To plot the functions and you can calculate their values for certain interval of t and plot them using the "plot" function:
% Parameters
T = 2;
dt = 0.01;
t = -4:dt:4;
% Calculate x1(t)
x1 = zeros(size(t));
x1(abs(t) <= T/2) = 1;
x1_func = @(t) double(abs(t) <= T/2);
% Calculate x2(t) - integral of x1(t)
x2 = zeros(size(t));
for i = 1:length(t)
x2(i) = integral(@(t) x1_func(t), -inf, inf);
end
% Create figure with subplots
figure;
% Plot x1(t)
subplot(2,1,1);
plot(t, x1, 'LineWidth', 2);
grid on;
title('x_1(t) - Rectangular Pulse');
xlabel('t');
ylabel('x_1(t)');
ylim([-0.2, 1.2]);
% Add vertical lines to show T/2 and -T/2
hold on;
plot([-T/2 -T/2], [-0.2 1.2], 'r--');
plot([T/2 T/2], [-0.2 1.2], 'r--');
legend('x_1(t)', 'T/2 boundaries');
% Plot x2(t)
subplot(2,1,2);
plot(t, x2, 'LineWidth', 2);
grid on;
title('x_2(t) - Integral of x_1(t)');
xlabel('t');
ylabel('x_2(t)');
For more information regarding the "integral" function, refer to this documentation: https://www.mathworks.com/help/matlab/ref/integral.html

Categorías

Más información sobre Fourier Analysis and Filtering en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by