Triangular pulse with function handle t(@)
古いコメントを表示
Hi! I have a rectangular pulse thas is given by this function handle: @(t)( (t>=0).*(t<pulseDuration) )
And I need to change this function handle to create a triangular pulse. Any ideas?
14 件のコメント
Michael
2020 年 11 月 2 日
Hi Laura,
There are lots of ways to approach this. Have you given any attempt to a solution, by incorporating additional variables, or how you would like to design the triangular pulse? These will be important in solving the problem.
Michael
Laura Ferrer Pascual
2020 年 11 月 3 日
Bjorn Gustavsson
2020 年 11 月 3 日
If that gives you half of your desired triangular pulse, what would you need to add to that to get a triangular pulse, step by step.
Stephan
2020 年 11 月 3 日
syms x
f = matlabFunction(triangularPulse(x))
plot((-1:1),f(-1:1))
Laura Ferrer Pascual
2020 年 11 月 3 日
Bjorn Gustavsson
2020 年 11 月 3 日
Laura, so you have the "up-slope" half of your triangular pulse (from [0, 0] to [1, 1]), right? From the point at [1,1] you want a line-segment back down to [0,2]? If you try to write an expression for that along similar lines as your initial function, how would you go about that? Is it enough to change the less-than and larger-than or equal conditionals? What more do you need to modify?
If you manage to construct such a "down-slope" part, can you add them toghether? Straighaway or with some additional adjustment?
Laura Ferrer Pascual
2020 年 11 月 3 日
Laura Ferrer Pascual
2020 年 11 月 3 日
Bjorn Gustavsson
2020 年 11 月 3 日
It's perfectly OK to be a beginner - everyone have been a beginner at everything they started with.
Your first up-slope function was correct for that part.
For the down-slope part you're correct about all points (and your first condition that t > 0 is extra, since the third point ensures that it is larger than pulseDuration/2 which is also larger than zero.), but in addition you have to think about the vertical off-set at time pulseDuration/2, or perhaps the intersection between the y-axis at time zero.
After that I think you will put the down-slope part together correctly. Then it is just to add them together, perhaps you will have to make sure that only one of the terms are non-zero at t=pulseDuration/2.
HTH
Laura Ferrer Pascual
2020 年 11 月 3 日
James Tursa
2020 年 11 月 3 日
編集済み: James Tursa
2020 年 11 月 3 日
Is the max height of the triangle pulse 1? Do you have to use a one-liner function handle or can you use a function file? It might be easier for you to write a function file for this instead of trying to come up with a one-liner. You can always create a function handle that points to the function file if needed.
Laura Ferrer Pascual
2020 年 11 月 3 日
Bjorn Gustavsson
2020 年 11 月 3 日
This is a task that is so much easier to handle in a .m-file where you can write a function using all of matlab's programming capabilities: conditionals (if-elseif-else-end), loops (for and while-loops) and on and on. The definition of dynamical/anonymous functions is way trickier, and doing this with multiple cases easily becomes a mess of parenthesises and operator precedences bungled up. If we take a look at your first function
ft1 = @(t)((t>=0).*(t<(pulseDuration)).*(t/(pulseDuration)));
You first define the lower and upper time-limits of the up-slope segment and then the shape of the function in that range.
If we modify that to just be half the length we get something like below:
ft2a = @(t)(t>0).*(t<pulseDuration/2).*(t/(pulseDuration/2));
Just a modified upper limit and a modified linear segment.
You are allowed to add multiple such segments together, if you just define their different ranges in time to give you what you want. So if we do that and add another segment that doesn't overlap you get something like this:
ft2b = @(t)(t>0).*(t<pulseDuration/2).*(t/(pulseDuration/2)) + (t>=pulseDuration/2).*(t<pulseDuration).*(some-line-equation);
I'll let you doodle-out what your linear equation in the second term should be, and since your pulseDuration is already defined you're allowed to use it as much as you need in the function. If you want you can also use pulseDuration as a second input argument to the function which make the function more adaptable to triangular pulses of different widths.
Laura Ferrer Pascual
2020 年 11 月 3 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Time Series Objects についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!