Help with plotting triangular wave

  • Thread starter Thread starter Davidlong
  • Start date Start date
  • Tags Tags
    Plotting Wave
Click For Summary

Discussion Overview

The discussion revolves around generating and plotting a triangular wave using MATLAB, specifically focusing on the convergence of a series representation of the wave. Participants are addressing issues related to plotting sampled waveforms, the correct implementation of the series, and the use of MATLAB syntax.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • One participant provides a series representation for a triangular wave and requests help with plotting it using MATLAB.
  • Another participant suggests that the plotting should involve sampling at specific times and introduces the need for two index variables: one for the series terms and another for sampling.
  • Concerns are raised about the clarity of variable names, with suggestions to use different notations for the series-sum index and the sampled time vector.
  • Participants discuss the necessity of a summation mechanism (for loop) to accumulate series terms, indicating that the original code lacks this feature.
  • There is confusion regarding the use of MATLAB operators, with some participants noting that the dot operators may not be necessary in certain contexts.
  • One participant expresses uncertainty about how to properly implement the series and sampling in their code, indicating that they are unsure if they are plotting the correct values.
  • Another participant mentions the importance of familiarizing oneself with MATLAB resources for better understanding and usage.

Areas of Agreement / Disagreement

Participants generally agree on the need for a summation mechanism and proper variable handling in MATLAB. However, there is no consensus on the exact implementation details or the correctness of the current approaches, as multiple suggestions and corrections are presented.

Contextual Notes

Participants highlight limitations in the original code, including the lack of a proper summation mechanism and confusion regarding variable definitions. There are also unresolved questions about the correct use of sampling time and how it interacts with the series representation.

Who May Find This Useful

This discussion may be useful for individuals learning MATLAB, particularly those interested in signal processing and waveform generation, as well as those seeking to understand series convergence in the context of triangular waves.

  • #31
lewando said:
Also, one final thing: what is the purpose of doing:

% Make wave start at 0
s = s - s(1);

This introduces an artificial offset to the data. Is this required?

It's not really required. I re-ran is by doing s=0; before all the maxterms and i did get a similar amplitude range for all 3 plots. The peaks don't vary much. The question asks us to provide the peak value hence the reason for hard coding it. Is there a simple bit of code that could automatically provide it?
 
Physics news on Phys.org
  • #32
Try:

m = max(s)
title_string = sprintf('maximum is: %f',m)
title(title_string)

As for your offset-- then don't do it. It is affecting the peak value you are reporting.
 
  • #33
I guess the peak value is the same for all 3 plots. The only noticeable difference is the sharpening of the edge of the triangle. I assume as convergence occurs there will be less visible change.
 

Attachments

  • graphs.jpg
    graphs.jpg
    36.8 KB · Views: 478
  • #34
They should not be the same. They should be close, but N=30 should give you a larger peak than N=6. Just considering the summation at the t=0, cos(0)=1, point.
 
  • #35
Ah it was because i didn't put m=max(s) before every maxterm. I have did that now and got a larger peak. 1.192, 1.209 and 1.225
 

Similar threads

Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K