Create nonlinear trend via trapmf function (trapezoidal signal)

2 views (last 30 days)
Hello there :)
I have created the following trend:
This is the script I have used to for that:
%%init
clear; % clear workspace
close all; % close all figures
%%defintions
Fs = 2;
Ts = 1/Fs;
t =0:Ts:30;
%%create trapezoidal signal
% time vectors for trapezoidal signal
t_1 = t(1,1:((3/Ts)));
t_2 = t(1,((3/Ts)+1):((16/Ts)));
t_3 = t(1,((16/Ts+1)):((19/Ts)));
t_4 = t(1,((19/Ts+1)):end);
% trapmf(time_vector,[Start_of_trapez, First_edge_ second_edge, end_point])
trapez_1 = trapmf(t_1,[.5 1 2 2.5]);
trapez_2 = (trapmf(t_2,[3 3.5 4.5 5]))*-1; % inverse trapezoidal signal
trapez_3 = (trapmf(t_3,[16.5 17 18 18.5]))*-1;
trapez_4 = (trapmf(t_4,[19 19.5 20.5 21]));
% create complete signal containing trapez_1 to trapez_4
signal = [trapez_1 trapez_2 trapez_3 trapez_4];
%%plot signal
plot (t,signal);
xlabel('x');
ylabel('y');
title ('Nonlinearity');
grid on;
I would like to create a nonlinear trend for the marked areas on the picture above (I've only marked the first area for example). For this purpose, I would like to use a cubical function to create a nonlinear trend between the stationary areas. From my point of view, the way to do this is define a cubical function and add it to the areas, where a linear trend exists.
Is there any trick to do this with the created trapezoidal signal? I need to remain the rest of the signal as it is right now (that's what makes it tricky for me...)
I would be really thankful for any help :)
Thanks in advance.
Best regards, Niko

Accepted Answer

Student88
Student88 on 13 Aug 2016
Hey there :)
I've solved my problem with Matlab function: interp1.
x1 = [0 0.125 0.25 0.375 0.5]; % define time points for cubical function
y1 = [0 0.4 0.6 0.65 1]; % define resulting y-data
xq1 = 0:0.001:0.5; % time points for first acceleration (upwards)
vq1 = interp1(x1,y1,xq1,'spline'); % resulting y-data for cubical function
plot(xq1,vq1);

More Answers (0)

Community Treasure Hunt

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

Start Hunting!