Help with plotting triangular wave

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

This discussion focuses on generating a triangular wave using MATLAB by summing a series defined as 1/(2n+1)^2 * cos((2n+1)*w0*t), where w0 = 2π/T. The participants troubleshoot issues related to plotting the wave with varying terms (6, 10, and 30) for T = 2. Key insights include the necessity of creating a sampled time vector and implementing a summation mechanism within a for loop to accumulate series terms correctly. The final code provided successfully demonstrates the convergence of the series to a triangular wave.

PREREQUISITES
  • Understanding of MATLAB syntax and functions
  • Familiarity with Fourier series and triangular waveforms
  • Knowledge of vector operations in MATLAB
  • Basic concepts of digital signal processing
NEXT STEPS
  • Learn how to implement for loops in MATLAB for series summation
  • Explore MATLAB's plotting functions for better visualization
  • Study the use of the filter() function for implementing difference equations
  • Investigate the relationship between triangular waves and their frequency response in LTI systems
USEFUL FOR

Students and professionals in signal processing, MATLAB users looking to visualize waveforms, and engineers working with LTI systems and Fourier series.

  • #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: 471
  • #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
2K
Replies
2
Views
1K
  • · 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