MATLAB Plot of a periodic function

Click For Summary
SUMMARY

The discussion focuses on plotting a periodic function in MATLAB using two different formulations. The first formulation, x(n) = 1 + sin((2*pi)/N)*n + 3*cos((2*pi)/N)*n + cos(((4*pi)/N)*n + pi/2);, results in a non-periodic appearance when plotted in a loop. In contrast, the second formulation using Euler's expansion produces a periodic graph. The user highlights the importance of using element-wise operations in MATLAB, specifically the need for a dot (.) before multiplication signs to avoid matrix multiplication issues.

PREREQUISITES
  • Understanding of MATLAB syntax and plotting functions
  • Familiarity with periodic functions and Fourier coefficients
  • Knowledge of Euler's formula and complex exponentials
  • Basic concepts of element-wise operations in MATLAB
NEXT STEPS
  • Learn about MATLAB's element-wise operations and their significance
  • Explore Fourier series and their applications in signal processing
  • Investigate MATLAB's plotting functions for visualizing periodic functions
  • Study the differences between matrix and element-wise operations in MATLAB
USEFUL FOR

Mathematicians, engineers, and data scientists interested in signal processing, MATLAB users looking to enhance their plotting techniques, and anyone studying periodic functions and Fourier analysis.

ColdStart
Messages
18
Reaction score
0
letsa say my function is:
x(n) = 1 + sin((2*pi)/N)*n + 3*cos((2*pi)/N)*n + cos( ((4*pi)/N)*n + pi/2);

when i plot it inside a loop, with a loop variable being n, i have something llike increasing slope... even when i set a period N to be 8,4 or whateva..

on the other side... when i plot the same function expanded using euler's expansion:
x(n) = 1 + (1/(2*1i))*(exp(1i*2*pi*n/N) - exp(-1i*2*pi*n/N)) + 1.5*(exp(1i*2*pi*n/N) + exp(-1i*2*pi*n/N)) + 0.5*(exp(1i*(4*pi*n/N + pi/2)) + exp(-1i*(4*pi*n/N + pi/2)));

i do get a function which looks periodic.. that is a little bit weird, or am i missing something?

p.s. and the second function is obtained from the Fourier ak Coofficients..
 
Physics news on Phys.org
Why use a loop. Make an array of all n-variables and then a array of all x(n) solutions for then to plot.

ie. n=0:0.01:2*pi;
x=...;
plot(n,x)

Also you might want to put a .(period) in front of all mutiplication signs, or else it does a matrix multiplication.
ie. >> x=1+sin(2.*pi*n)+3.*cos(2.*pi.*n)+cos((4.*pi.*n)+ pi/2);
 
thank you! yeah! i have no idea sometimes its confusing when in the books they put period outside of parenthesis!.. that make sense now!
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
6K