Matlab syntax help using fourier series & vectors

Click For Summary
SUMMARY

The discussion focuses on understanding MATLAB syntax for implementing a Fourier series approximation of a signal. The code provided demonstrates how to compute the Fourier series coefficients and update a vector using element-wise operations. Specifically, the line "yce = yce + cn*exp(j*n*wo*t);" illustrates how MATLAB evaluates vector and scalar operations, confirming that "exp(vector)" generates a new vector with exponentials of each entry in the original vector. This confirms the element-wise nature of operations in MATLAB.

PREREQUISITES
  • Familiarity with MATLAB programming language
  • Understanding of Fourier series and signal processing concepts
  • Knowledge of complex numbers and their representation in MATLAB
  • Basic understanding of vector and matrix operations in MATLAB
NEXT STEPS
  • Explore MATLAB's element-wise operations and their syntax
  • Learn about MATLAB's built-in functions for signal processing
  • Study the implementation of Fourier series in MATLAB with practical examples
  • Investigate MATLAB's handling of complex numbers and their applications
USEFUL FOR

Students and professionals in engineering, particularly those working with signal processing, as well as MATLAB users seeking to deepen their understanding of vector operations and Fourier series computations.

radiodude
Messages
14
Reaction score
0
I'm trying to understand some MATLAB code. It's the Fourier series approximation of a signal. This is my first time using matlab, so I guess I'm really trying to comprehend the syntax.

For my example, I am using some code I googled (http://www.ee.nmt.edu/~wedeward/EE341/FA97/example8.html)

Code:
01 N = 11;                            % summation limit (use N odd)
02 wo = pi;                           % fundamental frequency (rad/s)
03 c0 = 0;                            % dc bias
04 t = -3:0.01:3;                     % declare time values
05 
06 yce = c0*ones(size(t));            % initialize yce to c0
07 
08 for n = -N:2:N,                    % loop over series index n
09   cn = 2/(j*n*wo);                 % Fourier Series Coefficient
10   yce = yce + cn*exp(j*n*wo*t);    % Fourier Series computation
11 end

What I don't understand is the yce = yce + ... line (line 10). On that line you have
yce [vector]
cn [scalar]
j [scalar]
n [scalar]
wo [scalar]
t [vector]

So what does
vector = vector + scalar * exp(scalar * scalar * scalar * vector)
really evaluate to in matlab?

Does exp(vector) really mean it creates a new vector with entries:
e^old_vec_entry_for_t0
e^old_vec_entry_for_t1
...
e^old_vec_entry_for_tn

If so, then it makes sense as then it resolves to
vector = vector + scalar*vector

which is then

vector_running_sum = vector_running_sum + vector_values_for_all_t_from_neg_n_to_pos_n
 
Last edited:
Physics news on Phys.org
Your interpretation is correct. When you do vectorB=exp(vectorA), it produces a vector of the same size as vectorA containing the exponents of each of the values in vectorA.

This is an element-wise operator. Sometimes, you need to specify (usually by preceding the operator with a period, for instance ./ is element-wise division). For more, see:
http://www.cyclismo.org/tutorial/matlab/operations.html
 

Similar threads

  • · Replies 26 ·
Replies
26
Views
3K
  • · Replies 3 ·
Replies
3
Views
6K
  • · Replies 6 ·
Replies
6
Views
5K
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
3
Views
2K
Replies
2
Views
2K