FFT analysis in practice

Similar documents
Advanced Audiovisual Processing Expected Background

Final Exam Practice Questions for Music 421, with Solutions

Topic 6. The Digital Fourier Transform. (Based, in part, on The Scientist and Engineer's Guide to Digital Signal Processing by Steven Smith)

URBANA-CHAMPAIGN. CS 498PS Audio Computing Lab. Audio DSP basics. Paris Smaragdis. paris.cs.illinois.

Topic 2. Signal Processing Review. (Some slides are adapted from Bryan Pardo s course slides on Machine Perception of Music)

Lecture 3 Complex Exponential Signals

Chapter 5 Window Functions. periodic with a period of N (number of samples). This is observed in table (3.1).

ME scope Application Note 01 The FFT, Leakage, and Windowing

Discrete Fourier Transform (DFT)

Notes on Fourier transforms

Short-Time Fourier Transform and Its Inverse

The Fast Fourier Transform

EE 215 Semester Project SPECTRAL ANALYSIS USING FOURIER TRANSFORM

Signal Processing. Naureen Ghani. December 9, 2017

DISCRETE FOURIER TRANSFORM AND FILTER DESIGN

DFT: Discrete Fourier Transform & Linear Signal Processing

Signal processing preliminaries

CSC475 Music Information Retrieval

LABORATORY - FREQUENCY ANALYSIS OF DISCRETE-TIME SIGNALS

Lab 8. Signal Analysis Using Matlab Simulink

Design of FIR Filters

Frequency Division Multiplexing Spring 2011 Lecture #14. Sinusoids and LTI Systems. Periodic Sequences. x[n] = x[n + N]

Digital Filters IIR (& Their Corresponding Analog Filters) Week Date Lecture Title

G(f ) = g(t) dt. e i2πft. = cos(2πf t) + i sin(2πf t)

Filter Banks I. Prof. Dr. Gerald Schuller. Fraunhofer IDMT & Ilmenau University of Technology Ilmenau, Germany. Fraunhofer IDMT

Biomedical Signals. Signals and Images in Medicine Dr Nabeel Anwar

Multirate Signal Processing Lecture 7, Sampling Gerald Schuller, TU Ilmenau

Topic. Spectrogram Chromagram Cesptrogram. Bryan Pardo, 2008, Northwestern University EECS 352: Machine Perception of Music and Audio

Lecture 5: Sinusoidal Modeling

SAMPLING THEORY. Representing continuous signals with discrete numbers

speech signal S(n). This involves a transformation of S(n) into another signal or a set of signals

Laboratory Assignment 4. Fourier Sound Synthesis

The Polyphase Filter Bank Technique

Discrete Fourier Transform, DFT Input: N time samples

Lecture 3, Multirate Signal Processing

Lecture Schedule: Week Date Lecture Title

Lab 18 Delay Lines. m208w2014. Setup. Delay Lines

Hideo Okawara s Mixed Signal Lecture Series. DSP-Based Testing Fundamentals 14 FIR Filter

PART II Practical problems in the spectral analysis of speech signals

PROBLEM SET 6. Note: This version is preliminary in that it does not yet have instructions for uploading the MATLAB problems.

Fourier Transform Pairs

Digital Signal Processing

(i) Understanding of the characteristics of linear-phase finite impulse response (FIR) filters

Signal Processing for Speech Applications - Part 2-1. Signal Processing For Speech Applications - Part 2

PART I: The questions in Part I refer to the aliasing portion of the procedure as outlined in the lab manual.

Concordia University. Discrete-Time Signal Processing. Lab Manual (ELEC442) Dr. Wei-Ping Zhu

Lecture 7 Frequency Modulation

Spectrum Analysis - Elektronikpraktikum

(i) Understanding of the characteristics of linear-phase finite impulse response (FIR) filters

Signals and Systems Using MATLAB

Basic Signals and Systems

Sound Synthesis Methods

It is the speed and discrete nature of the FFT that allows us to analyze a signal's spectrum with MATLAB.

Sound synthesis with Pure Data

Chapter Three. The Discrete Fourier Transform

Sampling and Signal Processing

FIR/Convolution. Visulalizing the convolution sum. Convolution

Digital Video and Audio Processing. Winter term 2002/ 2003 Computer-based exercises

Signal Processing Toolbox

L19: Prosodic modification of speech

Lab 4 Fourier Series and the Gibbs Phenomenon

Signals. Continuous valued or discrete valued Can the signal take any value or only discrete values?

ECE438 - Laboratory 7a: Digital Filter Design (Week 1) By Prof. Charles Bouman and Prof. Mireille Boutin Fall 2015

Frequency Domain Representation of Signals

Chapter 4. Digital Audio Representation CS 3570

6 Sampling. Sampling. The principles of sampling, especially the benefits of coherent sampling

Problem Set 1 (Solutions are due Mon )

International Journal of Modern Trends in Engineering and Research e-issn No.: , Date: 2-4 July, 2015

Final Exam Solutions June 14, 2006

Module 3 : Sampling and Reconstruction Problem Set 3

Additive Synthesis OBJECTIVES BACKGROUND

Digital Filters FIR and IIR Systems

Speech Signal Analysis

Wavelet Transform. From C. Valens article, A Really Friendly Guide to Wavelets, 1999

Window Functions And Time-Domain Plotting In HFSS And SIwave

Hideo Okawara s Mixed Signal Lecture Series. DSP-Based Testing Fundamentals 13 Inverse FFT

The Discrete Fourier Transform. Claudia Feregrino-Uribe, Alicia Morales-Reyes Original material: Dr. René Cumplido

TWO-DIMENSIONAL FOURIER PROCESSING OF RASTERISED AUDIO

Hideo Okawara s Mixed Signal Lecture Series. DSP-Based Testing Fundamentals 6 Spectrum Analysis -- FFT

EE123 Digital Signal Processing

ESE531 Spring University of Pennsylvania Department of Electrical and System Engineering Digital Signal Processing

Sampling and Reconstruction of Analog Signals

EE 464 Short-Time Fourier Transform Fall and Spectrogram. Many signals of importance have spectral content that

Objectives. Abstract. This PRO Lesson will examine the Fast Fourier Transformation (FFT) as follows:

The Fundamentals of Mixed Signal Testing

COMPUTATIONAL RHYTHM AND BEAT ANALYSIS Nicholas Berkner. University of Rochester

VIBRATO DETECTING ALGORITHM IN REAL TIME. Minhao Zhang, Xinzhao Liu. University of Rochester Department of Electrical and Computer Engineering

Department of Electronic Engineering NED University of Engineering & Technology. LABORATORY WORKBOOK For the Course SIGNALS & SYSTEMS (TC-202)

B.Tech III Year II Semester (R13) Regular & Supplementary Examinations May/June 2017 DIGITAL SIGNAL PROCESSING (Common to ECE and EIE)

CMPT 468: Delay Effects

THE CITADEL THE MILITARY COLLEGE OF SOUTH CAROLINA. Department of Electrical and Computer Engineering. ELEC 423 Digital Signal Processing

FIR/Convolution. Visulalizing the convolution sum. Frequency-Domain (Fast) Convolution

EE 791 EEG-5 Measures of EEG Dynamic Properties

ECE 484 Digital Image Processing Lec 09 - Image Resampling

Linguistic Phonetics. Spectral Analysis

Speech Enhancement Using Spectral Flatness Measure Based Spectral Subtraction

Project 0: Part 2 A second hands-on lab on Speech Processing Frequency-domain processing

Spring 2018 EE 445S Real-Time Digital Signal Processing Laboratory Prof. Evans. Homework #1 Sinusoids, Transforms and Transfer Functions

CS3291: Digital Signal Processing

FFT Convolution. The Overlap-Add Method

Transcription:

FFT analysis in practice Perception & Multimedia Computing Lecture 13 Rebecca Fiebrink Lecturer, Department of Computing Goldsmiths, University of London 1

Last Week Review of complex numbers: rectangular and polar representations The complex exponential The Fourier Series and Discrete Fourier Transform (DFT) The Fast Fourier Transform (FFT) Lab: Understanding convolution and systems through hands-on practice Signals and convolution in R 2

Today Brief lab discussion (more tomorrow) Brief coursework discussion Using FFT in practice Choosing parameters and interpreting output Short-time Fourier Transform Example applications Variants of Fourier transform 3

Lab discussion Convolution by hand: Examples h=[3,2,4] : same as [3, 0, 0] + [0, 2, 0] + [0, 0, 4] same as 3[1] + 2[0, 1] + 4[0, 0, 1] same as 3[1] + 2T 1 {[1]} + 4T 2 {[1]} x h = x 3[1] + x 2T 1 {[1]} + x 4T 2 {[1]} Example on board 4

5 The FFT in Practice

Fast Fourier Transform (FFT) Review Given a signal, what is its frequency content? Helps us understand audio content (pitch, timbre, melody, rhythm, genre, speech, ) Also a building block for designing and understanding effects (filters, equalization, reverb, echo) One of the most powerful and useful techniques for working with audio, image, and video! 6

Fast Fourier Transform (FFT) Review Equation: 7 Essentially, dot-product multiply our signal x with complex exponentials with periods of N, N/ 2, N/3, 2 samples (i.e., frequencies of 1/N, 2/N, 3/N, 1/2 oscillations per sample), as well as DC component

Fast Fourier Transform (FFT) Review 8 Each X k is a complex number (e.g., 10+5i, or 3 π/2) If the k th frequency is present in the signal, X k will have non-zero magnitude, and its magnitude and phase will tell us how much of that frequency is present and at what phase (though not directly)

Viewing FFT output 1) Spectrum 9

Viewing FFT output 2) Spectrogram 10

What will you hear? 11

What will you hear? 12

What will you hear? 13

What is really output N-point FFT computes N complex values X 0 to X N-1, representing frequencies of 0Hz to (N-1/N * SampleRate) 0Hz, (1/N)*SR, (2/N)*SR, (N/2)/N*SR, (N-1)/N*SR =1/2*SR (Nyquist) These frequencies often called bins of FFT Note that adjacent bins are (1/N)*SR apart 14

Bins above Nyquist are redundant Magnitude spectrum is symmetric around the Nyquist frequency: 15

Bins above Nyquist are redundant Magnitude spectrum is symmetric around the Nyquist frequency: 16

Bins above Nyquist are redundant Bin k is complex conjugate of bin N-k: Complex conjugates (equal in magnitude, opposite in phase) 17

Bins above Nyquist are redundant Bin k is complex conjugate of bin N-k: phases of these bins are flipped 18

Why??? If your input is a real-valued sinusoid, FFT decomposes it into one phasor rotating clockwise and one rotating counterclockwise, at the same frequency. + 19

Practical takeaway so far: You only need to use bins 0 to N/2 for analysis, assuming your input signal is realvalued (and not complex-valued: always true for audio) There are specific, simple relationships between magnitudes & phases of these first N/2+1 bins and the rest of the bins. 20

Converting from bin # to frequency in Hz N bins of FFT evenly divide frequencies from 0 Hz to (N-1)/N * SR Why not up to sample rate itself? SR indistinguishable from 0Hz! 21 We re chopping frequencies from 0 up to (but not including) the sample rate into N bins, SO consecutive bins are (1/N)*SR apart

Width of spectrum bins Magnitude f Δf = f max /N = SampleRate /N 22

Example 23 I take an FFT of 128 samples; my sample rate is 1000Hz. N = 128; I have 128 bins. Bin 0 is? (assuming indexing starting w/ 0) 0 Hz Bin 1 is? (1/128) * 1000 7.8 Hz Bin 2 is? (2/128) * 1000 15.6 Hz

Example 24 I take an FFT of 128 samples; my sample rate is 1000Hz. N = 128; I have 128 bins. 14 th bin is? (14/128) * 1000 109 Hz Bins nearest to 300 Hz are? (b/128) * 1000 = 300! b = 38.4 bins 38 and 39 are closest Last bin I care about is? Nyquist: (b/128)*1000 = 500! b = 64 (equivalently, equal to N/2)

What happens if my signal contains a frequency that s not exactly equal to the center frequency of a bin? This frequency will leak into nearby bins. 25

26 SR = 100Hz, sine at 24 Hz

27 SR = 100Hz, sine at 25 Hz

28 SR = 100Hz, sine at 24.5 Hz

How many bins to use? (What should N be?) More bins? Better frequency resolution Worse time resolution (FFT can t detect changes within the analysis frame) Fewer bins? Worse frequency resolution Better time resolution 29

Time/Frequency tradeoff 30 N=64 N=4096

31

32

What s all that extra stuff in the spectrum? 33 Not just clean peaks at frequencies and 0 elsewhere

Reasons for this stuff FFT treats your analysis frame as one period of an infinite, periodic signal. 34 Signal doesn t have an integer # of periods in frame?! Contains frequency components other than 0, (1/N)*SR, (2/N)*SR, SR/2.

Reasons for this stuff FFT treats your analysis frame as one period of an infinite, periodic signal. periodic signal may have discontinuities! only representable with high frequency content 35 Stay tuned for a way to help with this

Practice: Pitch tracking Q: How many bins should we use? Q: Algorithm to determine pitch? 36

Example R code saw <- readwave("sawtooth.wav") X <- fft(saw@left[1:2048]) #saw@left gives # us left channel samples plot(abs(x)[1:1025], type="h") maxbin <- which.max(abs(x)[1:1025]) maxfreq <- (maxbin-1)/2048*44100 #assuming 44100 SR 37

How to deal with music that changes over time? Compute FFT at many points in time. 38

Short-time Fourier Transform (STFT) N-point FFT N-point FFT N-point FFT 39

STFT hop size # of samples between beginning of one frame and the next N-point FFT N-point FFT Equivalently talk about overlap between adjacent frames. Adjust based on application needs. 40

Example applications of STFT? Pitch tracking over time (melody extraction) Onset detection (for rhythm/tempo analysis?) Audio fingerprinting More discussion on these in a few weeks 41

Practical FFT Questions N =? (Frame length) Balances time & frequency resolutions FFT or STFT? Is frequency content changing over time? If STFT, choose hop size based on granularity of analysis needed Do I care about magnitude, phase, or both? Magnitude alone useful for basic timbre analysis, instrument identification, many other things; phase required for reconstruction of waveform ***Plus a few other things: revisiting this at end of lecture*** 42

Converting from FFT back into sound Option 1: Take magnitude and phase of each bin (including second half of bins), compute a sinusoid at appropriate magnitude, frequency, and phase Option 2 (MUCH BETTER): Use inverse FFT (i.e., the IFFT) 43

The Inverse Discrete Fourier Transform (IDFT) 44 x n = 1 N N 1 X k=0 X k e i2 kn/n Compare to DFT: X k = N 1 X n=0 x n e i2 kn/n IDFT is just like DFT, but 1) has 1/N factor and positive exponent; 2) converts from complex into real (assuming original signal was realvalued)

The IFFT in practice Compute IDFT using the IFFT N FFT bins! N IFFT samples In R, with signal library: x <- abs(ifft(x)) 45 (abs enforces reasonable assumption of real valued elements of x)

A possible application of IFFT? Modify a sound by manipulating its spectrum: Original signal FFT Multiply 4 th bin by 0.25 46 Modified signal IFFT

A possible application of IFFT? Modify a sound by manipulating its spectrum: There are better ways of doing this Original signal FFT Multiply 4 th bin by 0.25 47 Modified signal IFFT

Why so many versions of Fourier analysis? Continuous Time Discrete Time Aperiodic / unbounded time, continuous frequency Periodic or bounded time, discrete frequency Fourier Transform Discrete-time Fourier Transform (DTFT) Fourier Series Discrete Fourier Transform (DFT) (FFT used here) 48 Each of these also has an inverse. You ll mainly care about the FFT (the fast algorithm for computing the DFT).

How to build useful systems? Method 1) Design a useful impulse response. 49

A very simple system [1] = [1, 0, 0, ] H h[n] = [2] Impulse in h[n] = [0.5] Volume control! y[n] = x[n] h[n] 50

Another very simple system [1] = [1, 0, 0, ] H Impulse in h[n] = [1, 0, 0, 0.5] y[n] = x[n] h[n] [very simple] echo 51

More realistic echo Use this as h[n] 52

Convolution reverb Record impulse response for concert halls, churches, etc. Use this as h[n]. 53 Example impulse responses

A simple smoothing system Take average of nearby points: 54

A simple smoothing system [1] = [1, 0, 0, ] H h[n] = [0.5, 0.5] y[n] =.5x[n-1] +.5x[n] 55

How to improve this? Can use h=[0.25, 0.25, 0.25, 0.25], h=[0.1, 0.1, 0.1] to make signal even smoother But there s a better way... smoother = less high-frequency content 56

How to build useful systems? Method 1) Design a useful impulse response We have to know how we want the timedomain sound signal to be changed by the system. 57 Method 2) Design a useful frequency response Instead, we can decide how we want the spectrum of the sound to be changed by the system.

Frequency response Any LTI system has the ability to change the spectrum of a sound 58 Relative change in magnitude 1.0 Doesn t change magnitude spectrum Frequency

Frequency response Any LTI system has the ability to change the spectrum of a sound 59 Relative change in magnitude 1.0 Removes higher frequencies, leaves lower freqs unchanged Frequency

Frequency response Any LTI system has the ability to change the spectrum of a sound 60 Relative change in magnitude 1.0 Removes lower frequencies, leaves higher freqs unchanged Frequency

Frequency response Any LTI system has the ability to change the spectrum of a sound 61 Relative change in magnitude 1.0 Allows only a range of frequencies to pass through system Frequency

Frequency response Any LTI system has the ability to change the spectrum of a sound 62 Relative change in magnitude 1.0 Allows all but a range of frequencies to pass through system Frequency

Frequency response Any LTI system has the ability to change the spectrum of a sound 63 Relative change in magnitude 1.0 Allows all but a range of frequencies to pass through system Frequency

Filters Each of these systems is an example of a common type of audio filter. 64

Frequency response Any LTI system has the ability to change the spectrum of a sound 65 Relative change in magnitude 1.0 Doesn t change magnitude spectrum All-pass filter Frequency

Frequency response Any LTI system has the ability to change the spectrum of a sound 66 Relative change in magnitude 1.0 Removes higher frequencies, leaves lower freqs unchanged Low-pass filter Frequency

Frequency response Any LTI system has the ability to change the spectrum of a sound 67 Relative change in magnitude 1.0 Removes lower frequencies, leaves higher freqs unchanged high-pass filter Frequency

Frequency response Any LTI system has the ability to change the spectrum of a sound 68 Relative change in magnitude 1.0 Allows only a range of frequencies to pass through system band-pass filter Frequency

Frequency response Any LTI system has the ability to change the spectrum of a sound 69 Relative change in magnitude 1.0 Allows all but a range of frequencies to pass through system Band-stop filter Frequency

The frequency response The effect of a system on a signal can be understood as multiplying the signal s spectrum by the frequency response. nth bin in input x nth bin in frequency response = nth bin in output 70

Relationship of frequency response & impulse response If h[n] is a system s impulse response then the spectrum of h[n] (FFT(h[n])) is the frequency response! [1] = [1, 0, 0, ] H Impulse in 71 Impulse response h[n] = [1, 0, 0, 0.5] FFT(h[n]) is frequency response

Consequences 1) Can take the FFT of h[n] to understand what an arbitrary system with known h[n] will do to a spectrum 72

Point-wise multiplication in spectral domain = convolution in time domain: a[n] b[n] "! A k B k Point-wise multiplication in time domain = convolution in spectral domain: a[n] b[n] "! A k B k 73

Convolution & Multiplication Convolving in the time-domain (x[n] h[n]) is equivalent to multiplication in the frequency domain (X k H k ). = FFT FFT FFT = 74

Convolution & Multiplication Convolving in the time-domain (x[n] h[n]) is equivalent to multiplication in the frequency domain (X k H k ). = IFFT IFFT IFFT 75

Very important principles Convolving in the time-domain (x[n] h[n]) is equivalent to multiplication in the frequency domain! Also, multiplying in the time domain is equivalent to convolving in the frequency domain. 76

One big problem Filters like this are undesirable. 77 Relative change in magnitude 1.0 Frequency

More practical FFT advice 78

Windowing: Motivation A problem: 79

Windowing Selecting N time-domain samples is like point-by-point multiplication with a rectangular function ( window ): 80

Windowing A rectangular signal has a very messy spectrum! Signal: Spectrum: 81

Windowing Multiplying a signal by a rectangle in time Is equivalent to convolving their spectra! 82

Solution: Apply a smoother window Before taking FFT, multiply the signal with a smooth window with a nicer spectrum (Equivalently, something that will get rid of sharp edges at either end of analysis frame) 83

Windowing process point-wise multiply with window: Result (apply FFT to this) 84

Example windows 85 From http://en.wikipedia.org/wiki/window_function

Example windows 86 From http://en.wikipedia.org/wiki/window_function