Lab 4 Fourier Series and the Gibbs Phenomenon

Similar documents
Fourier Series and Gibbs Phenomenon

DSP First. Laboratory Exercise #2. Introduction to Complex Exponentials

Lab S-8: Spectrograms: Harmonic Lines & Chirp Aliasing

Laboratory Assignment 4. Fourier Sound Synthesis

Problem Set 1 (Solutions are due Mon )

Here are some of Matlab s complex number operators: conj Complex conjugate abs Magnitude. Angle (or phase) in radians

DSP First Lab 03: AM and FM Sinusoidal Signals. We have spent a lot of time learning about the properties of sinusoidal waveforms of the form: k=1

Massachusetts Institute of Technology Dept. of Electrical Engineering and Computer Science Fall Semester, Introduction to EECS 2

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

Lab P-4: AM and FM Sinusoidal Signals. We have spent a lot of time learning about the properties of sinusoidal waveforms of the form: ) X

1 Introduction and Overview

LABORATORY - FREQUENCY ANALYSIS OF DISCRETE-TIME SIGNALS

The Formula for Sinusoidal Signals

Physics 115 Lecture 13. Fourier Analysis February 22, 2018

Figure 1: Block diagram of Digital signal processing

Basic Signals and Systems

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

Fourier Signal Analysis

George Mason University Signals and Systems I Spring 2016

ECE 201: Introduction to Signal Analysis

Electrical & Computer Engineering Technology

Knowledge Integration Module 2 Fall 2016

Spectrum Analysis: The FFT Display

Additive Synthesis OBJECTIVES BACKGROUND

DFT: Discrete Fourier Transform & Linear Signal Processing

SMS045 - DSP Systems in Practice. Lab 1 - Filter Design and Evaluation in MATLAB Due date: Thursday Nov 13, 2003

SAMPLING THEORY. Representing continuous signals with discrete numbers

Subtractive Synthesis. Describing a Filter. Filters. CMPT 468: Subtractive Synthesis

Fall Music 320A Homework #2 Sinusoids, Complex Sinusoids 145 points Theory and Lab Problems Due Thursday 10/11/2018 before class

E40M Sound and Music. M. Horowitz, J. Plummer, R. Howe 1

Signal Processing First Lab 02: Introduction to Complex Exponentials Multipath. x(t) = A cos(ωt + φ) = Re{Ae jφ e jωt }

MATLAB Assignment. The Fourier Series

Digital Signalbehandling i Audio/Video

Signal Processing First Lab 20: Extracting Frequencies of Musical Tones

L A B 3 : G E N E R A T I N G S I N U S O I D S

Digital Signal Processing Laboratory 1: Discrete Time Signals with MATLAB

STANFORD UNIVERSITY. DEPARTMENT of ELECTRICAL ENGINEERING. EE 102B Spring 2013 Lab #05: Generating DTMF Signals

Biomedical Signals. Signals and Images in Medicine Dr Nabeel Anwar

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

Lecture 7 Frequency Modulation

ELT COMMUNICATION THEORY

FFT analysis in practice

Log Booklet for EE2 Experiments

Signal Processing First Lab 02: Introduction to Complex Exponentials Direction Finding. x(t) = A cos(ωt + φ) = Re{Ae jφ e jωt }

Sound synthesis with Pure Data

Lab 6: Sampling, Convolution, and FIR Filtering

DSP First. Laboratory Exercise #11. Extracting Frequencies of Musical Tones

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering. EIE2106 Signal and System Analysis Lab 2 Fourier series

Armstrong Atlantic State University Engineering Studies MATLAB Marina Sound Processing Primer

Lab Report #10 Alex Styborski, Daniel Telesman, and Josh Kauffman Group 12 Abstract

Music 171: Amplitude Modulation

EE 422G - Signals and Systems Laboratory

ENGR 210 Lab 12: Sampling and Aliasing

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

Class #16: Experiment Matlab and Data Analysis

GEORGIA INSTITUTE OF TECHNOLOGY. SCHOOL of ELECTRICAL and COMPUTER ENGINEERING

Fourier Transform. Prepared by :Eng. Abdo Z Salah

Lab S-7: Spectrograms of AM and FM Signals. 2. Study the frequency resolution of the spectrogram for two closely spaced sinusoids.

ESE 150 Lab 04: The Discrete Fourier Transform (DFT)

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

LAB 2 Machine Perception of Music Computer Science 395, Winter Quarter 2005

1. In the command window, type "help conv" and press [enter]. Read the information displayed.

1 Introduction and Overview

Discrete Fourier Transform

Signal Processing. Naureen Ghani. December 9, 2017

George Mason University ECE 201: Introduction to Signal Analysis Spring 2017

Lab 6: Building a Function Generator

Spectrum. Additive Synthesis. Additive Synthesis Caveat. Music 270a: Modulation

Laboratory Assignment 2 Signal Sampling, Manipulation, and Playback

Signal Processing. Introduction

DSP First. Laboratory Exercise #7. Everyday Sinusoidal Signals

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

ECE 2713 Homework 7 DUE: 05/1/2018, 11:59 PM

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

Midterm 1. Total. Name of Student on Your Left: Name of Student on Your Right: EE 20N: Structure and Interpretation of Signals and Systems

The Signals and Systems Toolbox: Comparing Theory, Simulation and Implementation using MATLAB and Programmable Instruments

Digital Signal Processing Lecture 1 - Introduction

Set-up. Equipment required: Your issued Laptop MATLAB ( if you don t already have it on your laptop)

PHYSICS LAB. Sound. Date: GRADE: PHYSICS DEPARTMENT JAMES MADISON UNIVERSITY

Lab 18 Delay Lines. m208w2014. Setup. Delay Lines

Fourier Transform Pairs

ECEn 487 Digital Signal Processing Laboratory. Lab 3 FFT-based Spectrum Analyzer

SIGNALS AND SYSTEMS LABORATORY 3: Construction of Signals in MATLAB

Bioacoustics Lab- Spring 2011 BRING LAPTOP & HEADPHONES

CMPT 468: Frequency Modulation (FM) Synthesis

MASSACHUSETTS INSTITUTE OF TECHNOLOGY /6.071 Introduction to Electronics, Signals and Measurement Spring 2006

ESE 150 Lab 04: The Discrete Fourier Transform (DFT)

ME 365 EXPERIMENT 8 FREQUENCY ANALYSIS

ELECTRONOTES APPLICATION NOTE NO Hanshaw Road Ithaca, NY August 3, 2017

E40M Sound and Music. M. Horowitz, J. Plummer, R. Howe 1

Lab week 4: Harmonic Synthesis

Linear Frequency Modulation (FM) Chirp Signal. Chirp Signal cont. CMPT 468: Lecture 7 Frequency Modulation (FM) Synthesis

UNIVERSITY OF TORONTO Faculty of Arts and Science MOCK EXAMINATION PHY207H1S. Duration 3 hours NO AIDS ALLOWED

FIR/Convolution. Visulalizing the convolution sum. Convolution

Laboratory 7: Active Filters

Experiments #6. Convolution and Linear Time Invariant Systems

Laboration Exercises in Digital Signal Processing

EE 311 February 13 and 15, 2019 Lecture 10

Lab S-5: DLTI GUI and Nulling Filters. Please read through the information below prior to attending your lab.

EGR 111 Audio Processing

Transcription:

Lab 4 Fourier Series and the Gibbs Phenomenon EE 235: Continuous-Time Linear Systems Department of Electrical Engineering University of Washington This work 1 was written by Amittai Axelrod, Jayson Bowen, and Maya Gupta, and is licensed under the Creative Commons Attribution License. 2 1 Introduction In this lab you will examine the Fourier series representation of periodic signals using matlab. In particular, you ll study the truncated Fourier series reconstruction of a periodic function. 2 Useful matlab Commands In addition to what you already know about matlab, you may need to use the following commands. You ve seen them in Lab 1, but use help to remind yourself of their syntax. abs Computes the magnitude of a complex number. angle Computes the phase angle of a complex number. stem Draws discrete plots (as opposed to plot, which draws continuous plots). 3 Signal Synthesis Later on in this lab you will use a Fourier series to approximate a square wave. The Fourier series represents the sum of smooth sinusoids, but a square wave is full of sharp edges, so this is a counter-intuitive result! Let s start with something a little easier: synthesizing the sound of a trumpet. Many musical instruments produce very periodic waveforms. In particular, the pitch of certain notes is determined by specific frequencies, such as 440Hz (which is Concert A, for tuning strings). 1 Last revision: Mon May 3 02:48:54 EDT 2010 2 http://www.creativecommons.org/licenses/by/2.0

3.1 Trumpet Synthesizer First, download the trumpet sound sample called trumpet.mat from the lab webpage 3. This trumpet sound was sampled at a rate of Fs = 11,025 Hz. Exercise 1: Play the trumpet sound to verify your setup. Plot a small section of the trumpet sound (100 samples). This will show about three periods of the sampled signal. Is the signal periodic? Look at the frequency spectrum of the trumpet sound by doing the following: >> Fs = 11025; % the sample rate is 11025 Hz >> Y = fft(trumpet, 512); % take the FFT of trumpet >> Ymag = abs(y); % take the magnitude of Y >> f = Fs * (0:256)/512; % scale the axis to be meaningful >> plot(f, Ymag(1:257)); % plot Ymag (only half the points are needed) >> xlabel( Frequency (Hz) ) >> ylabel( Magnitude ) The series of peaks that you see are the harmonics of the instrument. Use the data cursor tool in MATLAB s figure window to read the graph data. Write down the frequency and magnitude (the strength of the harmonic) for five to ten of the strongest peaks. You ll now synthesize the trumpet using only the information from these peaks. Each peak represents a scaled cosine at a particular frequency. The trumpet sound is the sum of these (possibly infinitely many) scaled cosines. Exercise 2: Create a function called addcosines that will add several cosines together and normalize the output. addcosines should take in three vectors: a time vector time, a vector of frequencies freqs, and a vector of magnitudes mags. The output should have the same dimensions as time. Furthermore, the output should only take on the range of values [-1,1] because you will want to play it like a sound vector. Verify your code by passing the inputs time = 0:1/Fs:1, freqs = [100 150], and mags = [1 2] to addcosines. Plot the inputs and output. Are they what you expect? 3 Or from http://cnx.org/content/m13854/latest/trumpet.mat 2

Here are some hints for the above: Assume the time vector will have the form 0:1/Fs:duration, where duration is in seconds. Each cosine function should look like mag(i)*cos(2*pi*freq(i)*t). Use a for loop to add together the cosines. You ll have one cosine for each frequency/magnitude pair in the freqs and mags vectors. To scale the output, recall that you did an identical thing in your mixer from Lab 2. Alternatively, you may use soundsc this time. Exercise 3: Use your addcosines function to sum the cosines specified by the peak data you collected from the trumpet sound in the previous exercise. Play trumpet and your new synthesized sound. Do they sound the same? Use subplot to plot a small section of your new synthesized sound along with trumpet. Do they look the same? Try synthesizing trumpet with fewer frequencies, then try again with more frequencies. How does this affect the sound of your synthesized trumpet? 3.2 That Funny Phase Although the waveforms of your synthesized trumpet sounds look different from the original, they ought to sound pretty similar. This should convince you that the Fourier series coefficients are a valid approximation of the original signal! Let s look at another example: Exercise 4: Pick two harmonic frequencies and create two cosines, cos1 and cos2, at these frequencies. Use the time vector time = 0:1/Fs:1 with Fs = 8000, but remember that you can only reproduce frequencies that are less than Fs/2. Add cos1 and cos2 to produce a signal sig1. Generate cos2b by time-delaying cos2 by half a cycle. Now create a second signal sig2 that is the sum of cos1 and cos2b. Use subplot to show a few cycles of sig1 and sig2. How do they compare? What did the time delay do to the phase of sig2? Play both sig1 and sig2 with soundsc. How do they compare? Make a couple other variants of sig2 (call them sig2b, sig2c, etc) with different delays on cos2, and compare the outputs to the original sig1. 3

Exercise 5: Create a third cosine cos3 at an arbitrary frequency. Add cos3 with a quarter-cycle-delayed version of itself to generate sig3. Use subplot to show a few cycles of cos3 and sig3. How do they compare? Play both cos3 and sig3 with soundsc. How do they compare? What can you conclude about human hearing capabilities? 4 Truncated Fourier Series In this exercise you ll reconstruct the periodic function x(t), shown below in Figure 1, by synthesizing a periodic signal from a number of Fourier Series coefficients. Along the way, you ll observe some similarities and differences between your reconstruction and the original signal. Figure 1: A periodic signal. 4.1 Gibbs Phenomena Download the Ck.m function from the lab webpage 4. This function takes one argument k, and computes the k th Fourier series coefficient for the square wave in Figure 1. The formula for the coefficient is: { 0 if k = 0, or k is even; C k = 1 2kπ [cos cos kπ ] if k is odd. jkπ 3 3 4 Or from http://cnx.org/content/m13854/latest/ck.m 4

For example, C k (1) = 1 jπ = 0 + j0.3183. Exercise 6: Compute the coefficients C k for k { 10, 9,..., 9, 10}. Use subplot to show the magnitude and phase (versus frequency ω) for each coefficient. The coefficients are a function of k, which is integer-valued, so use stem to draw the plots. You ve seen that a signal x(t) can be approximated with a truncated Fourier series. The actual calculation, for a given coefficient range k { K max, K max +1,..., K max 1, K max } is as follows: x(t) = = Kmax k= Kmax Kmax k=0 C k e jkω 0t 2 C k cos (kω 0 t + C k ) The reason for using the cosine form is to avoid numerical problems and ensure a real answer. For this example, ω 0 = 1. Exercise 7: Implement a function that approximates x(t) with a truncated Fourier series, as described above. Show the TA your (commented) code. Compute x(t) over the time vector t = -6:.01:6 for each of the following three cases: K max = 5, 15, and 30. Use subplot to plot all three approximations in the same figure. How do the vertical and horizontal edges compare? As you add more cosines to the approximation, you do get closer to the square wave (in terms of squared error). However, at the edges there is some undershoot and overshoot that becomes shorter in time, but the magnitude of the undershoot and overshoot stay large. This persistent undershoot and overshoot at edges is called the Gibbs Phenomenon. In general, this kind of ringing occurs at discontinuities the sharp vertical jumps in the square wave when you try to synthesize a sharp edge out of too few low frequencies. Another view is that low-pass filtering will trigger the ringing or Gibbs Phenomenon. If you start with a real signal and filter out its higher frequencies, then this is equivalent to going the other way and synthesizing the signal from low frequencies which is what you just did in the last exercise! As an example, higher frequencies are usually removed when compressing an audio signal (that is, the audio signal is low-pass filtered). Then, if there is an impulse edge or attack in the music, ringing will occur. However, the ringing (called pre-echo in audio) can be 5

heard only before the attack, because the attack masks the ringing that comes after it (this masking effect is psychoacoustic; it happens in your head). High-quality MP3 systems put a lot of effort into detecting attacks and processing the signals to avoid pre-echo. 5 Links This applet 5, from the National Taiwan University, provides a great interface for listening to sinusoids and their harmonics. eof 5 http://www.phy.ntnu.edu.tw/ntnujava/viewtopic.php?t=33 6