How to define this function?

1 回表示 (過去 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 Center および File ExchangeFourier Analysis and Filtering についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by