Jump to content

Could someone explain something to me related to Matlab?

ZeRedz

I need help with this argument in the code which is denoted by "W":
https://i.imgur.com/u7uW41n.png
https://i.imgur.com/vichQOs.png

 

Q1. What exactly is W doing here? What exactly is it doing to turn a sawtooth wave into a triangular wave?

Q2. I see no changes in the rising and falling edges except for the shapes of both edges. The rising edge is going from -1 to 1 and the falling edge is going from 1 to -1. Am I correct to assume that the only real change is in the shapes of the two?

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

That's not matlab, it's octave...

https://octave.sourceforge.io/signal/function/sawtooth.html

Quote

width is a real number between 0 and 1 which specifies the point between 0 and 2 * pi where the maximum is. The function increases linearly from -1 to 1 in [0, 2 * pi * width] interval, and decreases linearly from 1 to -1 in the interval [2 * pi * width, 2 * pi].

the difference is in where the maximum is.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

14 minutes ago, Sauron said:

That's not matlab, it's octave...

https://octave.sourceforge.io/signal/function/sawtooth.html

the difference is in where the maximum is.

The distinction here is irrelevant, and almost every user who would know the distinction would also know that it doesn't matter for this situation. While by contrast, people who only know Matlab might not know that the code is the same.

 

@OP 

https://www.mathworks.com/help/signal/ref/sawtooth.html

Better documentation for the same function including graphics of what happens with and without W, and yes it works the same way in Octave.

LINK-> Kurald Galain:  The Night Eternal 

Top 5820k, 980ti SLI Build in the World*

CPU: i7-5820k // GPU: SLI MSI 980ti Gaming 6G // Cooling: Full Custom WC //  Mobo: ASUS X99 Sabertooth // Ram: 32GB Crucial Ballistic Sport // Boot SSD: Samsung 850 EVO 500GB

Mass SSD: Crucial M500 960GB  // PSU: EVGA Supernova 850G2 // Case: Fractal Design Define S Windowed // OS: Windows 10 // Mouse: Razer Naga Chroma // Keyboard: Corsair k70 Cherry MX Reds

Headset: Senn RS185 // Monitor: ASUS PG348Q // Devices: Note 10+ - Surface Book 2 15"

LINK-> Ainulindale: Music of the Ainur 

Prosumer DYI FreeNAS

CPU: Xeon E3-1231v3  // Cooling: Noctua L9x65 //  Mobo: AsRock E3C224D2I // Ram: 16GB Kingston ECC DDR3-1333

HDDs: 4x HGST Deskstar NAS 3TB  // PSU: EVGA 650GQ // Case: Fractal Design Node 304 // OS: FreeNAS

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, Curufinwe_wins said:

The distinction here is irrelevant, and almost every user who would know the distinction would also know that it doesn't matter for this situation. While by contrast, people who only know Matlab might not know that the code is the same.

I would argue it's very relevant if OP doesn't know what tool they're using. In this case the function is the same but I doubt this question exists in a vacuum.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

9 minutes ago, Sauron said:

I would argue it's very relevant if OP doesn't know what tool they're using. In this case the function is the same but I doubt this question exists in a vacuum.

Ok, so here's the thing. If I had a question in my M-code, I would be using Octave atm because my company is cheap AF and won't buy matlab for me. I know when Octave and Matlab are not code-compatible, but I sure as fuck wouldn't be asking anyone for Octave help because the octave help is way less well documented and the user base is far smaller. I would instead do exactly what OP did and ask for Matlab help and if code-incompatibilies came up, then and only then would it be my problem to deal with.

 

(unless ofc I was explicitly asking for help in a situation where I knew the problem was because of code-incompatibility.)

 

[Just in case, reminder that Octave was/is designed to be as code-compatible with Matlab as possible.]

 

38 minutes ago, ZeRedz said:

I need help with this argument in the code which is denoted by "W":
https://i.imgur.com/u7uW41n.png
https://i.imgur.com/vichQOs.png

 

Q1. What exactly is W doing here? What exactly is it doing to turn a sawtooth wave into a triangular wave?

Q2. I see no changes in the rising and falling edges except for the shapes of both edges. The rising edge is going from -1 to 1 and the falling edge is going from 1 to -1. Am I correct to assume that the only real change is in the shapes of the two?

 

 

x = sawtooth(t,xmax) generates a modified triangle wave with the maximum location at each period controlled by xmax. Set xmax to 0.5 to generate a standard triangle wave.

From the matlab documentation. W (xmax) changes where the maximum value along the period occurs. Without W set, xMax defaults to 1 which means the max value occurs at the end of the period (sawtooth). At W=.5, the max value occurs at half the period, so the wave is symmetric and a standard triangle wave. Yes that is a shape change.

LINK-> Kurald Galain:  The Night Eternal 

Top 5820k, 980ti SLI Build in the World*

CPU: i7-5820k // GPU: SLI MSI 980ti Gaming 6G // Cooling: Full Custom WC //  Mobo: ASUS X99 Sabertooth // Ram: 32GB Crucial Ballistic Sport // Boot SSD: Samsung 850 EVO 500GB

Mass SSD: Crucial M500 960GB  // PSU: EVGA Supernova 850G2 // Case: Fractal Design Define S Windowed // OS: Windows 10 // Mouse: Razer Naga Chroma // Keyboard: Corsair k70 Cherry MX Reds

Headset: Senn RS185 // Monitor: ASUS PG348Q // Devices: Note 10+ - Surface Book 2 15"

LINK-> Ainulindale: Music of the Ainur 

Prosumer DYI FreeNAS

CPU: Xeon E3-1231v3  // Cooling: Noctua L9x65 //  Mobo: AsRock E3C224D2I // Ram: 16GB Kingston ECC DDR3-1333

HDDs: 4x HGST Deskstar NAS 3TB  // PSU: EVGA 650GQ // Case: Fractal Design Node 304 // OS: FreeNAS

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

9 minutes ago, Curufinwe_wins said:

Ok, so here's the thing. If I had a question in my M-code, I would be using Octave atm because my company is cheap AF and won't buy matlab for me. I know when Octave and Matlab are not code-compatible, but I sure as fuck wouldn't be asking anyone for Octave help because the octave help is way less well documented and the user base is far smaller. I would instead do exactly what OP did and ask for Matlab help and if code-incompatibilies came up, then and only then would it be my problem to deal with.

Even if this is the case all I did was point out that they're using octave, not matlab, while answering the question. At worst it was redundant. I prefer that to the ambiguity of whether OP knows what they're using/are supposed to be using or not. Better safe than sorry imo.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

9 minutes ago, Sauron said:

Even if this is the case all I did was point out that they're using octave, not matlab, while answering the question. At worst it was redundant. I prefer that to the ambiguity of whether OP knows what they're using/are supposed to be using or not. Better safe than sorry imo.

Ok, before I go on another or different rant... Have you used octave and matlab before? [Not trying to sound patronizing, it's an honest question.]

 

Octave's design goal, from the start, was to be an open-source Matlab equivalent, with as close to direct code compatibility as possible. Things have diverged a bit since then (Matlab retires some old functionality that Octave has preserved, and Matlab with far more resources adds many more specialized functions a year than Octave can keep up with)... but honestly the distinction is like complaining that someone asks for C++ help when they show you a code written in VC++....

 

(I am not going to say you wouldn't be justified in looking up the function calls and giving the correct function call documentation regardless, and you did point out the correct function call, so thank you for that...)

LINK-> Kurald Galain:  The Night Eternal 

Top 5820k, 980ti SLI Build in the World*

CPU: i7-5820k // GPU: SLI MSI 980ti Gaming 6G // Cooling: Full Custom WC //  Mobo: ASUS X99 Sabertooth // Ram: 32GB Crucial Ballistic Sport // Boot SSD: Samsung 850 EVO 500GB

Mass SSD: Crucial M500 960GB  // PSU: EVGA Supernova 850G2 // Case: Fractal Design Define S Windowed // OS: Windows 10 // Mouse: Razer Naga Chroma // Keyboard: Corsair k70 Cherry MX Reds

Headset: Senn RS185 // Monitor: ASUS PG348Q // Devices: Note 10+ - Surface Book 2 15"

LINK-> Ainulindale: Music of the Ainur 

Prosumer DYI FreeNAS

CPU: Xeon E3-1231v3  // Cooling: Noctua L9x65 //  Mobo: AsRock E3C224D2I // Ram: 16GB Kingston ECC DDR3-1333

HDDs: 4x HGST Deskstar NAS 3TB  // PSU: EVGA 650GQ // Case: Fractal Design Node 304 // OS: FreeNAS

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, Sauron said:

I would argue it's very relevant if OP doesn't know what tool they're using. In this case the function is the same but I doubt this question exists in a vacuum.

Bro, I just called it Matlab because the code and what not's the same.

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, Curufinwe_wins said:

Ok, before I go on another or different rant... Have you used octave and matlab before? [Not trying to sound patronizing, it's an honest question.]

 

Octave's design goal, from the start, was to be an open-source Matlab equivalent, with as close to direct code compatibility as possible. Things have diverged a bit since then (Matlab retires some old functionality that Octave has preserved, and Matlab with far more resources adds many more specialized functions a year than Octave can keep up with)... but honestly the distinction is like complaining that someone asks for C++ help when they show you a code written in VC++....

 

(I am not going to say you wouldn't be justified in looking up the function calls and giving the correct function call documentation regardless, and you did point out the correct function call, so thank you for that...)

I see it more like asking for MS Word help while showing Libreoffice Writer - it's often close enough but you should be aware of the difference. Unlike C++ compilers they're not two implementations of the same public standard (where a difference in core functionality would be considered a serious bug) but rather completely separate projects where one tries to approximate the functionality of the other.

 

I would argue that if I were in the situation you described before I would rather someone actually help me with Octave if possible. Maybe it was an unnecessary precaution but, honestly, I didn't come into it expecting to debate the merits of mentioning a possible pitfall in passing.

 

Yes, I have used them if that matters. I'm no expert of either but I can read documentation 🤷‍♂️

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

Calm down, guys. I'm just using Octave because I don't have Matlab installed at the minute. 

Link to comment
Share on other sites

Link to post
Share on other sites

I have a follow-up question. Is it safe to assume that the rising edge is from -1 to 1 and the falling edge is from 1 to -1 in both waveforms? Sorry if I'm being paranoid. 

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Sauron said:

snip

The reason why I mentioned VC++ is because technically speaking there are a number of functions and subroutines in VC++ that are not implemented in C++, and there are code incompatibilities the other way which are indeed serious bugs, but have been so for a long time unfortunately. (Again speaking from experience here haha).

 

Anyways, the real problem is that Octave user base is tiny by comparison, and I wouldn't want potentially hundreds of Matlab experts who literally just never heard of Octave not help me because they look at the title and don't understand it's the same thing (for this code purpose). I can potentially agree however the most ideal thing would be to reference both in the writeup... Maximize both the correctness and the user base which responds to you.

 

2 minutes ago, ZeRedz said:

Calm down, guys. I'm just using Octave because I don't have Matlab installed at the minute. 

Don't worry, we might have hijacked your thread, but we both responded on topic first to answer your question, so it's all good. Sometimes the old-timers need to butt-heads a bit.

LINK-> Kurald Galain:  The Night Eternal 

Top 5820k, 980ti SLI Build in the World*

CPU: i7-5820k // GPU: SLI MSI 980ti Gaming 6G // Cooling: Full Custom WC //  Mobo: ASUS X99 Sabertooth // Ram: 32GB Crucial Ballistic Sport // Boot SSD: Samsung 850 EVO 500GB

Mass SSD: Crucial M500 960GB  // PSU: EVGA Supernova 850G2 // Case: Fractal Design Define S Windowed // OS: Windows 10 // Mouse: Razer Naga Chroma // Keyboard: Corsair k70 Cherry MX Reds

Headset: Senn RS185 // Monitor: ASUS PG348Q // Devices: Note 10+ - Surface Book 2 15"

LINK-> Ainulindale: Music of the Ainur 

Prosumer DYI FreeNAS

CPU: Xeon E3-1231v3  // Cooling: Noctua L9x65 //  Mobo: AsRock E3C224D2I // Ram: 16GB Kingston ECC DDR3-1333

HDDs: 4x HGST Deskstar NAS 3TB  // PSU: EVGA 650GQ // Case: Fractal Design Node 304 // OS: FreeNAS

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, ZeRedz said:

I have a follow-up question. Is it safe to assume that the rising edge is from -1 to 1 and the falling edge is from 1 to -1 in both waveforms? Sorry if I'm being paranoid. 

Yep, there isn't a variable to adjust that type of thing within the function call. [an intentional limitation to the sawtooth() function relative to making your own]

LINK-> Kurald Galain:  The Night Eternal 

Top 5820k, 980ti SLI Build in the World*

CPU: i7-5820k // GPU: SLI MSI 980ti Gaming 6G // Cooling: Full Custom WC //  Mobo: ASUS X99 Sabertooth // Ram: 32GB Crucial Ballistic Sport // Boot SSD: Samsung 850 EVO 500GB

Mass SSD: Crucial M500 960GB  // PSU: EVGA Supernova 850G2 // Case: Fractal Design Define S Windowed // OS: Windows 10 // Mouse: Razer Naga Chroma // Keyboard: Corsair k70 Cherry MX Reds

Headset: Senn RS185 // Monitor: ASUS PG348Q // Devices: Note 10+ - Surface Book 2 15"

LINK-> Ainulindale: Music of the Ainur 

Prosumer DYI FreeNAS

CPU: Xeon E3-1231v3  // Cooling: Noctua L9x65 //  Mobo: AsRock E3C224D2I // Ram: 16GB Kingston ECC DDR3-1333

HDDs: 4x HGST Deskstar NAS 3TB  // PSU: EVGA 650GQ // Case: Fractal Design Node 304 // OS: FreeNAS

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, ZeRedz said:

I have a follow-up question. Is it safe to assume that the rising edge is from -1 to 1 and the falling edge is from 1 to -1 in both waveforms? Sorry if I'm being paranoid. 

Could one of you good ol' old-timers answer this? I'm sorry if the question is quite stupid.

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, ZeRedz said:

Could one of you good ol' old-timers answer this? I fucking suck at Matlab.

I did above ofc, but for future reference, the mathworks documentation is absolutely insanely detailed and helpful.

 

https://www.mathworks.com/help/signal/ref/sawtooth.html

 

See the many examples for this function and how they work graphically, it should explain exactly what happens. Any other time you get stuck (I do this too), the first step I would recommend is googling "function name matlab" and clicking on the mathworks link that shows up for that function. The examples given will almost always tell you everything you need to know.

LINK-> Kurald Galain:  The Night Eternal 

Top 5820k, 980ti SLI Build in the World*

CPU: i7-5820k // GPU: SLI MSI 980ti Gaming 6G // Cooling: Full Custom WC //  Mobo: ASUS X99 Sabertooth // Ram: 32GB Crucial Ballistic Sport // Boot SSD: Samsung 850 EVO 500GB

Mass SSD: Crucial M500 960GB  // PSU: EVGA Supernova 850G2 // Case: Fractal Design Define S Windowed // OS: Windows 10 // Mouse: Razer Naga Chroma // Keyboard: Corsair k70 Cherry MX Reds

Headset: Senn RS185 // Monitor: ASUS PG348Q // Devices: Note 10+ - Surface Book 2 15"

LINK-> Ainulindale: Music of the Ainur 

Prosumer DYI FreeNAS

CPU: Xeon E3-1231v3  // Cooling: Noctua L9x65 //  Mobo: AsRock E3C224D2I // Ram: 16GB Kingston ECC DDR3-1333

HDDs: 4x HGST Deskstar NAS 3TB  // PSU: EVGA 650GQ // Case: Fractal Design Node 304 // OS: FreeNAS

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

5 minutes ago, ZeRedz said:

I have a follow-up question. Is it safe to assume that the rising edge is from -1 to 1 and the falling edge is from 1 to -1 in both waveforms? Sorry if I'm being paranoid. 

Yes, at least if the documentation is to be believed.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Curufinwe_wins said:

I did above ofc, but for future reference, the mathworks documentation is absolutely insanely detailed and helpful.

 

https://www.mathworks.com/help/signal/ref/sawtooth.html

 

See the many examples for this function and how they work graphically, it should explain exactly what happens. Any other time you get stuck (I do this too), the first step I would recommend is googling "function name matlab" and clicking on the mathworks link that shows up for that function. The examples given will almost always tell you everything you need to know.

Oh, I posted that prior to you replying. Thanks for the link. Also, is the xmax value essentially the maximum value for the x-axis?

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, ZeRedz said:

Oh, I posted that prior to you replying. Thanks for the link. Also, is the xmax value essentially the maximum value for the x-axis?

The idea is that xmax is the first (more accurately, fundamental) x-value at which the y-axis is maximized. 

LINK-> Kurald Galain:  The Night Eternal 

Top 5820k, 980ti SLI Build in the World*

CPU: i7-5820k // GPU: SLI MSI 980ti Gaming 6G // Cooling: Full Custom WC //  Mobo: ASUS X99 Sabertooth // Ram: 32GB Crucial Ballistic Sport // Boot SSD: Samsung 850 EVO 500GB

Mass SSD: Crucial M500 960GB  // PSU: EVGA Supernova 850G2 // Case: Fractal Design Define S Windowed // OS: Windows 10 // Mouse: Razer Naga Chroma // Keyboard: Corsair k70 Cherry MX Reds

Headset: Senn RS185 // Monitor: ASUS PG348Q // Devices: Note 10+ - Surface Book 2 15"

LINK-> Ainulindale: Music of the Ainur 

Prosumer DYI FreeNAS

CPU: Xeon E3-1231v3  // Cooling: Noctua L9x65 //  Mobo: AsRock E3C224D2I // Ram: 16GB Kingston ECC DDR3-1333

HDDs: 4x HGST Deskstar NAS 3TB  // PSU: EVGA 650GQ // Case: Fractal Design Node 304 // OS: FreeNAS

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

5 minutes ago, Curufinwe_wins said:

The idea is that xmax is the first (more accurately, fundamental) x-value at which the y-axis is maximized. 

I see. 
Thanks for helping me out, guys!

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×