V(t) = Total Power = Calculating the Power Spectral Density (PSD) in IDL. Thomas Ferree, Ph.D. August 23, 1999

Similar documents
Vibration Testing. an excitation source a device to measure the response a digital signal processor to analyze the system response

Vibration Testing. Typically either instrumented hammers or shakers are used.

Adjustments for the Display of Quantized Ion Channel Dwell Times in Histograms with Logarithmic Bins

Fig. 1: Fourier series Examples

SNR Calculation and Spectral Estimation [S&T Appendix A]

Correlation, discrete Fourier transforms and the power spectral density

sinc function T=1 sec T=2 sec angle(f(w)) angle(f(w))

Signal Processing COS 323

UCSD SIO221c: (Gille) 1

12.1 Fourier Transform of Discretely Sampled Data

ANALOG AND DIGITAL SIGNAL PROCESSING ADSP - Chapter 8

SHOCK AND VIBRATION RESPONSE SPECTRA COURSE Unit 7A. Power Spectral Density Function

Chapter 4 Discrete Fourier Transform (DFT) And Signal Spectrum

Review: Continuous Fourier Transform

E2.5 Signals & Linear Systems. Tutorial Sheet 1 Introduction to Signals & Systems (Lectures 1 & 2)

Computational Data Analysis!

Chapter 3. Data Analysis

Centre for Mathematical Sciences HT 2017 Mathematical Statistics

Image Acquisition and Sampling Theory

Experimental Fourier Transforms

Degrees-of-freedom estimation in the Student-t noise model.

Information and Communications Security: Encryption and Information Hiding

which arises when we compute the orthogonal projection of a vector y in a subspace with an orthogonal basis. Hence assume that P y = A ij = x j, x i

Data Sampling Techniques for Fourier Analysis

Fourier transforms of molecular vibrations

Chapter 2 Fourier Series Phase Object Spectra

SEISMIC WAVE PROPAGATION. Lecture 2: Fourier Analysis

IB Paper 6: Signal and Data Analysis

2.161 Signal Processing: Continuous and Discrete Fall 2008

Jim Lambers ENERGY 281 Spring Quarter Lecture 5 Notes

Review of Linear System Theory

Linear Equations in Linear Algebra

2.161 Signal Processing: Continuous and Discrete Fall 2008

chapter 12 MORE MATRIX ALGEBRA 12.1 Systems of Linear Equations GOALS

Error Reporting Recommendations: A Report of the Standards and Criteria Committee

Computer Vision Lecture 3

Lecture 3: Linear Filters

The Discrete Fourier Transform

The discrete Fourier transform

INTRODUCTION TO THE DFS AND THE DFT

Each of these functions represents a signal in terms of its spectral components in the frequency domain.

Notes on FFT-based differentiation

Tutorial Sheet #2 discrete vs. continuous functions, periodicity, sampling

The Hilbert Transform

Review of Linear Systems Theory

ECG782: Multidimensional Digital Signal Processing

VII. Bandwidth Limited Time Series

FFT, total energy, and energy spectral density computations in MATLAB Aaron Scher

L6: Short-time Fourier analysis and synthesis

Lecture 3: Linear Filters

Fourier analysis of discrete-time signals. (Lathi Chapt. 10 and these slides)

Topic 3: Fourier Series (FS)

Math 56 Homework 5 Michael Downs

A523 Signal Modeling, Statistical Inference and Data Mining in Astrophysics Spring 2011

ω 0 = 2π/T 0 is called the fundamental angular frequency and ω 2 = 2ω 0 is called the

Bernstein polynomials of degree N are defined by

1. Introduction to commutative rings and fields

Fourier Analysis of Signals Using the DFT

Scientific Computing: An Introductory Survey

Spectra (2A) Young Won Lim 11/8/12

EEO 401 Digital Signal Processing Prof. Mark Fowler

Transform Representation of Signals

This pre-publication material is for review purposes only. Any typographical or technical errors will be corrected prior to publication.

Chirp Transform for FFT

The Simplex Method: An Example

System Modeling and Identification CHBE 702 Korea University Prof. Dae Ryook Yang

CS711008Z Algorithm Design and Analysis

ENGIN 100: Music Signal Processing. LAB #5: Spectrograms

1.4 Fourier Analysis. Random Data 17

The Discrete Fourier Transform (DFT) Properties of the DFT DFT-Specic Properties Power spectrum estimate. Alex Sheremet.

Examples of linear systems and explanation of the term linear. is also a solution to this equation.

In this Lecture. Frequency domain analysis

DHANALAKSHMI COLLEGE OF ENGINEERING DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING EC2314- DIGITAL SIGNAL PROCESSING UNIT I INTRODUCTION PART A

Discrete Wavelet Transform

Fourier Series. (Com S 477/577 Notes) Yan-Bin Jia. Nov 29, 2016

E : Lecture 1 Introduction

Lecture 20: Discrete Fourier Transform and FFT

DOING PHYSICS WITH MATLAB FOURIER ANALYSIS FOURIER TRANSFORMS

/ (2π) X(e jω ) dω. 4. An 8 point sequence is given by x(n) = {2,2,2,2,1,1,1,1}. Compute 8 point DFT of x(n) by

Engineering Physics 3W4 "Acquisition and Analysis of Experimental Information" Part II: Fourier Transforms

Numerical Methods I Orthogonal Polynomials

Radar Systems Engineering Lecture 3 Review of Signals, Systems and Digital Signal Processing

OSE801 Engineering System Identification. Lecture 05: Fourier Analysis

Designing Information Devices and Systems I Spring 2018 Lecture Notes Note Introduction to Linear Algebra the EECS Way

INTRODUCTION TO DELTA-SIGMA ADCS

Continuous Time Signal Analysis: the Fourier Transform. Lathi Chapter 4

Some of the different forms of a signal, obtained by transformations, are shown in the figure. jwt e z. jwt z e

Math Precalculus I University of Hawai i at Mānoa Spring

000=0 001=1 010=2 011=3 100=4 101=5 110=6 111=7 000=0 100=4 010=2 110=6 001=1 101=5 011=3 111=7

Time and Spatial Series and Transforms

Signals, Instruments, and Systems W5. Introduction to Signal Processing Sampling, Reconstruction, and Filters

6.003: Signal Processing

In-Structure Response Spectra Development Using Complex Frequency Analysis Method

Department of Electrical and Telecommunications Engineering Technology TEL (718) FAX: (718) Courses Description:

1. Introduction to commutative rings and fields

Lecture 7 Random Signal Analysis

The discrete and fast Fourier transforms

Sampling in 1D ( ) Continuous time signal f(t) Discrete time signal. f(t) comb

EE 435. Lecture 32. Spectral Performance Windowing

Distortion Analysis T

Transcription:

Calculating the Power Spectral Density (PSD) in IDL Thomas Ferree, Ph.D. August 23, 1999 This note outlines the calculation of power spectra via the fast Fourier transform (FFT) algorithm. There are several variants of the definition of the power of a signal V(t), distinguished mainly by their normalizations. Emphasis is placed on correct inclusion of negative frequency components within the FFT calculational framework, and on defining the PSD to be intensive so that it is independent of frequency bin size. Other topics such as windowing, averaging and padding to increase resolution are discussed briefly. IDL conventions are used throughout for array indexing and in defining the FFT. Continuous signals Time domain definition of total power To understand the definition of signal power, it is helpful to first consider the ideal situation in which we have an infinite amount of continuously sampled data. Given a continous time series V(t), the total power in the signal is usually defined in the time domain as The first thing to note about this definition is that it has units of [V] 2 sec, where [V] represents the units of the signal V(t). This is different than the familiar physics definition of power, which is mechanical, and has units of energy per unit time. Continuous Fourier transform Power By introducing the continuous Fourier transform (FT) V(t) 2 dt and its inverse V ( f ) = V(t) = V(t)e V ( f )e 2πi f t +2πi f t dt df it is straightforward to show that Total Power = V ( f ) 2 df 1

Together with the definition of total power given above, this is called Parseval s theorem, and it shows that the total power can equivalently be computed as an integral over all frequency components. This suggests that we define a power spectral density (PSD) function The term density is used in this context to mean that the PSD is intensive with respect to frequency, i.e., it does not scale linearly with the frequency bin size df, since the factor of df appearing in the total power has been factored from the definition of PSD. The superscript is meant to indicate that this is a two-sided PSD, which must be integrated over both positive and negative frequencies to retrieve the total power. The presence of both positive and negative frequencies in Parseval s theorem is a crucial issue. To begin with, the negative frequencies are not distinguished physically from positive frrequencies, but have their origin in the definition of the inverse FT. Negative frequencies are essential in an exponential representation of the FT, in the sense that they are necessary for the set of Fourier basis functions to comprise a complete set capable of characterizing an arbitrary time series. The two-sided PSD is a fine definition, provided that one knows how to interpret it. When one speaks of power at a particular frequency, however, one usually does not intend to distinguish between positive and negative frequencies. This suggests an alternative definition of PSD which is defined over positive frequencies f> only. The superscript indicates that this is a one-sided PSD, which gives the total signal power when integrated over positive frequencies only. As a further simplification, it can be seen from the definition of the FT that for real (not complex) signals Thus for continuously sampled real signals, the negative frequency components can be accounted for simply by including a factor of two in the definition of the one-sided PSD. This one-sided PSD obeys a different normalization condition to retrieve the total power. Discrete signals PSD (±) ( f ) = V ( f ) 2 PSD (+) ( f ) = V ( f ) 2 + V ( f ) 2 V ( f ) = Total Power = [ V ( f )] * PSD (+ ) ( f )df Now consider the realistic situation in which V(t) is sampled at only N time points t j = j t, j=,..., N 1 2

We assume that the sampling rate is given. For example, EGI s data acquisition software typically collects 25 or 5 samples per second, depending on the experimental protocol. The total time elapsed between the first and last data points is T = (N 1) t although this is never actually used in what follows. In what follows, we assume that N is even. In practice, N should be an integer power of 2 for the FFT algorithm to be most efficient. The corresponding discrete positive and negative frequencies are f k = k f, k = N 2,...,,..., + N 2 where the frequency bin size is f = 1 N t The maximum meaningful frequency is called the Nyquist frequency and occurs when k=+n/2 or k=-n/2. The standard tool for signal processing of discretely sampled data, however, is the fast Fourier transform (FFT). IDL defines the FFT as and the corresponding inverse FFT as V (k) 1 N f c = 1 2 t N 1 Note from the inverse transform that the discrete frequency index k=,,n-1, i.e., runs over nonnegative values only, and that those values extend beyond the Nyquist frequency. This is merely a matter of convenience in how the frequency information is stored in the FFT, because in most computer languages it is inconvenient to declare arrays with negative indices. Clearly the numbers stored in bins above the Nyquist bin (k=n/2) do not reflect spectral content of the data above the Nyquist frequency, since the FFT only samples the signal up to the Nyquist frequency. Rather, it is straightforward to show from the definition of the FFT that for a real signal V(t) V (N k) = N 1 j= V( j) e 2πi j k / N V( j) V (k) e +2πi j k / N k = [ V (k)] * = 3 V ( k)

for k=1,,n/2-1. In other words, the information stored in the upper half of the FFT array is redundant with that stored in the lower half, and corresponds exactly to the negative frequency components already discussed in the context of continuously sampled signals. Note also that the units of the FFT are different than those of the FT, since the FFT contains no factor of dt. This will be relevant for making a discrete definition of the PSD. Note also the factor of 1/N which appears in the FFT, but not in the FT. This is the IDL normalization convention for the FFT, and is different from that adopted in MATLAB (Stearns and David, 1996) and Numerical Recipes in C (Press et al., 1992). Mathematically, the 1/N can appear in either the FFT or the inverse FFT, since the only requirement is that the original signal V(t) be retrieved when the transform and inverse transform are applied sequentially. Its presence is therefore not a major issue, but it must be accounted for when defining the PSD via the FFT. We are now in a position to approach the definition of power spectral density for discrete signals. To maintain consistency with continuously sampled signals, and to arrive at an intensive definition of discree PSD, the total power of a discrete signal can be defined as To motivate a discrete definition of PSD, we again invoke Parseval s theorem. It is straightforward to show from the IDL definition of FFT that the discrete signal V(j) and its FFT obey a discrete form of Parseval s theorem N 1 V( j) 2 = N V (k) 2 j= N 1 Total Power V( j) 2 t j = where the sum on the right hand side runs over all frequency bins of the FFT. This is a crucial point: to compute the total signal power one must sum over all components of the FFT, where the bins above the Nyquist bin correspond to negative frequencies. Multiplying both sides by t yields a frequency-space definition of the total power: Total Power = N t N 1 In the second equality, we have used the definition of f, and introduced another factor of f in the numerator and denominator to make the right hand side look like that for continuously sampled data. This suggests that we define a two-sided PSD for discrete signals as N 1 k= V (k) 2 = k= N 1 k = V (k) 2 ( f ) 2 f PSD (±) (k) = 4 V (k) 2 ( f ) 2

To portray the total power in the frequency domain, one can plot this quantity symmetrically about zero frequency. Recognizing the redundancy of information in the FFT for real signals, and in an an attempt to simplify the plot of this quantity, many researchers plot this function only over values of k=,,n/2, i.e., up to the Nyquist frequency. This definition is awkward, however, for the same reasons as for continuous signals. Moreover, and most importantly, this awkwardness can not be remedied simply by introducing an overall factor of two, as was the case for continuous signals. This is because the bin (k=) centered on zero frequency, and the bin (k=n/2) centered on the Nyquist frequency, are not included in the redundant information. To define a properly normalized one-sided PSD, therefore, it is common to write PSD (+) () = PSD (+) (k) = PSD (+) (N / 2) = V () 2 ( f ) 2 Press et al. (1992). This definition has the desired property that summing over k=,,n/2 gives the total power, i.e., Total Power = V (k) 2 + V (N k) 2 ( f ) 2, k =1,..., N / 2 1 V (N / 2) 2 N /2 k = ( f ) 2 PSD (+) (k) f as required for straightfoward interpretation of the power at various frequencies. For real signals this definition results in a factor of two for all bins except those at k= and k=n/2. The distinction between the k= and k=n/2 bins versus all the other bins is essential if one wishes to quantify absolute power in a particular bin, or to compare power in neighboring bins where one of those bins corresponds to the lowest sampled frequency, i.e., k=. (Comparing the power in the Nyquist bin with its neighbors is seldom useful, since one normally assumes that the input signal has been low-pass filtered before sampling to eliminate aliasing, and that no meaningful information is present near the Nyquist bin.) Figure 1 shows the effect of computing the one-sided PSD correctly for discrete signals. Figure 1a shows a typical EEG time series consisting of 256 points, collected at 1/ t=25 samples/sec. Figure 1b shows the two-sided PSD amplitude (defined as the square root of the two-sided PSD for improved visualization), plotted over values k=,,n/2. Figure 1c shows the one-sided PSD amplitude, plotted over the same range. Note that in Figure 1b, the power in the second frequency bin (ranging from.5 to 1.5 Hz, but plotted as a single point at f=1 Hz) is slightly lower than the first frequency bin (ranging from.5 to.5 Hz, but plotted as a single point at f=). Calculation of the one-sided PSD in Figure 1c doubles the power in the second bin, without affecting the power in the first bin. (The 5

increase seen in the plot is actually only a factor of 1.41, due to the square root in the definition of PSD amplitude.) Thus the one-sided PSD shows a peak at nonzero frequencies, which would not have been identified properly in the two-sided PSD without deliberate mental calculation on the part of the reader. We assert that the one-sided PSD is much easier to interpret. The one-sided PSD in implemented in EGI s spectral analysis tools. 5 Raw EEG Data 15 Two-sided PSD Amplitude One-sided PSD Amplitude 15 4 3 2 1 1 1-1 -2 5 5-3 -4-5.5 1 t (sec) 1 2 1 2 Figure 1. (a) Raw EEG data, (b) two-sided PSD, and (c) one-sided PSD. Windowing As discussed in Press et al. (1992), having finite width frequency bins f, a direct consequence of having a finite recording interval T, results in artifacts in PSD estimation. Given the sampling interval t and the number of data points N, the discrete frequencies and their bin size f are determined. If the input signal has a single frequency which falls in the center of a bin, then the power of the signal will be represented entirely within that bin. In contrast, if the input signal has a single frequency which is not centered in a bin, which is the general case for EEG data, the power of the signal will be spread to many neighboring bins (Press et al., 1992). This effect can be minimized by windowing. Windowing refers to multiplying the input signal V(t) by a window function w(t), which is zero at the ends of the recording interval, and unity in the center. A common choice is the Hanning window 6

which is implemented in EGI s spectral analysis tools. Averaging As another means of improving the approximation of the PSD from discretely sampled data, we can invoke averaging. The original data set of length N is first segmented into M smaller data segments each of length L. After computing the FFT and discrete PSD for each segment, an average PSD is computed by averaging the power in each frequency bin over the M segments. Averaging capability is implemented in EGI s spectral analysis tools. Padding w( j) = 1 2π j 1 cos 2 N, j=,..., N 1 As descussed above, if N data points sampled at a rate 1/ t are fed to an FFT algorithm, one obtains values which correspond to the DFT at the discrete frequencies f=1/(n t). This seems to imply that the frequency resolution of the FFT is limited by the length of the time segment of data that one wishes to analyze, which could be a restriction if one is interested in studying changes in the PSD over time. A little-known fact is that this situation can be improved by padding the original data set with zeros. Since it seems at first glance that this would violate some conservation principle, a brief discussion of is in order. First, it is possible in principle to compute the discrete Fourier transform (DFT) for a finite data set at any frequency. The disadvantage is that the sum over the original data must then be computed explicitly, rather than via the highly efficient FFT algorithm. Second, padding with zeros does not change the value of the FFT at a particular frequency, since the additional terms included in the sum are all equal to zero. (A exception is due to the factor 1/N in the IDL defintion of FFT, but this is taken care of in our definition of PSD.) What padding does do, however, is force the FFT to evaluate the DFT at twice as many frequencies. These new frequencies all still lie between zero and the Nyquist, but there are twice as many of them, hence twice the frequency resolution. In order for the PSD to remain unchanged, however, it must be defined as an intensive quantity, as above. To demonstrate the effect of padding, Figure 2 shows the PSD for the same data set shown in Figure 1, but now plotted only to 1 Hz. Figure 2a shows the PSD computed for N=256 and no padding, resulting in a frequency resolution of f=1 Hz. Figure 2b shows the PSD computed for the same data set padded with 256 zeros, resulting in a frequency resolution of f=.5 Hz. Notice the value of the PSD at integer frequencies, e.g., and 1 Hz, are unchanged, however, as a consequence of making an intensive definition of the PSD. Figure 2c shows the PSD computed for the same data set padded with 234 zeros, resulting in a frequency resolution of f=.1 Hz. This clearly shows structure in the PSD which could not have been inferred at lower resolutions obtained without padding. For example, the niche between.5 and 1 Hz seen in Figure 2c was completely missed at lower resolutions. At the highest resolution, in Figure 2c, the point at zero frequency appears to be discontinuous with the rest of the spectrum at low frequencies. Indeed, the ratio of the first point to the zeroth point is 1.41 to a good approximation, and clearly has its origin in our definition of a one-sided PSD. While this appears 7

to be a disadvantage to the one-sided definition of PSD, this definition has the advantage that the plot accurately portrays the total signal power. 15 One-Sided PSDA 15 One-Sided PSDA 15 One-Sided PSDA 1 1 1 5 5 5 5 1 5 1 5 1 Padding and Windowing Figure 2. (a) no padding, (b) single padding, and (c) nine-fold padding. If combining methods, windowing should be performed before padding to have the desired effect. This is because the effect of windowing in the time domain is to force both ends of the data to zero in a smooth way. If windowing were applied to the augmented data set after padding, then the last nonzero data point would align with the window in such a way that it would not be forced smoothly to zero as desired. References Press, W. H., S.A. Teukolsky, W. T. Vetterling and B. P. Flannery (1992). Numerical recipes in C: The art of scientific computing. Cambridge University Press. 8

Stearns, S. D. and R. A. David (1996). Signal processing algorithms in MATLAB. Prentice-Hall, New Jersey. 9