CMPT 468: Matlab Tutorial 3: Analysis with the Fast Fourier Transform (FFT)



Similar documents
Lab 1. The Fourier Transform

B3. Short Time Fourier Transform (STFT)

ANALYZER BASICS WHAT IS AN FFT SPECTRUM ANALYZER? 2-1

How To Understand The Discrete Fourier Transform

Frequency Response of FIR Filters

Analysis/resynthesis with the short time Fourier transform

Matlab GUI for WFB spectral analysis

Sampling and Interpolation. Yao Wang Polytechnic University, Brooklyn, NY11201

Timing Analysis of X-ray Lightcurves

USB 3.0 CDR Model White Paper Revision 0.5

Time Series Analysis: Introduction to Signal Processing Concepts. Liam Kilmartin Discipline of Electrical & Electronic Engineering, NUI, Galway

The Fourier Analysis Tool in Microsoft Excel

SR2000 FREQUENCY MONITOR

Spectral Analysis Using a Deep-Memory Oscilloscope Fast Fourier Transform (FFT)

Window function From Wikipedia, the free encyclopedia For the term used in SQL statements, see Window function (SQL)

Analog and Digital Signals, Time and Frequency Representation of Signals

Cell Phone Vibration Experiment

FOURIER TRANSFORM BASED SIMPLE CHORD ANALYSIS. UIUC Physics 193 POM

SIGNAL PROCESSING FOR EFFECTIVE VIBRATION ANALYSIS

Auto-Tuning Using Fourier Coefficients

Short-time FFT, Multi-taper analysis & Filtering in SPM12

SIGNAL PROCESSING & SIMULATION NEWSLETTER

ECE 435 INTRODUCTION TO THE MICROWAVE NETWORK ANALYZER

Controller Design in Frequency Domain

The Calculation of G rms

Fermi National Accelerator Laboratory. The Measurements and Analysis of Electromagnetic Interference Arising from the Booster GMPS

Real time spectrum analyzer light

Introduction to IQ-demodulation of RF-data

Design of FIR Filters

The Fundamentals of FFT-Based Audio Measurements in SmaartLive

chapter Introduction to Digital Signal Processing and Digital Filtering 1.1 Introduction 1.2 Historical Perspective

Scientific Programming

Period04 User Guide. Abstract. 1 Introduction. P. Lenz, M. Breger

WINDAQ Data Acquisition and Playback Software

Function Guide for the Fourier Transformation Package SPIRE-UOL-DOC

Adding Sinusoids of the Same Frequency. Additive Synthesis. Spectrum. Music 270a: Modulation

Final Year Project Progress Report. Frequency-Domain Adaptive Filtering. Myles Friel. Supervisor: Dr.Edward Jones

Lecture 1-6: Noise and Filters

Department of Electrical and Computer Engineering Ben-Gurion University of the Negev. LAB 1 - Introduction to USRP

Applications of the DFT

FAST Fourier Transform (FFT) and Digital Filtering Using LabVIEW

10 Discrete-Time Fourier Series

The Fundamentals of Signal Analysis. Application Note 243

Time series analysis Matlab tutorial. Joachim Gross

RANDOM VIBRATION AN OVERVIEW by Barry Controls, Hopkinton, MA

PLOTTING COMMANDS (!' ) "' # "*# "!(!' +,

NRZ Bandwidth - HF Cutoff vs. SNR

SGN-1158 Introduction to Signal Processing Test. Solutions

The Algorithms of Speech Recognition, Programming and Simulating in MATLAB

Spectrum Analyzers And Network Analyzers. The Whats, Whys and Hows...

RF Measurements Using a Modular Digitizer

RADIO FREQUENCY INTERFERENCE AND CAPACITY REDUCTION IN DSL

Tutorial and Simulations for Micro-Cap IV

Utilizing Time Domain (TDR) Test Methods For Maximizing Microwave Board Performance

Sampling Theorem Notes. Recall: That a time sampled signal is like taking a snap shot or picture of signal periodically.

Multiplexing and Sampling Theory

Convolution, Correlation, & Fourier Transforms. James R. Graham 10/25/2005

AN-756 APPLICATION NOTE One Technology Way P.O. Box 9106 Norwood, MA Tel: 781/ Fax: 781/

SOFTWARE FOR GENERATION OF SPECTRUM COMPATIBLE TIME HISTORY

MUSICAL INSTRUMENT FAMILY CLASSIFICATION

T = 1 f. Phase. Measure of relative position in time within a single period of a signal For a periodic signal f(t), phase is fractional part t p

RightMark Audio Analyzer 6.0. User s Guide

Lab #9: AC Steady State Analysis

The continuous and discrete Fourier transforms

4 Digital Video Signal According to ITU-BT.R.601 (CCIR 601) 43

CHAPTER 6 Frequency Response, Bode Plots, and Resonance

Understand the effects of clock jitter and phase noise on sampled systems A s higher resolution data converters that can

Ralph L. Brooker, Member, IEEE. Andrew Corporation, Alexandria, VA 22314, USA

Laboratory Manual and Supplementary Notes. CoE 494: Communication Laboratory. Version 1.2

Digital Transmission of Analog Data: PCM and Delta Modulation

High Quality Integrated Data Reconstruction for Medical Applications

Jitter Measurements in Serial Data Signals

Introduction to Digital Filters

Introduction to Digital Audio

Computer Networks and Internets, 5e Chapter 6 Information Sources and Signals. Introduction

Computers. Hardware. The Central Processing Unit (CPU) CMPT 125: Lecture 1: Understanding the Computer

AC : MEASUREMENT OF OP-AMP PARAMETERS USING VEC- TOR SIGNAL ANALYZERS IN UNDERGRADUATE LINEAR CIRCUITS LABORATORY

Chapter 8 - Power Density Spectrum

Jitter Transfer Functions in Minutes

CONVOLUTION Digital Signal Processing

How To Understand The Nyquist Sampling Theorem

Spectrum Level and Band Level

Switch Mode Power Supply Topologies

PROCESS CONTROL SYSTEM DESIGN Process Control System Design LECTURE 2: FREQUENCY DOMAIN ANALYSIS

Software for strong-motion data display and processing

Spectrum Analyzer. Software Instruction Manual

MATRIX TECHNICAL NOTES

Agilent Time Domain Analysis Using a Network Analyzer

Understanding CIC Compensation Filters

TCOM 370 NOTES 99-4 BANDWIDTH, FREQUENCY RESPONSE, AND CAPACITY OF COMMUNICATION LINKS

Positive Feedback and Oscillators

Electrical Resonance

u = [ 2 4 5] has one row with three components (a 3 v = [2 4 5] has three rows separated by semicolons (a 3 w = 2:5 generates the row vector w = [ 2 3

AVX EMI SOLUTIONS Ron Demcko, Fellow of AVX Corporation Chris Mello, Principal Engineer, AVX Corporation Brian Ward, Business Manager, AVX Corporation

Real-Time Spectrum Analyzer Fundamentals

Doppler. Doppler. Doppler shift. Doppler Frequency. Doppler shift. Doppler shift. Chapter 19

Transcription:

CMPT 468: Matlab Tutorial 3: Analysis with the Fast Fourier Transform (FFT) Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University September 24, 2013 This tutorial is available in its original form at: http://ccrma.stanford.edu/~jos/mdft/ FFT of a simple sinusoid The FFT, or fast fourier transform is an efficient implementation of the discrete fourer transform if the signal length is a power of two. In this example, we will use Matlab to take the FFT. Recall our simple discrete sinusoid is which we may implement in Matlab as N = 64; % signal length (power of 2) T = 1; % sampling period (and rate) is set to 1 A = 1; % sinusoid amplitude phi = 0; % phase of zero f = 0.25; % frequency (under Nyquist limit) nt = [0:N-1]*T; % discrete time axis x = cos(2*pi*f*nt + phi); % sinusoid X = fft(x); x(t) = cos(ω 0 nt +φ). (1) In the last line, we use Matlab s fft function to obtain the spectrum of the sinusoid. Since X is complex, we do no usually plot it as is. Rather, to obtain a more meaningful graph, we first obtain the magnitude before plotting. Recall that the magnitude of a complex number z = x+jy is given by mag z = z = x 2 +y 2. (2) Inmatlabwe canusetheabsfunctiontoobtaintheabolutevalueofthespectrum. Therefore if we add the line 1

magx = abs(x); to our code above we will have a sequence of real numbers representing the magnitude of the frequency components. Likewise, we may obtain the phase using Matlab s angle function. argx = angle(x); though we will discuss this more late. Let s now make 3 plots: one to plot the time domain evolution, one to plot the magnitude of the fft on a linear scale, and finally one on a db scale. % Plot time data: figure(1); subplot(3,1,1); plot(n,x, *k ); ni = [0:.1:N-1]; % Interpolated time axis hold on; plot(ni,a*cos(2*pi*ni*f*t+phi), -k ); grid off; title( Sinusoid at 1/4 the Sampling Rate ); xlabel( Time (samples) ); ylabel( Amplitude ); text(-8,1, a) ); hold off; % Plot spectral magnitude: magx = abs(x); fn = [0:1/N:1-1/N]; % Normalized frequency axis subplot(3,1,2); stem(fn,magx, ok ); grid on; ylabel( Magnitude (Linear) ); text(-.11,40, b) ); % Same thing on a db scale: spec = 20*log10(magX); % Spectral magnitude in db spec = spec - max(spec); % Normalize to 0 db max subplot(3,1,3); plot(fn,spec, --ok ); grid on; axis([0 1-350 50]); text(-.11,50, c) ); CMPT 468: Matlab Tutorial 3: Analysis with the Fast Fourier Transform (FFT) 2

FFT of a slightly less simple sinusoid The above example was somewhat contrived. It is more likely that the signals you analyse will have inusoidal components that don t complete a full cycle or, said differently, have frequency components that lie between frequency bins. Let s see what happens in such a case. First, increase the frequency in the above example by one-half of a bin: % Example 2 = Example 1 with frequency between bins f = 0.25 + 0.5/N; % Move frequency up 1/2 bin x = cos(2*pi*f*nt); % Signal to analyze X = fft(x); % Spectrum Plot the resulting magnitude spectrum as you did above. Notice that at this frequency, we get extensive spectral leakage into all the side bins. To get an idea of where this is coming from, let s look at the periodic extension of the time waveform: % Plot the periodic extension of the time-domain signal plot([x x], k ); title( Time Waveform Repeated Once ); xlabel( Time (samples) ); ylabel( Amplitude ); Notice the glitch in the middle where the signal begins its forced repetition. This results in undesirable frequency components in our spectrum. Zero-padding To get finer resolution in the frequency domain, we can zero-pad the signal, that is, append zeroes to the end of the time-domain signal. zpf = 8; % zero-padding factor x = [cos(2*pi*f*nt),zeros(1,(zpf-1)*n)]; % zero-padded X = fft(x); % interpolated spectrum magx = abs(x); % magnitude spectrum... % waveform plot as before nfft = zpf*n; % FFT size = new frequency grid size fni = [0:1.0/nfft:1-1.0/nfft]; % normalized freq axis subplot(3,1,2); % with interpolation, we can use solid lines - : plot(fni,magx, -k ); grid on;... CMPT 468: Matlab Tutorial 3: Analysis with the Fast Fourier Transform (FFT) 3

spec = 20*log10(magX); % spectral magnitude in db % clip below at -40 db: spec = max(spec,-40*ones(1,length(spec)));... % plot as before Using a window Use of a Blackman Window The previous examples can all be interpreted as using a rectangular window to select a finite segment (of length N) from a sampled sinusoid. To see the spectral characteristics of the rectangle window, try the following in Matlab: N = 64; zpf = 8; x = [ones(1, N) zeros(1, (zpf-1)*n)]; %rectangle window subplot(311); plot(x); title( Rectangle Window ); xlabel( Time(s) ); ylabel( Amplitude ); Nfft = N*zpf; X = fft(x); magx = abs(x); spec = 20*log10(magX); spec = spec-max(spec); spec = max(spec, -40*ones(1, length(spec))); fn = 0:1/Nfft:1-1/Nfft; subplot(312); plot(fn, spec); xlabel( Normalized Frequency (cycles per sample) ); %replot showing negative frequencies below zero X = fftshift(x); magx = abs(x); spec = 20*log10(magX); spec = spec-max(spec); spec = max(spec, -40*ones(1, length(spec))); fn = -.5:1/Nfft:.5-1/Nfft; subplot(313); plot(fn, spec); CMPT 468: Matlab Tutorial 3: Analysis with the Fast Fourier Transform (FFT) 4

xlabel( Normalized Frequency (cycles per sample) ); In practical spectrum analysis, such excerpts are normally analyzed using a window which is tapered more gracefully to zero on the left and right. In this section, we will look at using a Blackman window on our example sinusoid. The Blackman window has good (though suboptimal) characteristics for audio work. InOctaveortheMatlabSignalProcessingToolbox,aBlackmanwindowoflengthM = 64 can be designed very easily: M = 64; w = blackman(m); Many other standard windows are defined as well, including hamming, hanning, and bartlett windows. In Matlab without the Signal Processing Toolbox, the Blackman window is readily computed from its mathematical definition: w =.42 -.5*cos(2*pi*(0:M-1)/(M-1))... +.08*cos(4*pi*(0:M-1)/(M-1)); To see the spectral characteristics of the Blackman window try the following: M = 64; w = blackman(m); figure(1); subplot(3,1,1); plot(w, * ); title( Blackman Window ); xlabel( Time (samples) ); ylabel( Amplitude ); text(-8,1, a) ); % Also show the window transform: zpf = 8; % zero-padding factor xw = [w,zeros(1,(zpf-1)*m)]; % zero-padded window Xw = fft(xw); % Blackman window transform spec = 20*log10(abs(Xw)); % Spectral magnitude in db spec = spec - max(spec); % Normalize to 0 db max nfft = zpf*m; spec = max(spec,-100*ones(1,nfft)); % clip to -100 db fni = [0:1.0/nfft:1-1.0/nfft]; % Normalized frequency axis subplot(3,1,2); plot(fni,spec, - ); axis([0,1,-100,10]); grid; text(-.12,20, b) ); % Replot interpreting upper bin numbers as frequencies<0: CMPT 468: Matlab Tutorial 3: Analysis with the Fast Fourier Transform (FFT) 5

nh = nfft/2; specnf = [spec(nh+1:nfft),spec(1:nh)]; % see fftshift() fninf = fni - 0.5; subplot(3,1,3); plot(fninf,specnf, - ); axis([-0.5,0.5,-100,10]); grid; text(-.62,20, c) ); cmd = [ print -deps,../eps/blackman.eps ]; disp(cmd); eval(cmd); disp pausing for RETURN (check the plot)... ; pause CMPT 468: Matlab Tutorial 3: Analysis with the Fast Fourier Transform (FFT) 6