How to define this function?
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Antworten (1)
Divyam
am 30 Okt. 2024 um 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));
fprintf("Value of x2(t) at t = %.2f is: %.2f\n", t, x2_func);
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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Fourier Analysis and Filtering finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!