Plotting the derivative of an "switch-funktion"
Show older comments
Hello,
we got some switch funktions which i plotted with the code shown below.
The only thing i need to fix, is the plot of the derivative of these funktion.
Where the dirac should be shown (just a peak), nothing appears.
Can someone give me a hint?
Thank you in advance.

%% ÜA Karlsruhe
% 2
% 2.1
clc, clear, clf
set(0,'DefaultFigureWindowStyle','docked')
% Signal A
figure('Name', 'RT_Karlsruhe 2.1', 'NumberTitle', 'off')
subplot(4, 1, 1)
hold on, grid on, axis equal
start = -2;
ende = 10;
t = linspace(start,ende,5000);
a = @(t) (t-2).*(heaviside(t-2) - heaviside(t-4)) + (t-6).*(heaviside(t-4) - heaviside(t-6));
A = a(t);
a_derivative = @(t) heaviside(t-2) - 4*dirac(t-4) - heaviside(t-6);
A_derivative = a_derivative(t);
syms x
diff_test = diff((x-2).*(heaviside(x-2) - heaviside(x-4)) + (x-6).*(heaviside(x-4) - heaviside(x-6)));
% x = t;
%
% Diff_test = diff_test(x);
plot(t,A, 'g', 'LineWidth', 2)
plot(t,A_derivative, 'r--', 'LineWidth', 2)
fplot(diff_test, [-2 10], 'bo', 'LineWidth', 2)
title('Signal A')
xlabel('Zeit "t"')
ylabel('a(t) und a_derivative(t)')
%% Signal B
subplot(4,1,2)
hold on, grid on, axis equal
% Beide Funktionen für Signal B funktionieren
b = @(t) heaviside(t-2) - heaviside(t-8) + heaviside(t-4) - heaviside(t-6);
% b = @(t) heaviside(t-2) - heaviside(t-4) + 2*(heaviside(t-4) - heaviside(t-6)) ...
% + heaviside(t-6) - heaviside(t-8);
B = b(t);
b_derivative = @(t) dirac(t-2) - dirac(t-8) + dirac(t-4) - dirac(t-6);
B_derivative = b_derivative(t);
plot(t,B, 'g', 'LineWidth', 2)
plot(t,B_derivative, 'r--', 'LineWidth', 2)
title('Signal B')
xlabel('Zeit "t"')
ylabel('b(t) und b_derivative(t)')
%% Signal C
subplot(4,1,3)
hold on, grid on, axis equal
c = @(t) -2*heaviside(t-1) + 2*heaviside(t-3) + (t-4).*heaviside(t-4) - (t-4).*heaviside(t-6);
C = c(t);
c_derivative = @(t) -2*dirac(t-1) + 2*dirac(t-3) + heaviside(t-4) - heaviside(t-6);
C_derivative = c_derivative(t);
plot(t,C, 'g', 'LineWidth', 2)
plot(t,C_derivative, 'r--', 'LineWidth', 2)
title('Signal C')
xlabel('Zeit "t"')
ylabel('b(t) und c_derivative(t)')
%% Signal D
subplot(4,1,4)
hold on, grid on, axis equal
% d = @(t) 2*t.*(heaviside(t+1) - heaviside(t-1)) + (3-t).*(heaviside(t-1) - heaviside(t-3));
d = @(t) (2*t).*heaviside(t+1) - (3*t-3).*heaviside(t-1) - (3-t).*heaviside(t-3);
D = d(t);
d_derivative = @(t) 2*heaviside(t+1) + (2*t).*dirac(t+1) - 3*heaviside(t-1) ...
+ heaviside(t-3);
D_derivative = d_derivative(t);
plot(t,D, 'g', 'LineWidth', 2)
plot(t, D_derivative, 'r--', 'LineWidth', 2)
xticks(start:1:ende)
title('Signal D')
xlabel('Zeit "t"')
ylabel('d(t) und d_derivative(t)')%% ÜA Karlsruhe
% 2
% 2.1
clc, clear, clf
set(0,'DefaultFigureWindowStyle','docked')
% Signal A
figure('Name', 'RT_Karlsruhe 2.1', 'NumberTitle', 'off')
subplot(4, 1, 1)
hold on, grid on, axis equal
start = -2;
ende = 10;
t = linspace(start,ende,5000);
a = @(t) (t-2).*(heaviside(t-2) - heaviside(t-4)) + (t-6).*(heaviside(t-4) - heaviside(t-6));
A = a(t);
a_derivative = @(t) heaviside(t-2) - 4*dirac(t-4) - heaviside(t-6);
A_derivative = a_derivative(t);
syms x
diff_test = diff((x-2).*(heaviside(x-2) - heaviside(x-4)) + (x-6).*(heaviside(x-4) - heaviside(x-6)));
% x = t;
%
% Diff_test = diff_test(x);
plot(t,A, 'g', 'LineWidth', 2)
plot(t,A_derivative, 'r--', 'LineWidth', 2)
fplot(diff_test, [-2 10], 'bo', 'LineWidth', 2)
title('Signal A')
xlabel('Zeit "t"')
ylabel('a(t) und a_derivative(t)')
%% Signal B
subplot(4,1,2)
hold on, grid on, axis equal
% Beide Funktionen für Signal B funktionieren
b = @(t) heaviside(t-2) - heaviside(t-8) + heaviside(t-4) - heaviside(t-6);
% b = @(t) heaviside(t-2) - heaviside(t-4) + 2*(heaviside(t-4) - heaviside(t-6)) ...
% + heaviside(t-6) - heaviside(t-8);
B = b(t);
b_derivative = @(t) dirac(t-2) - dirac(t-8) + dirac(t-4) - dirac(t-6);
B_derivative = b_derivative(t);
plot(t,B, 'g', 'LineWidth', 2)
plot(t,B_derivative, 'r--', 'LineWidth', 2)
title('Signal B')
xlabel('Zeit "t"')
ylabel('b(t) und b_derivative(t)')
%% Signal C
subplot(4,1,3)
hold on, grid on, axis equal
c = @(t) -2*heaviside(t-1) + 2*heaviside(t-3) + (t-4).*heaviside(t-4) - (t-4).*heaviside(t-6);
C = c(t);
c_derivative = @(t) -2*dirac(t-1) + 2*dirac(t-3) + heaviside(t-4) - heaviside(t-6);
C_derivative = c_derivative(t);
plot(t,C, 'g', 'LineWidth', 2)
plot(t,C_derivative, 'r--', 'LineWidth', 2)
title('Signal C')
xlabel('Zeit "t"')
ylabel('b(t) und c_derivative(t)')
%% Signal D
subplot(4,1,4)
hold on, grid on, axis equal
% d = @(t) 2*t.*(heaviside(t+1) - heaviside(t-1)) + (3-t).*(heaviside(t-1) - heaviside(t-3));
d = @(t) (2*t).*heaviside(t+1) - (3*t-3).*heaviside(t-1) - (3-t).*heaviside(t-3);
D = d(t);
d_derivative = @(t) 2*heaviside(t+1) + (2*t).*dirac(t+1) - 3*heaviside(t-1) ...
+ heaviside(t-3);
D_derivative = d_derivative(t);
plot(t,D, 'g', 'LineWidth', 2)
plot(t, D_derivative, 'r--', 'LineWidth', 2)
xticks(start:1:ende)
title('Signal D')
xlabel('Zeit "t"')
ylabel('d(t) und d_derivative(t)')
Accepted Answer
More Answers (0)
Categories
Find more on Fourier Analysis and Filtering in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!