Module 7.2: nag sym fft Symmetric Discrete Fourier Transforms. Contents

Similar documents
Module 25.2: nag correl Correlation Analysis. Contents

Module 28.3: nag mv rotation Rotations. Contents

Module 5.5: nag sym bnd lin sys Symmetric Banded Systems of Linear Equations. Contents

NAG Library Function Document nag_sum_fft_cosine (c06rfc)

Module 25.1: nag lin reg Regression Analysis. Contents

Module 29.1: nag tsa identify Time Series Analysis Identification. Contents

Module 3.7: nag ell fun Elliptic Functions. Contents

Module 19.1: nag ip Integer Programming. Contents

Module 3.5: nag fresnel intg Fresnel Integrals. Contents

NAG Library Function Document nag_sum_fft_real_3d (c06pyc)

Module 6.4: nag lin lsq Linear Least-squares Problems. Contents

Review More Arrays Modules Final Review

4. Image Retrieval using Transformed Image Content

Digital Signal Processing Lecture Notes 22 November 2010

Digital Signal Processing. Soma Biswas

Unit 4 Graphs of Trigonometric Functions - Classwork

On The Computational Cost of FFT-Based Linear Convolutions. David H. Bailey 07 June 1996 Ref: Not published

Graphing Trig Functions - Sine & Cosine

Fiber Fourier optics

ARRAYS COMPUTER PROGRAMMING. By Zerihun Alemayehu

Practical Exercise 1 Question 1: The Hello World Program Write a Fortran 95 program to write out Hello World on the screen.

Index. C m (Ω), 141 L 2 (Ω) space, 143 p-th order, 17

Trigonometric Functions. Copyright Cengage Learning. All rights reserved.

ENT 315 Medical Signal Processing CHAPTER 3 FAST FOURIER TRANSFORM. Dr. Lim Chee Chin

PACKAGE SPECIFICATION HSL 2013

Fast Fourier Transform (FFT)

2 Unit Bridging Course Day 10

New Basis Functions and Their Applications to PDEs

Allocating Storage for 1-Dimensional Arrays

Study and implementation of computational methods for Differential Equations in heterogeneous systems. Asimina Vouronikoy - Eleni Zisiou

12.4 FFT in Two or More Dimensions

Fathom Dynamic Data TM Version 2 Specifications

Int. Adv. Algebra Geometry Solving a Trig. Function Review Name:

Mathematics Year 9-11 Skills and Knowledge Checklist. Name: Class: Set : Premier Date Year 9 MEG :

Mathematics Year 9-11 Skills and Knowledge Checklist. Name: Class: Set : 1 Date Year 9 MEG :

Chapter 4. Matrix and Vector Operations

The Fast Fourier Transform Algorithm and Its Application in Digital Image Processing

Section 7.6 Graphs of the Sine and Cosine Functions

NAG Library Function Document nag_sum_convcorr_real (c06fkc)

The p-sized partitioning algorithm for fast computation of factorials of numbers

ParaFEM Coding Standard for Fortran 90. Contents. 1.0 Introduction. 2.0 Documentation. 2.1 External Documentation

Chapter 11 Image Processing

Trigonometry LESSON FIVE - Trigonometric Equations Lesson Notes

Susumu Yamamoto. Tokyo, , JAPAN. Fourier Transform (DFT), and the calculation time is in proportion to N logn,

Digital Image Processing. Lecture 6

2 Making Decisions. Store the value 3 in memory location y

7. Procedures and Structured Programming

Curriculum Connections (Fractions): K-8 found at under Planning Supports

Introduction to Programming with Fortran 90

Fast Algorithm for the Modulated Complex Lapped Transform

An efficient multiplierless approximation of the fast Fourier transform using sum-of-powers-of-two (SOPOT) coefficients

Image Processing. Application area chosen because it has very good parallelism and interesting output.

Higher. The Wave Equation. The Wave Equation 146

Matlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name:

Graphing Trigonometric Functions: Day 1

FPGA Implementation of 16-Point Radix-4 Complex FFT Core Using NEDA

Check In before class starts:

Image Transformation Techniques Dr. Rajeev Srivastava Dept. of Computer Engineering, ITBHU, Varanasi

Lecture 5: Frequency Domain Transformations

Fast Orthogonal Neural Networks

Trigonometric Integrals

NAG Library Routine Document D02UCF.1

CONFORMAL MAPPING POTENTIAL FLOW AROUND A WINGSECTION USED AS A TEST CASE FOR THE INVISCID PART OF RANS SOLVERS

An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s.

1.2. Pictorial and Tabular Methods in Descriptive Statistics

Course Outlines. Elementary Mathematics (Grades K-5) Kids and Numbers (Recommended for K-1 students)

Computer Vision 2. SS 18 Dr. Benjamin Guthier Professur für Bildverarbeitung. Computer Vision 2 Dr. Benjamin Guthier

Image Compression System on an FPGA

Introduction to PDEs: Notation, Terminology and Key Concepts

Introduction to Wavelets

Name: Teacher: Pd: Algebra 2/Trig: Trigonometric Graphs (SHORT VERSION)

Development of a Maxwell Equation Solver for Application to Two Fluid Plasma Models. C. Aberle, A. Hakim, and U. Shumlak

Module 9 AUDIO CODING. Version 2 ECE IIT, Kharagpur

Review of Trigonometry

Lecture V: Introduction to parallel programming with Fortran coarrays

Goals for This Lecture:

4.6 GRAPHS OF OTHER TRIGONOMETRIC FUNCTIONS

( ) = 1 4. (Section 4.6: Graphs of Other Trig Functions) Example. Use the Frame Method to graph one cycle of the graph of

Semantics via Syntax. f (4) = if define f (x) =2 x + 55.

Приложение 34 к приказу 949 от 29 сентября 2017 г. MOSCOW AVIATION INSTITUTE (NATIONAL RESEARCH UNIVERSITY)

CCSSM Curriculum Analysis Project Tool 1 Interpreting Functions in Grades 9-12

9 Using Equation Networks

A Quick Review of Trigonometry

On Rainbow Cycles in Edge Colored Complete Graphs. S. Akbari, O. Etesami, H. Mahini, M. Mahmoody. Abstract

This is called the horizontal displacement of also known as the phase shift.

FOURIER MASKING ENCRYPTION ALGORITHM FOR POLYALPHABETIC SYMMETRIC KEY CRYPTOGRAPHY

Module 9 : Numerical Relaying II : DSP Perspective

A Image Comparative Study using DCT, Fast Fourier, Wavelet Transforms and Huffman Algorithm

Dr Richard Greenaway

Maths Curriculum Map - Years 10 and 11 Higher Year 1 Scheme of Work

D01GCF NAG Fortran Library Routine Document

VW 1LQH :HHNV 7KH VWXGHQW LV H[SHFWHG WR

7.4 Image, Tensor Representation, and Fourier Transform

Standards for Mathematics: Grade 1

Chapter P: Preparation for Calculus

Trigonometric ratios provide relationships between the sides and angles of a right angle triangle. The three most commonly used ratios are:

CURRICULUM STRUCTURE Topics Covered Term 1: Term 2: Term 3:

2 3. Syllabus Time Event 9:00{10:00 morning lecture 10:00{10:30 morning break 10:30{12:30 morning practical session 12:30{1:30 lunch break 1:30{2:00 a

Module 4 Graphs of the Circular Functions

F04EBFP.1. NAG Parallel Library Routine Document

Transcription:

Transforms Module Contents Module 7.2: nag sym fft Symmetric Discrete Fourier Transforms nag sym fft provides procedures for computations involving one-dimensional real symmetric discrete Fourier transforms. Contents Introduction... 7.2.3 Procedures nag fft sin... 7.2.5 Single or multiple 1-d discrete Fourier sine transform nag fft cos... 7.2.7 Single or multiple 1-d discrete Fourier cosine transform nag fft qtr sin... 7.2.9 Single or multiple 1-d discrete quarter-wave Fourier sine transform, or its inverse nag fft qtr cos... 7.2.11 Single or multiple 1-d discrete quarter-wave Fourier cosine transform, or its inverse Examples Example 1: Discrete Fourier sine transform of a single 1-d sequence... 7.2.13 Example 2: Discrete Fourier cosine transforms of multiple 1-d sequences... 7.2.15 Example 3: Discrete quarter-wave Fourier sine transforms of multiple 1-d sequences... 7.2.17 Example 4: Discrete quarter-wave Fourier cosine transform of a single 1-d sequence... 7.2.19 Additional Examples... 7.2.21 References... 7.2.22 [NP3245/3/pdf] Module 7.2: nag sym fft 7.2.1

Module Contents Transforms 7.2.2 Module 7.2: nag sym fft [NP3245/3/pdf]

Transforms Module Introduction Introduction 1 The Discrete Fourier Transform (DFT) The one-dimensional DFT of a sequence of n values x j,j =0, 1,...,n 1, is defined in this module by ˆx k = 1 n 1 ( x j exp 2πijk ), (1) n n j=0 for k =0, 1,...,n 1. The original values x j and the transformed values ˆx k are, in general, complex. 2 Real Symmetric Transforms In many applications the sequence x j will not only be real, but may also possess additional symmetries which we may exploit to reduce further the computing time and storage requirements. If the sequence x j is odd (x j = x n j ), then the discrete Fourier transform of x j contains only sine terms. Rather than compute the transform of an odd sequence, we define the discrete sine transform (DST) (Van Loan [7]) of a real sequence by ˆx k = 2 n n 1 ( ) πjk x j sin n j=1,k =1, 2,...,n 1, (2) which could have been computed using the Fourier transform of a real odd sequence of length 2n. In this case the x j are arbitrary, and the symmetry only becomes apparent when the sequence is extended. Similarly we define the discrete cosine transform (also called DCT; see Van Loan [7]) of a real sequence by ˆx k = 2 n n 1 1 2 x 0 + x j cos j=1 ( ) πjk n + 1 2 ( 1)k x n,k=0,...,n, (3) which could have been computed using the Fourier transform of a real even sequence of length 2n. In addition to these half-wave symmetries described above, sequences arise in practice with quarterwave symmetries. We define the discrete quarter-wave sine transform by ˆx k = 1 n 1 ( ) πj(2k 1) x j sin + 1 n 2n 2 ( 1)k 1 x n,k=1,...,n. (4) j=1 Similarly we define the discrete quarter-wave cosine transform by ˆx k = 1 n 1 1 n 2 x ( ) πj(2k 1) 0 + x j cos,k=0,...,n 1. (5) 2n j=1 3 Real Symmetric Inverse Transforms The sine or cosine Fourier transform is its own inverse. The inverse of the quarter-wave sine transform (also called DST-II; see Van Loan [7]) is: x k = 2 n ( ) πk(2j 1) ˆx j sin n 2n j=1 and the inverse of the quarter-wave cosine transform (also called DCT-II; see Van Loan [7]): x k = 2 n 1 ( ) πk(2j 1) ˆx j cos n 2n. (7) j=0 (6) [NP3245/3/pdf] Module 7.2: nag sym fft 7.2.3

Module Introduction Transforms 4 Applications to Solving Partial Differential Equations One application of Fourier transforms of symmetric sequences is in the solution of elliptic partial differential equations. If an equation is discretised using finite differences, then it is sometimes possible to reduce the problem of solving the resulting large system of linear equations to that of solving a number of tridiagonal systems of linear equations. This is accomplished by uncoupling the equations using Fourier transforms, where the nature of the boundary conditions determines the choice of transforms. This approach is used for the solution of the 3-d Helmholtz equation in the module nag pde helm (13.1). Full details of the Fourier method for the solution of partial differential equations may be found in Swarztrauber [4] and Swarztrauber [6]. 5 Trigonometric Coefficients Computing a DFT involves computation of a number of trigonometric coefficients, which can take a significant proportion of the total CPU-time. The procedures in this module can either compute the trigonometric coefficients internally (in which case they are recomputed at each call) or they allow the coefficients to be pre-computed by the procedure nag fft trig from the module nag fft (7.1) and supplied in an optional argument (which is more efficient if several calls are made to compute transforms of the same length). If you are using procedures from this module, and wish to pre-compute the trigonometric coefficients by calling nag fft trig, it is not necessary to add a separate USE statement for the module nag fft (7.1). The procedure nag fft trig is also available through the USE statement for this module. 7.2.4 Module 7.2: nag sym fft [NP3245/3/pdf]

Transforms nag fft sin Procedure: nag fft sin 1 Description nag fft sin returns the discrete Fourier sine transform of order n of either a single sequence or m sequences (all of the same length n 1). The Fourier sine transform is its own inverse and two consecutive calls of this procedure will restore the original data. 2 Usage USE nag sym fft [value =] nag fft sin(x [, optional arguments]) The function result is an array of type real(kind=wp) and the same shape as that of x. 3 Arguments Note. All array arguments are assumed-shape arrays. The extent in each dimension must be exactly that required by the problem. Notation such as x(n) is used in the argument descriptions to specify that the array x must have exactly n elements. This procedure derives the values of the following problem parameters from the shape of the supplied arrays. m 1 the number of sequences to be transformed n 1 the order of the transform (one more than the number of data values in each sequence) 3.1 Mandatory Argument x(n 1) / x(m, n 1) real(kind=wp), intent(in) Input: if x has rank 1, it must hold the single sequence to be transformed. If x has rank 2, it must hold the m sequences to be transformed, with each sequence stored in a row of the array. 3.2 Optional Arguments Note. Optional arguments must be supplied by keyword, not by position. The order in which they are described below may differ from the order in which they occur in the argument list. trig(2n) real(kind=wp), intent(in), optional Input: trigonometric coefficients required for the computation of transforms of order n. Default: if trig is not present, the coefficients are computed internally. Constraints: trig must have been set by a prior call to the procedure nag fft trig from the module nag fft (7.1). This procedure is accessible through the USE statement for this module. error type(nagerror), intent(inout), optional The NAG fl 90 error-handling argument. See the Essential Introduction, or the module document nag error handling (1.2). You are recommended to omit this argument if you are unsure how to use it. If this argument is supplied, it must be initialized by a call to nag set error before this procedure is called. [NP3245/3/pdf] Module 7.2: nag sym fft 7.2.5

nag fft sin Transforms 4 Error Codes Fatal errors (error%level = 3): error%code Description 301 An input argument has an invalid value. 302 An array argument has an invalid shape. 303 Array arguments have inconsistent shapes. 320 The procedure was unable to allocate enough memory. 5 Examples of Usage A complete example of the use of this procedure appears in Example 1 of this module document. 6 Further Comments 6.1 Algorithmic Detail The procedure uses a variant of the fast Fourier transform (FFT) algorithm (see Brigham [1]) known as the Stockham self-sorting algorithm, which is described in Temperton [2] and Temperton [3], together with pre- and post-processing stages described in Swarztrauber [5]. Special coding is provided for the cases where n has factors 2, 3, 4, 5, or 6. 6.2 Accuracy Some indication of accuracy can be obtained by performing a subsequent inverse transform and comparing the results with the original sequence (in exact arithmetic they would be identical). 6.3 Timing The time taken by the procedure is approximately proportional to nm log n, but also depends on the factors of n. The procedure is fastest if the only prime factors of n are 2, 3, and 5, and is particularly slow if n is a large prime, or has large prime factors. If several calls are made to this procedure to compute transforms of the same order n, supplying trigonometric coefficients through the optional argument trig results in a saving of CPU-time. 7.2.6 Module 7.2: nag sym fft [NP3245/3/pdf]

Transforms nag fft cos Procedure: nag fft cos 1 Description nag fft cos returns the discrete Fourier cosine transform of order n of either a single sequence or m sequences (all of the same length n +1). The Fourier cosine transform is its own inverse and two consecutive calls of this procedure will restore the original data. 2 Usage USE nag sym fft [value =] nag fft cos(x [, optional arguments]) The function result is an array of type real(kind=wp) and the same shape as that of x. 3 Arguments Note. All array arguments are assumed-shape arrays. The extent in each dimension must be exactly that required by the problem. Notation such as x(n) is used in the argument descriptions to specify that the array x must have exactly n elements. This procedure derives the values of the following problem parameters from the shape of the supplied arrays. m 1 the number of sequences to be transformed n 1 the order of the transform (one less than the number of data values in each sequence) 3.1 Mandatory Argument x(n +1)/ x(m, n +1) real(kind=wp), intent(in) Input: if x has rank 1, it must hold the single sequence to be transformed. If x has rank 2, it must hold the m sequences to be transformed, with each sequence stored in a row of the array. 3.2 Optional Arguments Note. Optional arguments must be supplied by keyword, not by position. The order in which they are described below may differ from the order in which they occur in the argument list. trig(2n) real(kind=wp), intent(in), optional Input: trigonometric coefficients required for the computation of transforms of order n. Default: if trig is not present, the coefficients are computed internally. Constraints: trig must have been set by a prior call to the procedure nag fft trig from module nag fft (7.1). This procedure is accessible through the USE statement for this module. error type(nagerror), intent(inout), optional The NAG fl 90 error-handling argument. See the Essential Introduction, or the module document nag error handling (1.2). You are recommended to omit this argument if you are unsure how to use it. If this argument is supplied, it must be initialized by a call to nag set error before this procedure is called. [NP3245/3/pdf] Module 7.2: nag sym fft 7.2.7

nag fft cos Transforms 4 Error Codes Fatal errors (error%level = 3): error%code Description 301 An input argument has an invalid value. 302 An array argument has an invalid shape. 303 Array arguments have inconsistent shapes. 320 The procedure was unable to allocate enough memory. 5 Examples of Usage A complete example of the use of this procedure appears in Example 2 of this module document. 6 Further Comments 6.1 Algorithmic Detail The procedure uses a variant of the fast Fourier transform (FFT) algorithm (see Brigham [1]) known as the Stockham self-sorting algorithm, which is described in Temperton [2] and Temperton [3], together with pre- and post-processing stages described in Swarztrauber [5]. Special coding is provided for the cases where n has factors 2, 3, 4, 5, or 6. 6.2 Accuracy Some indication of accuracy can be obtained by performing a subsequent inverse transform and comparing the results with the original sequence (in exact arithmetic they would be identical). 6.3 Timing The time taken by the procedure is approximately proportional to nm log n, but also depends on the factors of n. The procedure is fastest if the only prime factors of n are 2, 3, and 5, and is particularly slow if n is a large prime, or has large prime factors. If several calls are made to this procedure to compute transforms of the same order n, supplying trigonometric coefficients through the optional argument trig results in a saving of CPU-time. 7.2.8 Module 7.2: nag sym fft [NP3245/3/pdf]

Transforms nag fft qtr sin Procedure: nag fft qtr sin 1 Description nag fft qtr sin returns the discrete quarter-wave Fourier sine transform, or its inverse, of either a single sequence or m sequences (all of the same length n). 2 Usage USE nag sym fft [value =] nag fft qtr sin(x [, optional arguments]) The function result is an array of type real(kind=wp) and the same shape as that of x. 3 Arguments Note. All array arguments are assumed-shape arrays. The extent in each dimension must be exactly that required by the problem. Notation such as x(n) is used in the argument descriptions to specify that the array x must have exactly n elements. This procedure derives the values of the following problem parameters from the shape of the supplied arrays. m 1 the number of sequences to be transformed n 1 the number of data values in each sequence 3.1 Mandatory Argument x(n) / x(m, n) real(kind=wp), intent(in) Input: if x has rank 1, it must hold the single sequence to be transformed. If x has rank 2, it must hold the m sequences to be transformed, with each sequence stored in a row of the array. 3.2 Optional Arguments Note. Optional arguments must be supplied by keyword, not by position. The order in which they are described below may differ from the order in which they occur in the argument list. inverse logical, intent(in), optional Input: specifies whether the inverse transform is to be calculated. If inverse =.false., then the forward transform is calculated; if inverse =.true., then the inverse transform is calculated. See Section 2 and Section 3 of the Module Introduction for definitions of the forward quarter-wave sine transform and its inverse, respectively. Default: inverse =.false.. trig(2n) real(kind=wp), intent(in), optional Input: trigonometric coefficients required for the computation of transforms of length n. Default: if trig is not present, the coefficients are computed internally. Constraints: trig must have been set by a prior call to the procedure nag fft trig from module nag fft (7.1). This procedure is accessible through the USE statement for this module. [NP3245/3/pdf] Module 7.2: nag sym fft 7.2.9

nag fft qtr sin Transforms error type(nagerror), intent(inout), optional The NAG fl 90 error-handling argument. See the Essential Introduction, or the module document nag error handling (1.2). You are recommended to omit this argument if you are unsure how to use it. If this argument is supplied, it must be initialized by a call to nag set error before this procedure is called. 4 Error Codes Fatal errors (error%level = 3): error%code Description 301 An input argument has an invalid value. 302 An array argument has an invalid shape. 303 Array arguments have inconsistent shapes. 320 The procedure was unable to allocate enough memory. 5 Examples of Usage A complete example of the use of this procedure appears in Example 3 of this module document. 6 Further Comments 6.1 Algorithmic Detail The procedure uses a variant of the fast Fourier transform (FFT) algorithm (see Brigham [1]) known as the Stockham self-sorting algorithm, which is described in Temperton [2] and Temperton [3], together with pre- and post-processing stages described in Swarztrauber [5]. Special coding is provided for the cases where n has factors 2, 3, 4, 5, or 6. 6.2 Accuracy Some indication of accuracy can be obtained by performing a subsequent inverse transform and comparing the results with the original sequence (in exact arithmetic they would be identical). 6.3 Timing The time taken by the procedure is approximately proportional to nm log n, but also depends on the factors of n. The procedure is fastest if the only prime factors of n are 2, 3, and 5, and is particularly slow if n is a large prime, or has large prime factors. If several calls are made to this procedure to compute transforms of the same length n, supplying trigonometric coefficients through the optional argument trig results in a saving of CPU-time. 7.2.10 Module 7.2: nag sym fft [NP3245/3/pdf]

Transforms nag fft qtr cos Procedure: nag fft qtr cos 1 Description nag fft qtr cos returns the discrete quarter-wave Fourier cosine transform, or its inverse, of either a single sequence or m sequences (all of the same length n). 2 Usage USE nag sym fft [value =] nag fft qtr cos(x [, optional arguments]) The function result is an array of type real(kind=wp) and the same shape as that of x. 3 Arguments Note. All array arguments are assumed-shape arrays. The extent in each dimension must be exactly that required by the problem. Notation such as x(n) is used in the argument descriptions to specify that the array x must have exactly n elements. This procedure derives the values of the following problem parameters from the shape of the supplied arrays. m 1 the number of sequences to be transformed n 1 the number of data values in each sequence 3.1 Mandatory Argument x(n) / x(m, n) real(kind=wp), intent(in) Input: if x has rank 1, it must hold the single sequence to be transformed. If x has rank 2, it must hold the m sequences to be transformed, with each sequence stored in a row of the array. 3.2 Optional Arguments Note. Optional arguments must be supplied by keyword, not by position. The order in which they are described below may differ from the order in which they occur in the argument list. inverse logical, intent(in), optional Input: specifies whether the inverse transform is to be calculated. If inverse =.false., then the forward transform is calculated; if inverse =.true., then the inverse transform is calculated. See Section 2 and Section 3 of the Module Introduction for definitions of the forward quarter-wave cosine transform and its inverse, respectively. Default: inverse =.false.. trig(2n) real(kind=wp), intent(in), optional Input: trigonometric coefficients required for the computation of transforms of length n. Default: if trig is not present, the coefficients are computed internally. Constraints: trig must have been set by a prior call to the procedure nag fft trig from module nag fft (7.1). This procedure is accessible through the USE statement for this module. [NP3245/3/pdf] Module 7.2: nag sym fft 7.2.11

nag fft qtr cos Transforms error type(nagerror), intent(inout), optional The NAG fl 90 error-handling argument. See the Essential Introduction, or the module document nag error handling (1.2). You are recommended to omit this argument if you are unsure how to use it. If this argument is supplied, it must be initialized by a call to nag set error before this procedure is called. 4 Error Codes Fatal errors (error%level = 3): error%code Description 301 An input argument has an invalid value. 302 An array argument has an invalid shape. 303 Array arguments have inconsistent shapes. 320 The procedure was unable to allocate enough memory. 5 Examples of Usage A complete example of the use of this procedure appears in Example 4 of this module document. 6 Further Comments 6.1 Algorithmic Detail The procedure uses a variant of the fast Fourier transform (FFT) algorithm (see Brigham [1]) known as the Stockham self-sorting algorithm, which is described in Temperton [2] and Temperton [3], together with pre- and post-processing stages described in Swarztrauber [5]. Special coding is provided for the cases where n has factors 2, 3, 4, 5, or 6. 6.2 Accuracy Some indication of accuracy can be obtained by performing a subsequent inverse transform and comparing the results with the original sequence (in exact arithmetic they would be identical). 6.3 Timing The time taken by the procedure is approximately proportional to nm log n, but also depends on the factors of n. The procedure is fastest if the only prime factors of n are 2, 3, and 5, and is particularly slow if n is a large prime, or has large prime factors. If several calls are made to this procedure to compute transforms of the same length n, supplying trigonometric coefficients through the optional argument trig results in a saving of CPU-time. 7.2.12 Module 7.2: nag sym fft [NP3245/3/pdf]

Transforms Example 1 Example 1: Discrete Fourier sine transform of a single 1-d sequence This program reads a sequence of real data values and prints its discrete Fourier sine transform. The inverse transform is then calculated and printed out, showing that the original sequence is restored. This example program also shows the use of the procedure nag fft trig from module nag fft (7.1). Note that nag fft trig is accessed through the USE statement for this module. 1 Program Text Note. The listing of the example program presented below is double precision. Single precision users are referred to Section 5.2 of the Essential Introduction for further information. PROGRAM nag_sym_fft_ex01!example Program Text for nag_sym_fft!nag fl90, Release 3. NAG Copyright 1997.!.. Use Statements.. USE nag_examples_io, ONLY : nag_std_in, nag_std_out USE nag_sym_fft, ONLY : nag_fft_sin, nag_fft_trig!.. Implicit None Statement.. IMPLICIT NONE!.. Intrinsic Functions.. INTRINSIC KIND!.. Parameters.. INTEGER, PARAMETER :: wp = KIND(1.0D0)!.. Local Scalars.. INTEGER :: n!.. Local Arrays.. REAL (wp), ALLOCATABLE :: trig(:), x(:), xhat(:)!.. Executable Statements.. Example Program Results for nag_sym_fft_ex01 READ (nag_std_in,*) READ (nag_std_in,*) n!skip heading in data file ALLOCATE (x(n-1),xhat(n-1),trig(2*n))!allocate storage READ (nag_std_in,*) x Original data WRITE (nag_std_out, (7f10.4) ) x CALL nag_fft_trig(trig) xhat = nag_fft_sin(x,trig=trig) Transformed data WRITE (nag_std_out, (7f10.4) ) xhat x = nag_fft_sin(xhat,trig=trig) Original data restored by inverse transform WRITE (nag_std_out, (7f10.4) ) x DEALLOCATE (x,xhat,trig)!deallocate storage [NP3245/3/pdf] Module 7.2: nag sym fft 7.2.13

Example 1 Transforms END PROGRAM nag_sym_fft_ex01 2 Program Data Example Program Data for nag_sym_fft_ex01 8 : n 0.3854 0.6772 0.1138 0.6751 0.6362 0.1424 0.9562 : (z(i),i=1,n-1) 3 Program Results Example Program Results for nag_sym_fft_ex01 Original data 0.3854 0.6772 0.1138 0.6751 0.6362 0.1424 0.9562 Transformed data 1.2305-0.1191 0.4285-0.0242 0.5240-0.6539-0.0242 Original data restored by inverse transform 0.3854 0.6772 0.1138 0.6751 0.6362 0.1424 0.9562 7.2.14 Module 7.2: nag sym fft [NP3245/3/pdf]

Transforms Example 2 Example 2: Discrete Fourier cosine transforms of multiple 1-d sequences This program reads sequences of real data values and prints their discrete Fourier cosine transforms. The inverse transforms are then calculated and printed out, showing that the original sequences are restored. 1 Program Text Note. The listing of the example program presented below is double precision. Single precision users are referred to Section 5.2 of the Essential Introduction for further information. PROGRAM nag_sym_fft_ex02!example Program Text for nag_sym_fft!nag fl90, Release 3. NAG Copyright 1997.!.. Use Statements.. USE nag_examples_io, ONLY : nag_std_in, nag_std_out USE nag_sym_fft, ONLY : nag_fft_cos USE nag_write_mat, ONLY : nag_write_gen_mat!.. Implicit None Statement.. IMPLICIT NONE!.. Intrinsic Functions.. INTRINSIC KIND!.. Parameters.. INTEGER, PARAMETER :: wp = KIND(1.0D0)!.. Local Scalars.. INTEGER :: i, m, n!.. Local Arrays.. REAL (wp), ALLOCATABLE :: x(:,:), xhat(:,:)!.. Executable Statements.. Example Program Results for nag_sym_fft_ex02 READ (nag_std_in,*) READ (nag_std_in,*) m, n!skip heading in data file ALLOCATE (x(m,n+1),xhat(m,n+1))!allocate storage DO i = 1, m READ (nag_std_in,*) x(i,:) END DO CALL nag_write_gen_mat(x,format= f10.4,int_row_labels=.true., & title= Original data ) xhat = nag_fft_cos(x) CALL nag_write_gen_mat(xhat,format= f10.4,int_row_labels=.true., & title= Transformed data ) x = nag_fft_cos(xhat) CALL nag_write_gen_mat(x,format= f10.4,int_row_labels=.true., & title= Original data restored by inverse transform ) DEALLOCATE (x,xhat)!deallocate storage [NP3245/3/pdf] Module 7.2: nag sym fft 7.2.15

Example 2 Transforms END PROGRAM nag_sym_fft_ex02 2 Program Data Example Program Data for nag_sym_fft_ex02 3 6 : m, n 0.3854 0.6772 0.1138 0.6751 0.6362 0.1424 0.9562 : (z(1,i),i=1,n+1) 0.5417 0.2983 0.1181 0.7255 0.8638 0.8723 0.4936 : (z(2,i),i=1,n+1) 0.9172 0.0644 0.6037 0.6430 0.0428 0.4815 0.2057 : (z(3,i),i=1,n+1) 3 Program Results Example Program Results for nag_sym_fft_ex02 Original data 1 0.3854 0.6772 0.1138 0.6751 0.6362 0.1424 0.9562 2 0.5417 0.2983 0.1181 0.7255 0.8638 0.8723 0.4936 3 0.9172 0.0644 0.6037 0.6430 0.0428 0.4815 0.2057 Transformed data 1 1.6833-0.0482 0.0176 0.1368 0.3240-0.5830-0.0427 2 1.9605-0.4884-0.0655 0.4444 0.0964 0.0856-0.2289 3 1.3838 0.1588-0.0761-0.1184 0.3512 0.5759 0.0110 Original data restored by inverse transform 1 0.3854 0.6772 0.1138 0.6751 0.6362 0.1424 0.9562 2 0.5417 0.2983 0.1181 0.7255 0.8638 0.8723 0.4936 3 0.9172 0.0644 0.6037 0.6430 0.0428 0.4815 0.2057 7.2.16 Module 7.2: nag sym fft [NP3245/3/pdf]

Transforms Example 3 Example 3: Discrete quarter-wave Fourier sine transforms of multiple 1-d sequences This program reads sequences of real data values and prints their discrete quarter-wave Fourier sine transforms. The inverse transforms are then calculated and printed out, showing that the original sequences are restored. 1 Program Text Note. The listing of the example program presented below is double precision. Single precision users are referred to Section 5.2 of the Essential Introduction for further information. PROGRAM nag_sym_fft_ex03!example Program Text for nag_sym_fft!nag fl90, Release 3. NAG Copyright 1997.!.. Use Statements.. USE nag_examples_io, ONLY : nag_std_in, nag_std_out USE nag_sym_fft, ONLY : nag_fft_qtr_sin USE nag_write_mat, ONLY : nag_write_gen_mat!.. Implicit None Statement.. IMPLICIT NONE!.. Intrinsic Functions.. INTRINSIC KIND!.. Parameters.. INTEGER, PARAMETER :: wp = KIND(1.0D0)!.. Local Scalars.. INTEGER :: i, m, n!.. Local Arrays.. REAL (wp), ALLOCATABLE :: x(:,:), xhat(:,:)!.. Executable Statements.. Example Program Results for nag_sym_fft_ex03 READ (nag_std_in,*) READ (nag_std_in,*) m, n ALLOCATE (x(m,n),xhat(m,n))!skip heading in data file!allocate storage DO i = 1, m READ (nag_std_in,*) x(i,:) END DO CALL nag_write_gen_mat(x,format= f10.4,int_row_labels=.true., & title= Original data ) xhat = nag_fft_qtr_sin(x) CALL nag_write_gen_mat(xhat,format= f10.4,int_row_labels=.true., & title= Transformed data ) x = nag_fft_qtr_sin(xhat,inverse=.true.) CALL nag_write_gen_mat(x,format= f10.4,int_row_labels=.true., & title= Original data restored by inverse transform ) [NP3245/3/pdf] Module 7.2: nag sym fft 7.2.17

Example 3 Transforms DEALLOCATE (x,xhat)!deallocate storage END PROGRAM nag_sym_fft_ex03 2 Program Data Example Program Data for nag_sym_fft_ex03 3 6 : m, n 0.3854 0.6772 0.1138 0.6751 0.6362 0.1424 : (z(1,i),i=1,n) 0.5417 0.2983 0.1181 0.7255 0.8638 0.8723 : (z(2,i),i=1,n) 0.9172 0.0644 0.6037 0.6430 0.0428 0.4815 : (z(3,i),i=1,n) 3 Program Results Example Program Results for nag_sym_fft_ex03 Original data 1 0.3854 0.6772 0.1138 0.6751 0.6362 0.1424 2 0.5417 0.2983 0.1181 0.7255 0.8638 0.8723 3 0.9172 0.0644 0.6037 0.6430 0.0428 0.4815 Transformed data 1 0.7304 0.2078 0.1150 0.2577-0.2869-0.0815 2 0.9274-0.1152 0.2532 0.2883-0.0026-0.0635 3 0.6268 0.3547 0.0760 0.3078 0.4987-0.0507 Original data restored by inverse transform 1 0.3854 0.6772 0.1138 0.6751 0.6362 0.1424 2 0.5417 0.2983 0.1181 0.7255 0.8638 0.8723 3 0.9172 0.0644 0.6037 0.6430 0.0428 0.4815 7.2.18 Module 7.2: nag sym fft [NP3245/3/pdf]

Transforms Example 4 Example4:Discretequarter-waveFouriercosinetransform of a single 1-d sequence This program reads a sequence of real data values and prints its discrete quarter-wave Fourier cosine transform. The inverse transform is then calculated and printed out, showing that the original sequence is restored. This example program also shows the use of the procedure nag fft trig from module nag fft (7.1). Note that nag fft trig is accessed through the USE statement for nag sym fft. 1 Program Text Note. The listing of the example program presented below is double precision. Single precision users are referred to Section 5.2 of the Essential Introduction for further information. PROGRAM nag_sym_fft_ex04!example Program Text for nag_sym_fft!nag fl90, Release 3. NAG Copyright 1997.!.. Use Statements.. USE nag_examples_io, ONLY : nag_std_in, nag_std_out USE nag_sym_fft, ONLY : nag_fft_qtr_cos, nag_fft_trig!.. Implicit None Statement.. IMPLICIT NONE!.. Intrinsic Functions.. INTRINSIC KIND!.. Parameters.. INTEGER, PARAMETER :: wp = KIND(1.0D0)!.. Local Scalars.. INTEGER :: n!.. Local Arrays.. REAL (wp), ALLOCATABLE :: trig(:), x(:), xhat(:)!.. Executable Statements.. Example Program Results for nag_sym_fft_ex04 READ (nag_std_in,*) READ (nag_std_in,*) n!skip heading in data file ALLOCATE (x(n),xhat(n),trig(2*n))!allocate storage READ (nag_std_in,*) x Original data WRITE (nag_std_out, (7f10.4) ) x CALL nag_fft_trig(trig) xhat = nag_fft_qtr_cos(x,trig=trig) Transformed data WRITE (nag_std_out, (7f10.4) ) xhat x = nag_fft_qtr_cos(xhat,inverse=.true.,trig=trig) Original data restored by inverse transform WRITE (nag_std_out, (7f10.4) ) x DEALLOCATE (x,xhat,trig)!deallocate storage [NP3245/3/pdf] Module 7.2: nag sym fft 7.2.19

Example 4 Transforms END PROGRAM nag_sym_fft_ex04 2 Program Data Example Program Data for nag_sym_fft_ex04 6 : n 0.3854 0.6772 0.1138 0.6751 0.6362 0.1424 : (z(i),i=1,n) 3 Program Results Example Program Results for nag_sym_fft_ex04 Original data 0.3854 0.6772 0.1138 0.6751 0.6362 0.1424 Transformed data 0.7257-0.2216 0.1011 0.2355-0.1406-0.2282 Original data restored by inverse transform 0.3854 0.6772 0.1138 0.6751 0.6362 0.1424 7.2.20 Module 7.2: nag sym fft [NP3245/3/pdf]

Transforms Additional Examples Additional Examples Not all example programs supplied with NAG fl 90 appear in full in this module document. The following additional examples, associated with this module, are available. nag sym fft ex05 Discrete Fourier sine transforms of multiple 1-d sequences nag sym fft ex06 Discrete Fourier cosine transform of a single 1-d sequence nag sym fft ex07 Discrete quarter-wave Fourier sine transform of a single 1-d sequence nag sym fft ex08 Discrete quarter-wave Fourier cosine transforms of multiple 1-d sequences [NP3245/3/pdf] Module 7.2: nag sym fft 7.2.21

References Transforms References [1] Brigham E O (1973) The Fast Fourier Transform Prentice-Hall [2] Temperton C (1983) Fast mixed-radix real Fourier transforms J. Comput. Phys. 52 340 350 [3] Temperton C (1983) Self-sorting mixed-radix fast fourier transforms J. Comput. Phys. 52 1 23 [4] Swarztrauber P N (1977) The methods of cyclic reduction, Fourier analysis and the FACR algorithm for the discrete solution of Poisson s equation on a rectangle SIAM Rev. 19 (3) 490 501 [5] Swarztrauber P N (1982) Vectorizing the FFT s Parallel Computation (ed G Rodrique) Academic Press 51 83 [6] Swarztrauber P N (1984) Fast Poisson solvers Studies in Numerical Analysis (ed G H Golub) Mathematical Association of America [7] Van Loan C (1992) Computational Frameworks for the Fast Fourier Transform SIAM, Philadelphia 7.2.22 Module 7.2: nag sym fft [NP3245/3/pdf]