cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

How can I extend a signal defined in a finite range to be periodic?

Cornel
19-Tanzanite

How can I extend a signal defined in a finite range to be periodic?

Hello,

 

CornelBejan_0-1681808493280.png

CornelBejan_1-1681808502423.png

 

 

CornelBejan_2-1681808597268.png????

 

How can I extend the above x(t,...) signal which is defined from -pi to pi to a periodic one so that I can display more periods of the signal, as it is shown below?

 

CornelBejan_3-1681808645707.png

 

Mathcad Prime 8 file attached.

 

Thank you.

 

 

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:Cornel)


How can I extend the above x(t,...) signal which is defined from -pi to pi to a periodic one so that I can display more periods of the signal, as it is shown below?

If its just for displaying the graph, here are a few ways to turn a piece of a function periodic.

I created utility functions which expect a function with just one argument.

The first way uses the floor function

Werner_E_0-1681819824394.png

 

Another possibility would be to use the mod function. Because its implemented in Prime in a way to return negative values for negative arguments (which is undesirable here), I used it twice, adding the period for the second time to be sure to avoid negative values.

Werner_E_1-1681819986222.png

 

You may also use a recursive approach, but I would not suggest doing so

Werner_E_2-1681820079357.png

You could achieve the same effect as in the recursive approach by using a while loop

Werner_E_3-1681820523434.png

 

Attached sheet is in Prime 9 format

 

 

 

 

View solution in original post

15 REPLIES 15
-MFra-
21-Topaz II
(To:Cornel)

In the attached pdf, from page 12 onwards, there are numerous examples:

Cornel
19-Tanzanite
(To:-MFra-)

Ok. Thank you. But now I am interested in the extension of the periodicity to start from my function defined above (x(t,...)) and adapted in order to be able to display 2 periods, or 3 periods, etc.

Hi,

To plot the periodic function try this:

To plot one or more periods restrict the variable t to a given range.

Capture.JPG

Werner_E
25-Diamond I
(To:Cornel)


How can I extend the above x(t,...) signal which is defined from -pi to pi to a periodic one so that I can display more periods of the signal, as it is shown below?

If its just for displaying the graph, here are a few ways to turn a piece of a function periodic.

I created utility functions which expect a function with just one argument.

The first way uses the floor function

Werner_E_0-1681819824394.png

 

Another possibility would be to use the mod function. Because its implemented in Prime in a way to return negative values for negative arguments (which is undesirable here), I used it twice, adding the period for the second time to be sure to avoid negative values.

Werner_E_1-1681819986222.png

 

You may also use a recursive approach, but I would not suggest doing so

Werner_E_2-1681820079357.png

You could achieve the same effect as in the recursive approach by using a while loop

Werner_E_3-1681820523434.png

 

Attached sheet is in Prime 9 format

 

 

 

 

Cornel
19-Tanzanite
(To:Werner_E)

I do not have at this moment Mathcad Prime 9, but just Mathcad Prime 8. So, I cannot open Mathcad Prime 9 file. But I inserted the mkPer1 function you wrote.

 

CornelBejan_1-1681822125103.png

 

CornelBejan_2-1681822150179.png

CornelBejan_3-1681822159869.png

 

a) 

CornelBejan_4-1681822176711.png

 

 

CornelBejan_5-1681822185768.png

Here I do not know why signalp(t) shows these discontinuities.

 

b)

CornelBejan_6-1681822203205.png

CornelBejan_7-1681822209758.png

 

c)

CornelBejan_8-1681822223248.png

 

CornelBejan_9-1681822251443.png

 

Mathcad Prime 8 file attached.

 

 

Werner_E
25-Diamond I
(To:Cornel)


@Cornel wrote:

I do not have at this moment Mathcad Prime 9, but just Mathcad Prime 8. 

 


That was the reason for the pictures I attached 😉

 


Here I do not know why signalp(t) shows these discontinuities.

 


Actually the signal IS NOT continuous. The vertical line segments which you seem to be missing would be incorrect from a mathematical point of view. But Prime omits these lines not because its so clever as we can see in the other examples.

Actually I don't know how plotting is implemented, so we can tell when vertical lines would be plotted and when not.

In my original file the verticals were missing when I used the quickplot feature but, as you could see in the picture, they were plotted when I defined a range for the abscissa values t.

When I opened your sheet and defined a range, nothing changed - the vertical lines still were not plotted.

I also tried modifying your function definition, but as you can see in the next pic, the vertical lines are still missing partially for the periodic signalp(t), but it IS drawn in the plot of signal(t),  The verticals are now drawn to connect the periodic parts, but not in the parts themselves. Can't explain why.

Werner_E_0-1681826487987.png

 

But then, the 2D plots in Prime have also other disadvantages and strange bugs (one is mentioned in my last picture). It sure isn't a masterpiece of programming.

Werner_E
25-Diamond I
(To:Werner_E)

OK, if you really need the verticals, you may play around with the step width of the range.

It looks the when the t-value for the verticals is part of the range, a vertical is drawn.

Werner_E_1-1681827488949.png

 

Cornel
19-Tanzanite
(To:Werner_E)

Is it necessary that NaN? I tried also without this NaN in the x(t,...) function and it works.

Werner_E
25-Diamond I
(To:Cornel)

If you try my approach without the NaN by simply deleting it you will get an error.

In your approach with the local variable x which you return at the end, you return zero if t is not in the range a..c.

My intention was to just plot the original function within the range a..c and I did not want to have the zero line otherwise. So I return NaN in hat case which avoids plotting anything.

Werner_E_0-1681829463252.png

You can achieve the same effect as in your approach if you return 0 instead of NaN at the end

Werner_E_1-1681829509628.png

 

 

Cornel
19-Tanzanite
(To:Werner_E)

I mean this:

 

CornelBejan_1-1681829424960.png

CornelBejan_2-1681829525836.png

 

 

CornelBejan_0-1681829400466.png

CornelBejan_3-1681829538687.png

The two above implementations return the same result, but one implementation is with NaN and the other without NaN at the end of the function.

 

 

Werner_E
25-Diamond I
(To:Cornel)

Yes, omitting NaN returns an error if you evaluate is at a position outside of the range a..c

Werner_E_0-1681829691723.png

But these errors are ignored by the plot region (similar to the NaN's).
Nonetheless a function using "if" should always return values for all possible input values.

Cornel
19-Tanzanite
(To:Werner_E)

Ok. Now I understand this.

 

Which is better to use further between the two implementations: x1 or x2? I mean the type of programming...with which it is better to stay with? Or does not matter?

 

CornelBejan_0-1681829979094.png

CornelBejan_2-1681829998712.png

CornelBejan_3-1681830047316.png

 

 

 

Werner_E
25-Diamond I
(To:Cornel)

Personally I would prefer x1 for some reasons:

1) its more efficient to leave the program immediately after a condition is fulfilled (which return is doing) and not checking all the subsequent conditions. I would use a normal "if" instead of the "if else".

2) We spare the local variable x

3) We have better control as to which value should be returned if t is not in [a; c]. Of course you could put x <-- Nan (or whatever) as first line in x2 to achieve the same effect.

 

But at the end, I guess its just a matter of personal preference.

 

ttokoro
20-Turquoise
(To:Cornel)

-MFra-
21-Topaz II
(To:Cornel)

It seems to me that you are looking for something like this (see photo) and open the attached file (for M15):

risposta a CornelBejan 2.jpg

Announcements

Top Tags