ECE 420 Lecture 3 Feb 4 2019 - University of Illinois ...

Post on 18-Dec-2021

1 views 0 download

Transcript of ECE 420 Lecture 3 Feb 4 2019 - University of Illinois ...

ECE 420

Lecture 3

Feb 4 2019

Or

1

Everything you wanted to know about

Glottal Waveforms and Laryngeal Excitation

Cycles but were afraid to ask

Converting Frequency Domains

β€’ A common question: A particular digital frequency corresponds

to what analog frequency?

β€’ Option 1: Work through the equations relating the various

transforms to find your answer

β€’ FT: 𝑋 𝑓 = βˆžβˆ’βˆž

π‘₯ 𝑑 π‘’βˆ’π‘—2πœ‹π‘“π‘‘ 𝑑𝑑

β€’ DTFT: 𝑋 πœ” = σ𝑛=βˆ’βˆžβˆž π‘₯ 𝑛 π‘’βˆ’π‘—πœ”π‘›

β€’ DFT: 𝑋 π‘š = σ𝑛=0π‘βˆ’1 π‘₯ 𝑛 π‘’βˆ’π‘—2πœ‹π‘šπ‘›/𝑁

β€’ Replacing x(t) with samples at x[nT]

β€’ σ𝑛=βˆ’βˆžβˆž π‘₯(𝑛𝑇)π‘’βˆ’π‘—2πœ‹π‘“π‘›π‘‡

β€’ So πœ” = 2πœ‹π‘“π‘‡

β€’ DFT/DTFT easily related, and then also DFT/FT

β€’ πœ” = 2πœ‹π‘š/𝑁

β€’ 𝑓 = π‘š/𝑁𝑇

2

Converting Frequency Domains

β€’ Option 2: Recall that these are all linear relationships, and use

ratios based on maximum frequency

β€’ β€˜Max frequency’ of analog signal is 1/𝑇 β‰œ 𝐹𝑠

β€’ DTFT, DFT have periods of 2πœ‹,𝑁 respectively

β€’ Yields the relationships π‘š

𝑁=

πœ”

2πœ‹=

𝑓

𝐹𝑠

β€’ Allows to fluidly convert in either direction

β€’ Always β€˜gets the units right’ (Hz, rads, normalized freq., etc.)

3

Always think: Ratios!

Composite Algorithms

β€’ Algorithms composed of one or more steps/pieces

β€’ Might involve decision points (β€œcontrol flow”) or combinations

from different paths

β€’ Allows for sophisticated algorithms but increases system

complexity substantially

β€’ Flow graph helps manage system and convey operation to

others

4

Step A

Step B

Step C Step D

Step E

Implementing Composite Algorithms

β€’ Always implement components as separate functions/classes

β€’ Sometimes these will be in different libraries anyway

β€’ Separation of concerns allows for better focus to the code,

generally resulting in better coding style and code that is much

easier to debug

β€’ Creates code segments that can be portable among projects

and not tied to a specific implementation

5

A Note on Testing

β€’ Good practice to validate components of your code first

β€’ Writing each step as separate functions facilitates for good unit

testing

β€’ Increases probability of success when putting everything together

β€’ Types of testing

β€’ Unit

β€’ Integration

β€’ System/End-to-End

β€’ These testing categories get cover progressively larger aspects

of the system, but at higher cost

6

Unit Testing is your friend!

A Note on Testing

β€’ How do you know if something is working?

β€’ Test signals!

β€’ What test signals do you use?

β€’ They might be provided for you

β€’ You can make them up

β€’ You can use a repository of test data

β€’ You can acquire them

β€’ Classes of test data

β€’ β€˜Easy’ vs. β€˜Hard’

β€’ β€˜Noisy’ vs. β€˜Clean’

β€’ Different noise characteristics

β€’ Corner cases

7

A Note on Testing

β€’ A key is to have β€˜high quality’ data to establish β€˜ground truth’

β€’ Nothing is worse than getting misled about algorithm performance

due to incorrect data

β€’ Allows for quantitative measures of performance if sufficiently large

set available

β€’ Simple and clean data can facilitate establishing basic algorithm

functionality

β€’ Always a good idea to at least try with a non-ideal test signal as

a sanity check

β€’ Some algorithms can catastrophically break down when certain

assumptions are not met or noise is introduced!

8

Test Database / Benchmarks

β€’ Huge value!

β€’ Provides a suite of test cases

β€’ Ground truth for evaluation of algorithm efficacy

β€’ Common set to allows for apples-to-apples comparison among

algorithms

β€’ β€˜Real world’ conditions

β€’ Facilitates automatic tuning and evaluation of algorithms

β€’ Prevalent in many areas of engineering

9

Pitch Detection

β€’ This lab is a pitch detection implementation

β€’ What exactly is pitch? Not actually strictly defined.

β€’ Period of signal in time domain

β€’ Fundamental frequency in spectral domain (caution!)

β€’ Perceived frequency of signal by human ear

β€’ Anatomically as distance between pulses/cycles of larynx

10

T

Basic Pitch Detection Algorithm

β€’ Operate on a single frame of audio input

β€’ Initial decision: voiced or unvoiced?

β€’ If voiced, perform pitch analysis and report pitch frequency

11

Voiced

Decision

Pitch

AnalysisF0

β€œNo Signal”

Y

N

Frame

Challenges of Pitch Detection

β€’ Frame size selection

β€’ Likely not an integer multiple of period length

β€’ Probably need at least one period, maybe more

β€’ Larger frame sizes = more latency

β€’ Pitch values may not be integral values of sampling rate /

frequency bins

β€’ May distort analysis sufficiently to pick improper bin

β€’ Speech vs. Music

β€’ Non-ideal environmental situation

β€’ Multiple concurrent signals

β€’ Noise

β€’ Bad microphone quality

12

Categorization of Frames

β€’ Three coarse categorization of frames

β€’ Voiced sounds – generated by vibration of the vocal cords

β€’ Unvoiced sounds – speech generated without vibration of the

vocal cords

β€’ Silence / noise – no active speech

β€’ We will only be concerned with classifying and measuring pitch

for Voiced frames

13

Voiced Decision

β€’ Voiced signals tend to be louder and more sustained

β€’ Unvoiced signals have more abrupt characteristics

β€’ Over the span of a frame, we would therefore expect voiced

signals to have a higher energy than unvoiced/silent frames

β€’ Calculate the energy of the frame, compare to a threshold for

voiced decision

14

Οƒπ‘₯ 𝑛 2Y

N

Frame > Es Voiced

Not Voiced

Pitch Calculation - Autocorrelation

β€’ 𝑅π‘₯π‘₯ 𝑙 =σ𝑛=0π‘βˆ’1 π‘₯ 𝑛 π‘₯[π‘›βˆ’π‘™]

σ𝑛=0π‘βˆ’1 π‘₯ 𝑛 2

β€’ Provides an estimate of how self-similar a signal is given a

particular delay (lag) 𝑙

β€’ When offset corresponds to period of signal, values coherently

combine to yield a large correlation value

15

Challenges of Harmonics

β€’ Pitch estimation searches for a peak value in the autocorrelation

function

β€’ Two main challenges

β€’ Lag of 0 will generally have the largest overall value, but is certainly

not the value we are looking for

β€’ Multiples of the pitch (higher order harmonics) will also yield local

peaks but must be rejected

β€’ Solving these challenges is part of the Lab design objectives

16

Basic Pitch Detection Algorithm

17

Voiced

Decision

Autocorrelation

Frame

Peak Detection

Estimated

Pitch

Not

Voiced

Algorithmic Complexity

β€’ β€œBig O” notation

β€’ 𝑂 𝑁 , 𝑂 𝑁2 , 𝑂 log𝑁 , 𝑂 1 , 𝑂(2𝑁)

β€’ Key property of complexity analysis is that the higher order term

dominates

β€’ 𝑂 𝑁 + 𝑁2 = 𝑂(𝑁2)

β€’ Always a good idea to know the complexity of the algorithms you

are using

β€’ Know what you are getting yourself into!

β€’ For a complicated composite algorithm, each step might have

different complexity

β€’ Knowing complexity tells you where the dominant computation step

β€’ Optimize there!

18

Efficient Cross-Correlation

β€’ 𝑅π‘₯π‘₯ 𝑙 = π‘₯ 𝑛 βˆ— π‘₯ 𝑛 is an 𝑂 𝑁2 operation

β€’ What is complexity of energy calculation step?

β€’ What is complexity of peak detection step?

β€’ Calculate correlation using 𝑅π‘₯π‘₯ 𝑙 = πΉβˆ’1{𝐹 π‘₯ πΉβˆ— π‘₯ }

β€’ πΉβˆ— π‘₯ denotes complex conjugate

β€’ Replace with an 𝑂 π‘π‘™π‘œπ‘”π‘ algorithm

β€’ What is the dominant component of our system now?

β€’ Can actually perform joint voiced/unvoiced and pitch analysis

with just 𝑅π‘₯π‘₯

19

Postprocessing

β€’ Improve overall pitch values by post-processing of the estimates

β€’ Smoothing of pitch values

β€’ Linear

β€’ Non-linear (e.g. median)

β€’ Can also apply as a pre-processing if we wish (with caution!)

β€’ Consider evolution of pitch value over successive frames

β€’ Attribute cost associated with changes in pitch and transition voiced

to/from unvoiced

β€’ Can work in concert with multiple pitch estimates to pick β€˜the best’

20

Categories of Pitch Analysis (subset)

21

Algorithm Selection

β€’ Dozens of pitch detection algorithms out there

β€’ How do you pick one? (Or decide to develop your own?)

β€’ What is your problem domain?

β€’ Are the algorithms targeted at this domain?

β€’ Is it possible to quantify performance and compare?

β€’ Training/test data

β€’ Different aspects to compare: measurement accuracy,

computational speed, output latency

β€’ What are your requirements?

β€’ What is most important? What compromises can be made?

β€’ Can an algorithm be modified to meet those requirements?

β€’ The more specific you are, the more discriminating you can be

regarding algorithm selection

22

YIN Algorithm

β€’ Distance Metric

β€’ 𝑑 𝜏 = Οƒ π‘₯ 𝑛 βˆ’ π‘₯ 𝑛 + 𝜏 2

β€’ Cumulative normalized distance

β€’ 𝑑′ 𝜏 = 𝑑(𝜏)/[1/𝜏 σ𝑗=1𝜏 𝑑(𝑗)]

β€’ Absolute threshold

β€’ π‘Žπ‘Ÿπ‘”π‘šπ‘–π‘›πœ 𝑑′ 𝜏 𝑑′ 𝜏 < 𝐸}

β€’ Parabolic Interpolation

β€’ Expand 𝑑′ 𝜏 analytically and

find minimum

β€’ Best Local Estimate

β€’ Examine small frame location

offsets for better 𝑑′ 𝜏

23

Algorithm Gross

Error %

Baseline Autocorrelation 10.0

Distance Metric 1.95

+ Cumulative Norm. 1.69

+ Absolute Thresh 0.78

+ Parabolic Interpolation 0.77

+ Best Local Estimate 0.50

β€˜Ad-hoc’ Algorithm Development

β€’ Identify weak points / scenarios in the algorithm

β€’ Large set of training data is helpful

β€’ Augment the algorithm

β€’ Change existing parameters / steps

β€’ Add extra steps

β€’ Validate the changes

β€’ Did performance improve in the desired areas?

β€’ Did good performance persist in other areas (no regressions)?

β€’ Emergent complex system

β€’ Potentially very powerful

β€’ Potentially very hard to analyze

β€’ Potentially very hard to maintain

24

Assigned Lab

β€’ Lead-in to the Final Project

β€’ Forming up groups for both Assigned Lab and Final Project

β€’ Explore a DSP algorithm from the literature

β€’ Implementation in Python for this stage, NOT on tablet yet

β€’ Proposal for Assigned Lab

β€’ Overview of proposed algorithm, cite source(s)

β€’ Plan for testing and validation

β€’ Rough idea(s) for Final Project application

β€’ Due March 1

β€’ Assigned Lab Report upon completion, demo incorporated into

Final Proposal design review

25

This week

β€’ Lab 3: Real time spectral analyzer Quiz/Demo

β€’ Lab 4: Pitch Analyzer

β€’ Be thinking about Assigned Project Labs / Groups

β€’ Early vetting of ideas is fine!

26