next up previous contents
Next: Power Spectrum of a Up: Power Spectrum Previous: Power Spectrum   Contents

Some commands used to calculate the module of complex values in Scilab

In this section we are interested in calculating the amount of energy carried by each frequency. The whole energy of the signal is proportional to the sum of the squared amplitude of its values.

There are several ways to calculate the ``sum squared amplitude'' of a vector in Scilab. If a vector contains real and complex values (positive and negative) the next example will show the effect of some operators.


-->x = [5, -5, 3+4*%i, 5*%i, -5*%i]
 x  =
 
!   5.  - 5.    3. + 4.i    5.i  - 5.i !
 
-->abs(x)
 ans  =
 
!   5.    5.    5.    5.    5. !
 
-->conj(x)
 ans  =
 
!   5.  - 5.    3. - 4.i  - 5.i    5.i !
 
-->x'
 ans  =
 
!   5.       !
! - 5.       !
!   3. - 4.i !
! - 5.i      !
!   5.i      !

Notice that the operator quote is used to conjugate and transpose the vector. If we want only to transpose the vector we can use a dot


-->x.'              
 ans  =
 
!   5.       !
! - 5.       !
!   3. + 4.i !
!   5.i      !
! - 5.i      !

Now we are going to calculate the square of the values of a vector


-->abs(x)^2
 ans  =
 
!   25.    25.    25.    25.    25. !
 
-->x .* conj(x)
 ans  =
 
!   25.    25.    25.    25.    25. !

Notice that operations with complex values can cause some troubles if we do not manipulate them properly


-->x .* x
 ans  =
 
!   25.    25.  - 7. + 24.i  - 25.  - 25. !
 
-->x ^ 2
 ans  =
 
!   25.    25.  - 7. + 24.i  - 25.  - 25. !

As we are interested in calculating the sum of the squared values, we can use the next commands


-->sum(abs(x)^2)
 ans  =
 
    125.  
 
-->sum(x .* conj(x))
 ans  =
 
    125.  
 
-->x * x'
 ans  =
 
    125.

Notice that the last command makes a dot product between a vector and its conjugate and transpose one.

Finally, if we want to calculate the squared root of the last value we can use the next commands


-->sqrt(x * x')
 ans  =
 
    11.18034  
 
-->norm(x)
 ans  =
 
    11.18034

In summary, although there are several different forms to get the same result we can use the next commands:


abs(x)      // returns the absolute values.
abs(x)^2    // returns the absolute squared values
x * x'      // returns the sum of the absolute squared values
norm(x)     // returns the norm of the vector


next up previous contents
Next: Power Spectrum of a Up: Power Spectrum Previous: Power Spectrum   Contents
je 2006-10-13