1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Matlab syntax help using fourier series & vectors

  1. Jan 26, 2009 #1
    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 (Text):

    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
    06 yce = c0*ones(size(t));            % initialize yce to c0
    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:

    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: Jan 26, 2009
  2. jcsd
  3. Jan 27, 2009 #2


    User Avatar
    Science Advisor

    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:
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook