Scilab Week 7. October 5, In this assignment, the focus will be on Fourier Transforms to solve various problems. ( t

Similar documents
SIGNAL PROCESSING & SIMULATION NEWSLETTER

SWISS ARMY KNIFE INDICATOR John F. Ehlers

Review of Fourier series formulas. Representation of nonperiodic functions. ECE 3640 Lecture 5 Fourier Transforms and their properties

Second Order Linear Nonhomogeneous Differential Equations; Method of Undetermined Coefficients. y + p(t) y + q(t) y = g(t), g(t) 0.

OPERATIONAL AMPLIFIERS. o/p

Basic Electronics Prof. Dr. Chitralekha Mahanta Department of Electronics and Communication Engineering Indian Institute of Technology, Guwahati

FFT Algorithms. Chapter 6. Contents 6.1

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

MATH 4330/5330, Fourier Analysis Section 11, The Discrete Fourier Transform

The continuous and discrete Fourier transforms

ELECTRICAL ENGINEERING

Auto-Tuning Using Fourier Coefficients

L9: Cepstral analysis

Lecture 27: Mixers. Gilbert Cell

Trigonometric functions and sound

Loop Bandwidth and Clock Data Recovery (CDR) in Oscilloscope Measurements. Application Note

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

CHAPTER 6 Frequency Response, Bode Plots, and Resonance

Signal to Noise Instrumental Excel Assignment

Frequency Response of Filters

Chapter 19 Operational Amplifiers

Introduction to Digital Audio

7. Beats. sin( + λ) + sin( λ) = 2 cos(λ) sin( )

Lecture 8 ELE 301: Signals and Systems

FEGYVERNEKI SÁNDOR, PROBABILITY THEORY AND MATHEmATICAL

Positive Feedback and Oscillators

BSEE Degree Plan Bachelor of Science in Electrical Engineering:

Filter Comparison. Match #1: Analog vs. Digital Filters

Analysis/resynthesis with the short time Fourier transform

The front end of the receiver performs the frequency translation, channel selection and amplification of the signal.

3.2 Sources, Sinks, Saddles, and Spirals

AM Receiver. Prelab. baseband

Introduction to Digital Filters

Basic Op Amp Circuits

Angle Modulation, II. Lecture topics FM bandwidth and Carson s rule. Spectral analysis of FM. Narrowband FM Modulation. Wideband FM Modulation

Scaling and Biasing Analog Signals

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

So far, we have looked at homogeneous equations

PCM Encoding and Decoding:

Basics of Digital Recording

Active Vibration Isolation of an Unbalanced Machine Spindle

CHAPTER 5 Round-off errors

RF Network Analyzer Basics

PURSUITS IN MATHEMATICS often produce elementary functions as solutions that need to be

The Critical Length of a Transmission Line

Analog Filters. A common instrumentation filter application is the attenuation of high frequencies to avoid frequency aliasing in the sampled data.

System Modeling and Control for Mechanical Engineers

MATH Fundamental Mathematics IV

Review of Fundamental Mathematics

The Effective Number of Bits (ENOB) of my R&S Digital Oscilloscope Technical Paper

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

CDMA TECHNOLOGY. Brief Working of CDMA

Design of FIR Filters

x 2 + y 2 = 1 y 1 = x 2 + 2x y = x 2 + 2x + 1

FOURIER TRANSFORM BASED SIMPLE CHORD ANALYSIS. UIUC Physics 193 POM

Coupled Inductors. Introducing Coupled Inductors

Lab 1. The Fourier Transform

Implementation of Digital Signal Processing: Some Background on GFSK Modulation

Precision Diode Rectifiers

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

III. Reaction Kinetics

LS.6 Solution Matrices

Introduction to IQ-demodulation of RF-data

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Linda Shapiro Winter 2015

Operation Count; Numerical Linear Algebra

VCO K 0 /S K 0 is tho slope of the oscillator frequency to voltage characteristic in rads per sec. per volt.

Convolution. The Delta Function and Impulse Response

Analog Signal Conditioning

The Method of Partial Fractions Math 121 Calculus II Spring 2015

Clock Recovery in Serial-Data Systems Ransom Stephens, Ph.D.

Linear Filtering Part II

Operational Amplifier - IC 741

Lecture 14. Point Spread Function (PSF)

Introduction to Complex Fourier Series

Analog and Digital Signals, Time and Frequency Representation of Signals

9 Fourier Transform Properties

PYKC Jan Lecture 1 Slide 1

RANDOM VIBRATION AN OVERVIEW by Barry Controls, Hopkinton, MA

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

5.1 Radical Notation and Rational Exponents

Lab 1: The Digital Oscilloscope

Timing Errors and Jitter

Digital to Analog Converter. Raghu Tumati

2x + y = 3. Since the second equation is precisely the same as the first equation, it is enough to find x and y satisfying the system

Line Monitoring and Control in Subsea Networks

General Framework for an Iterative Solution of Ax b. Jacobi s Method

The Operational Amplfier Lab Guide

LOW COST MOTOR PROTECTION FILTERS FOR PWM DRIVE APPLICATIONS STOPS MOTOR DAMAGE

Correlation and Convolution Class Notes for CMSC 426, Fall 2005 David Jacobs

Harmonics and Noise in Photovoltaic (PV) Inverter and the Mitigation Strategies

1 Review of Least Squares Solutions to Overdetermined Systems

Nodal and Loop Analysis

Image Compression through DCT and Huffman Coding Technique

PRE-CALCULUS GRADE 12

The Fourier Analysis Tool in Microsoft Excel

Lecture - 4 Diode Rectifier Circuits

Mutual Inductance and Transformers F3 3. r L = ω o

Lecture 18: The Time-Bandwidth Product

ε: Voltage output of Signal Generator (also called the Source voltage or Applied

B3. Short Time Fourier Transform (STFT)

Transcription:

Scilab Week 7 October 5, 2009 In this assignment, the focus will be on Fourier Transforms to solve various problems Study the spectra of data Solve differential equations Filter data to extract interesting information 1 Fourier Analysis The Fourier Transform is defined by F(ω) = 1 f (t)e jωt dt, 2π work in frequency domain, solve our problem there, and invert to get the solution f (t) = F(ω)e jωt dω. Note that you can put the factor of 1/2π in front of either integral. Also note that the sign of the exponent is opposite for the two integrals. You have studied in Maths and in Networks that F(ω) is unique given f (t) The Fourier transform is a linear transformation. i.e., the transform of a linear combination of f (t) and g(t) is the same linear combination of F(ω) and G(ω). The transform of a convolution is the product of the transforms, i.e., if then h(t) = f (τ)g(t τ)dτ H(ω) = F(ω)G(ω) The transforms of a derivitive and indefinite integral are simpler in the Transform domain: ( ) d f F dt,t ω = jωf(ω) ( t ) F f dτ,t ω = F(ω) jω Many problems are solved using Fourier transforms. In electrical engineering, the following are some of the types of ways we use Fourier transforms: 1

Harmonic content of nonlinear circuits driven by a phasor source. For instance if a diode switches on and off based on the sign of the voltage across it, what harmonics are induced? Fourier spectrum of AM and FM modulated signals. Frequency response of a circuit. This has been done last time using Laplace transfroms, but it can be done in the Fourier domain as well. Studying the transfer function of a system to know if it is stable under feedback. This is a crucial part of control systems theory and analog circuit theory. The spectrum of noise. Central to communications theory and control systems theory. Filter design. We want to isolate a desired part of the spectrum. How to do it in fourier domain, and how to do it in time domain itself. System identification: An earthquake has occurred and you have the trace. How to analyse it, knowing the type of trace an earthquake can give to identify where and when it occurred and what type and how strong it was. This often uses fourier methods as part of the process of system identification. Adaptive circuits: You want to listen to a radio station, but its transmission frequency is not constant (or your receiver s tuner is not stable). How to lock the receiver to the transmitted signal? These are known as phase locked loops. Also analysed and designed using fourier methods, since what we are tracking is a frequency signal. We will take some sample problems here to look at. 2 Digital Fourier Transforms Now, computers are not good at performing continuous integrals over unbounded domains, and so these equations are not useful as they are. However, we know that the Fourier Transform is just the limit of the Fourier Series. So we can solve the Fourier Series problem that is nearest to the exact problem and get an approximate solution. But even that is too complicated, since the general function has an infinite number of fourier coefficients. So we keep only a finite number of fourier coefficients to get to the computer approximation of the Fourier Transform. Let us take an example: f (t) = 1 1 +t 2 e t2 The plot of the function looks as follows: 2

f 1.0 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0.0 3 2 1 0 1 2 3 t Since the plot goes nearly to zero, we can safely ignore the rest of the function. Even better, we can make copies of f (t) every 6 seconds to make it a periodic function, g(t). The plot of g(t) looks like this 1.0 0.9 0.8 0.7 0.6 g(t) 0.5 0.4 0.3 0.2 0.1 0.0 10 8 6 4 2 0 2 4 6 8 10 t Then a Fourier series will do the job. We write g(t) = n= c n e jnωt where ω = 2π/6. Since the function is even and real, the fourier series is also even and real, and so it collapses into a cosine series: g(t) = n=0 a n cos(nωt) 3

We can compute the coefficients as a 0 = 1 6 a n = 1 3 3 3 3 3 g(t)dt g(t)cos(nωt)dt Using the intg function that is built in, we can compute the integrals. The code is as follows [branch code0: 4 * 4 global count; function y=g(t) global count; count=count+1 y=exp(-t.^2)./(1+t.^2); endfunction function y=gn(t) global count; count=count+1; y=exp(-t.^2).*cos(n*omega*t)./(1+t.^2); endfunction omega=2*%pi/6; count=0; a=zeros(21,1); a(1)=intg(0,3,g)/3; for n=1:20 a(n+1)=intg(0,3,gn)/1.5; end bar(0:20,a); xtitle("fourier coefficients","n","a(n)"); mprintf("number of times function called: %d\n",count); 4

] The coefficients look as follows: Fourier coefficients 0.25 0.20 0.15 a(n) 0.10 0.05 0.00 0.05 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 n Now, while this works, we are actually doing numerical integration to compute each coefficient. That is quite expensive. If you run the above code, you find that the function was called 8883 times, or about 450 times per coefficient. In practical situations we often take fourier transforms of very large data sets (could be millions of elements). We need a faster method. This faster method is called the Discrete Fourier Transform or the DFT. You will learn the mathematics in your ADSP course. The main thing about it is that the integral to compute the coefficients collapses to a sum. We first sample the function f (t) at N times over a time period t 0, t 0 + t, etc to get N samples f 0, f 1,..., f N 1. The DFT is then defined by: f n = F k = 1 N N 1 F k e j2πkn/n k=0 N 1 f n e j2πkn/n n=0 The coefficients F n are closely related to the coefficients a n in the exact Fourier series. We can go from F n to a cosine series Comparing we can see that or, N/2 1 f n = A 0 + k=1 A k cos(2πnk/n) 2π kn N nωt 2π N ω t which is reasonable, since N t should correspond to a period, i.e., 2π/ω. The DFT is a much better algorithm than the integration method above, since only N evaluations are done. To get 21 coefficients, we would only evaluate the function 21 times. Let us compute the coefficients using the DFT and compare them to the fourier 5

6a 6b series values. Note that we have to compute 41 coefficients, since each cosine is equivalent to two complex exponentials. * 4 + N=41; t=linspace(-3,3,n+1);t=t(1:n); This peculiar piece of code is to get 41 samples between 0 and 6, not counting both t = 0 and t = 6, since they are the same point. So I get 42 points including the end points and discard the 42 nd point. * 4 + f=fftshift(g(t)); F=dft(f,-1)/N; A=zeros(21,1); A(1)=F(1); A(2:21)=F(2:21)+F(41:-1:22); clf bar(1:21,[a real(a)]); legends(["exact";"dft"],2:3); 6

The result is plotted below 0.40 0.35 0.30 exact DFT 0.25 0.20 0.15 0.10 0.05 0.00 0.05 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 It is obvious that the coefficients are not the same. In fact, they should not be. After all, the DFT is computing the integral using 21 uniformly spaced samples of f (t). Only if the integral can be exactly calculated from those samples, will the coefficients agree. Which means that the more samples we take, the more accurate will be the approximation. So let us take (say) 256 samples. 7 * 4 + N=256; t=linspace(-3,3,n+1);t=t(1:n); ff=fftshift(g(t)); FF=dft(ff,-1)/N; AA=zeros(21,1); AA(1)=FF(1); AA(2:21)=FF(2:21)+FF(N:-1:N-19); clf bar(1:21,[a real(aa)]); legends(["exact";"dft-256"],2:3) 7

Now we get the following: 0.40 0.35 0.30 exact DFT 256 0.25 0.20 0.15 0.10 0.05 0.00 0.05 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 The errors are as follows: 8 * 4 + [(1:21) real(a)-a real(aa)-a] 8

The answer that Scilab gives is shown below 1. - 4.781E-08-1.242E-09 2. - 0.0011045 2.485E-09 3. - 0.0026768-2.485E-09 4. - 0.0027972 2.485E-09 5. - 0.0019422-2.486E-09 6. - 0.0010921 2.487E-09 7. - 0.0005517-2.487E-09 8. - 0.0002619 2.488E-09 9. - 0.0001192-2.490E-09 10. - 0.0000525 2.491E-09 11. - 0.0000225-2.492E-09 12. - 0.0000095 2.494E-09 13. - 0.0000039-2.496E-09 14. - 0.0000016 2.497E-09 15. - 0.0000006-2.500E-09 16. - 0.0000003 2.502E-09 17. - 3.128E-08-2.504E-09 18. - 0.0000001 2.507E-09 19. 6.934E-08-2.509E-09 20. - 9.917E-08 2.512E-09 21. 0.0000001-2.515E-09 These errors we get for small N are due to the fact that the integral cannot be properly evaluated given only a few points. The technical name for this problem is aliasing, something about which you will learn a lot in your ADSP course. 3 The Fast Fourier Transform Well that was good. We could compute a decently accurate Fourier series using a few samples. No need for integration. But to do a good job we needed a lot of samples, and the computation of the sum requires a large number (roughly N 2 ) multiplications of complex numbers. That is still very expensive. Instead of 8000 function evaluations we are now doing 64000 complex multiplications! There is a better way, through an algorithm known as the Fast Fourier Transform or FFT. It computes exactly the same DFT but uses only about 3N log 2 N computations. For N = 256, this works out to be about 3000 complex multiplications. As N increases, the savings become huge. As far as Scilab is concerned, the only changes required to use the FFT are: N must be a power of 2. Instead of a command like F=dft(f,-1) we instead have a command like F=fft(f,-1). That s it. Nothing else changes, but the speed up is huge, and the memory utilization is far less. If you did the dft calculation with a few thousand samples, you would run out of memory. No such problems with fft. 4 Filtering and Data Analysis Suppose we have data whose frequencies of interest lie in a range. We can extract that data by suitable filtering. For example, consider f (t) = A(t)cost + B(t)cos2t 9

where A(t) and B(t) are signals which vary very slowly. Then, we can filter out the cos2t term and analyse only A(t). The steps are as follows: Obtain the fourier transform of f (t). Plot the magnitude spectrum and identify the frequencies you want and the frequencies you want to reject. Zero the entries of F(ω) for those frequencies you want to reject. This operation is called filtering, and in this case, we are low pass filtering since we are throwing away the high frequencies. The main thing to keep in mind is that you must keep both the positive low frequencies and the negative low frequencies, i.e., keep terms corresponding to n = 0 to k and n = N k to N 1 while throwing away the rest. Get back the filtered f (t) by inverse fourier transforming. Multiply all the terms of the signal with cost. Fourier transform the signal again. Now we are taking the fourier transform of ( ) 1 + cos2t A(t)cos 2 t = A(t) 2 Again filter to reject the cos2t term. Inverse transform to get A(t) itself. 5 The Assignment 1. Compute the exact fourier series and the DFT for the following periodic function f (t) = 1 1 + cos 2 t How exact are the solutions if you use 16 terms. How many terms were needed for the error to become negligible? Do you understand this result? 2. Compute the sine fourier series and extract the corresponding terms from the DFT for the function. How many terms were needed for the result to become exact? 3. Solve the differential equation f (t) = sin 3 (t + 1) d 2 y dt 2 + y = cos(3t) Note that this is not an initial value problem - we would use Laplace Transforms for that. You will have to Fourier transform the equation, solve it in frequency domain, and then invert back to get the function in real time. To do that, use y=fft(y,1). Note: You have to figure out how to implement the derivitive in the DFT. Basically a term like e j2πkn/n e jnωt and the derivitive will pull out jnω. Here your ω is unity, which gives you the factor to use. 10

Note: Another problem you will face is that of a zero in the denominator. Handle it by adding a tiny number (say 10 14 ) to eliminate the singularity. Note: You will have to play around with the factors of N. fft often has the factor of N built in. Look at the fourier transform and decide if the answer is reasonble. How many samples are required for an accurate answer? Verify the answer by direct differentiation. How does the error scale with N? Do you understand this? 4. Given a signal f (t) = J 0 (0.01t)cost + cos2t where J 0 (x) is the the Bessel function of zeroth order. You can compute it in Scilab by besselj(0,x). Create a Scilab function to generate the function f (t), Sample it from t = 0 to t = 500 with 8 samples per 2π. Filter as explained above to extract the coefficient of cost. Plot the function extracted along with J 0 (0.01t) itself and compare to see if the extraction worked. This is nothing but an example of AM modulation. There are many uses of the Fourier transform, and you should get very familiar with it. 11