Book Image

GNU Octave Beginner's Guide

By : Jesper Schmidt Hansen
Book Image

GNU Octave Beginner's Guide

By: Jesper Schmidt Hansen

Overview of this book

Today, scientific computing and data analysis play an integral part in most scientific disciplines ranging from mathematics and biology to imaging processing and finance. With GNU Octave you have a highly flexible tool that can solve a vast number of such different problems as complex statistical analysis and dynamical system studies.The GNU Octave Beginner's Guide gives you an introduction that enables you to solve and analyze complicated numerical problems. The book is based on numerous concrete examples and at the end of each chapter you will find exercises to test your knowledge. It's easy to learn GNU Octave, with the GNU Octave Beginner's Guide to hand.Using real-world examples the GNU Octave Beginner's Guide will take you through the most important aspects of GNU Octave. This practical guide takes you from the basics where you are introduced to the interpreter to a more advanced level where you will learn how to build your own specialized and highly optimized GNU Octave toolbox package. The book starts by introducing you to work variables like vectors and matrices, demonstrating how to perform simple arithmetic operations on these objects before explaining how to use some of the simple functionality that comes with GNU Octave, including plotting. It then goes on to show you how to write new functionality into GNU Octave and how to make a toolbox package to solve your specific problem. Finally, it demonstrates how to optimize your code and link GNU Octave with C and C++ code enabling you to solve even the most computationally demanding tasks. After reading GNU Octave Beginner's Guide you will be able to use and tailor GNU Octave to solve most numerical problems and perform complicated data analysis with ease.
Table of Contents (15 chapters)
GNU Octave
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface

Time for action - using the fft function


  1. 1. Let us try to Fourier transform the function:

(7.17)

  • where t ∈ [0; 2π] using 150 data points. This function is characterized by two different frequencies (or modes) that will show in the Fourier transformation as two distinct peaks.

2This is also referred to as an O(N2) algorithm. O is pronounced 'big-O'.

  1. 2. To generate the data we use:

octave:29> N=150; t = linspace(0,2*pi, N);
octave:30> f = sin(2*t) + 2*sin(5*t);
  1. 3. Then we simply transform those data via:

octave:31> F = fft(f);
  1. 4. The complex vector F is not really of much information itself, so we often display the absolute value (or magnitude) of the elements in the array:

octave:32> plot(abs(F), "o-")
  • which produces the plot seen in the figure below:

What just happened?

In Commands 29 and 30, we generated the data set. I strongly recommend that you try to plot f versus t to see the function that we are transforming. We then call fft and plot the absolute value of the transformed data...