How to define this function?

조회 수: 2 (최근 30일)
Niloufar
Niloufar 2022년 11월 5일
답변: Divyam 2024년 10월 30일
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
John D'Errico
John D'Errico 2022년 11월 5일
x2 is NOT a function of t. Period. As an integral, t goes away.

댓글을 달려면 로그인하십시오.

답변 (1개)

Divyam
Divyam 2024년 10월 30일
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

카테고리

Help CenterFile Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by