1. Trang chủ
  2. » Kỹ Thuật - Công Nghệ

Lecture BSc Multimedia - Chapter 2: DSP, filters and the fourier transform

107 46 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Chapter 2: DSP, filters and the fourier transform. In this chapter, you learned to: Digital signal processing and digital audio recap from CM2202; relationship between amplitude, frequency and phase; basic DSP concepts and definitions; Why use decibel scales?...

CM3106 Chapter 2: DSP, Filters and the Fourier Transform Prof David Marshall dave.marshall@cs.cardiff.ac.uk and Dr Kirill Sidorov K.Sidorov@cs.cf.ac.uk www.facebook.com/kirill.sidorov School of Computer Science & Informatics Cardiff University, UK Digital Signal Processing and Digital Audio Recap from CM2202 Issues to be Recapped: Basic Digital Signal Processing and Digital Audio Waveforms and Sampling Theorem Digital Audio Signal Processing Filters For full details please refer to last Year’s CM2202 Course Material — Especially detailed underpinning maths CM3106 Chapter Digital Signal Processing and Digital Audio Recap from CM2202 Simple Waveforms Frequency is the number of cycles per second and is measured in Hertz (Hz) Wavelength is inversely proportional to frequency i.e Wavelength varies as frequency CM3106 Chapter Basic Digital Audio Signal Processing The Sine Wave and Sound The general form of the sine wave we shall use (quite a lot of) is as follows: y = A.sin(2π.n.Fw /Fs ) where: A is the amplitude of the wave, Fw is the frequency of the wave, Fs is the sample frequency, n is the sample index MATLAB function: sin() used — works in radians CM3106 Chapter Basic Digital Audio Signal Processing Relationship Between Amplitude, Frequency and Phase CM3106 Chapter Recap: Relationship Between Amplitude, Frequency and Phase Phase of a Sine Wave sinphasedemo.m % Simple Sin Phase Demo samp_freq = 400; dur = 800; % seconds amp = 1; phase = 0; freq = 1; s1 = mysin(amp,freq,phase,dur,samp_freq); axisx = (1:dur)*360/samp_freq; % x axis in degrees plot(axisx,s1); set(gca,’XTick’,[0:90:axisx(end)]); fprintf(’Initial Wave: \t Amplitude = \n’, amp, freq, phase, ); % change amplitude phase = input(’\nEnter Phase:\n\n’); s2 = mysin(amp,freq,phase,dur,samp_freq); hold on; plot(axisx, s2,’r’); set(gca,’XTick’,[0:90:axisx(end)]); CM3106 Chapter Recap: Relationship Between Amplitude, Frequency and Phase Phase of a Sine Wave: sinphasedemo output 0.8 0.6 0.4 0.2 −0.2 −0.4 −0.6 −0.8 −1 90 180 CM3106 Chapter 270 360 450 540 630 Recap: Relationship Between Amplitude, Frequency and Phase Basic DSP Concepts and Definitions: The Decibel (dB) When referring to measurements of power or intensity, we express these in decibels (dB): XdB = 10 log10 where: X X0 X is the actual value of the quantity being measured, X0 is a specified or implied reference level, XdB is the quantity expressed in units of decibels, relative to X0 X and X0 must have the same dimensions — they must measure the same type of quantity in the the same units The reference level itself is always at dB — as shown by setting X = X0 (note: log10 (1) = 0) CM3106 Chapter Basic DSP Concepts and Definitions Why Use Decibel Scales? When there is a large range in frequency or magnitude, logarithm units often used If X is greater than X0 then XdB is positive (Power Increase) If X is less than X0 then XdB is negative (Power decrease) Power Magnitude = |X (i)|2 | so (with respect to reference level) XdB = 10 log10 (|X (i)2 |) = 20 log10 (|X (i)|) which is an expression of dB we often come across CM3106 Chapter Basic DSP Concepts and Definitions Decibel and Chillies! Decibels are used to express wide dynamic ranges in a many applications: CM3106 Chapter Basic DSP Concepts and Definitions 10 Convolution Many Useful Applications of Convolution Several important audio and optical effects can be described in terms of convolutions FIltering — In fact the above Fourier filtering is applying convolutions of a low pass filter where the equations are Fourier Transforms of real space equivalents Deblurring — high pass filtering Reverb — impulse response convolution (more soon) Note we have seen a discrete real domain example of Convolution with Edge Detection CM3106 Chapter Filtering in the Frequency Domain 93 Formal Definition of 1D Convolution: Let us examine the concepts using 1D continuous functions The convolution of two functions f (x) and g (x), written f (x) ∗ g (x), is defined by the integral f (x) ∗ g (x) = ∞ −∞ f (α)g (x − α) dα ∗ is the mathematical notation for convolution No Fourier Transform in sight here — but wait! CM3106 Chapter Filtering in the Frequency Domain 94 1D Convolution Real Domain Example (1) Convolution of Two Top Hat Functions For example, let us take two top hat functions: Let f (α) be the top hat function shown: f (α) = if |α| ≤ otherwise, and let g (α) be as shown in next slide, defined by g (α) = CM3106 Chapter 1/2 if ≤ α ≤ otherwise Filtering in the Frequency Domain 95 1D Convolution Example (2) Our Two Top Hat Functions Plots 1.0 -5.0 f (α) = 1.0 0.0 5.0 if |α| ≤ otherwise, CM3106 Chapter -5.0 0.0 g (α) = Filtering in the Frequency Domain 5.0 1/2 if ≤ α ≤ otherwise 96 1D Convolution Example (3) The Convolution Process: Graphical Interpretation g (−α) is the reflection of this function in the vertical y -axis, g (x − α) is the latter shifted to the right by a distance x Thus for a given value of x, f (α)g (x − α) integrated over all α is the area of overlap of these two top hats, as f (α) has unit height An example is shown for x in the range −1 ≤ x ≤ opposite CM3106 Chapter Filtering in the Frequency Domain 1.0 -5.0 x 0.0 5.0 97 1D Convolution Example (4) So the solution is: If we now consider x moving from −∞ to +∞, we can see that For x ≤ −1 or x ≥ 2, there is no overlap; As x goes from −1 to the area of overlap steadily increases from to 1/2; As x increases from0 to 1, the overlap area remains at 1/2; Finally as x increases from to 2, the overlap area steadily decreases again from 1/2 to Thus the convolution of f (x) and g (x), f (x) ∗ g (x), in this case has the form shown on next slide CM3106 Chapter Filtering in the Frequency Domain 98 1D Convolution Example (5) 1.0 -5.0 0.0 5.0 Result of f (x) ∗ g (x) CM3106 Chapter Filtering in the Frequency Domain 99 1D Convolution Example (6) Mathematically the convolution is expressed by:  (x + 1)/2    1/2 f (x) ∗ g (x) =  − x/2   if −1 ≤ x ≤ if ≤ x ≤ if ≤ x ≤ otherwise 1.0 -5.0 CM3106 Chapter 0.0 5.0 Filtering in the Frequency Domain 100 Fourier Transforms and Convolution Convolution Theorem: Convolution in Frequency Space is Easy One major reason that Fourier transforms are so important in signal/image processing is the convolution theorem which states that: If f (x) and g (x) are two functions with Fourier transforms F (u) and G (u), then the Fourier transform of the convolution f (x) ∗ g (x) is simply the product of the Fourier transforms of the two functions, F (u)G (u) CM3106 Chapter Filtering in the Frequency Domain 101 Fourier Transforms and Convolution (Cont.) Recall our Low Pass Filter Example (MATLAB CODE) % Apply filter G=H.*F; Where F was the Fourier transform of the image, H the filter CM3106 Chapter Filtering in the Frequency Domain 102 Computing Convolutions with the Fourier Transform Example Applications: To apply some reverb to an audio signal To compensate for a less than ideal image capture system More soon CM3106 Chapter Filtering in the Frequency Domain 103 Example Applications (Cont.) Deconvolution: Compensating for undesirable effects To this fast convolution we simply: Take the Fourier transform of the audio/imperfect image, Take the Fourier transform of the function describing the effect of the system, Multiply by the effect to apply effect to audio data To remove/compensate for effect: Divide by the effect to obtain the Fourier transform of the ideal image Inverse Fourier transform to recover the new improved audio image This process is sometimes referred to as deconvolution CM3106 Chapter Filtering in the Frequency Domain 104 Image Deblurring Deconvolution Example Inverting our Previous Low-Pass Filter Recall our Low Pass (Butterworth) Filter example of a few slides ago: butterworth.m: deconv.m and deconv2.m reuses this code and adds a deconvolution stage: Our computed butterworth low pass filter, H is our blurring function So to simply invert this we can divide (as opposed to multiply) by H with the blurred image G — effectively a high pass filter Ghigh = G./H; ghigh=real(ifft2(double(Ghigh))); figure(5) imshow(ghigh) In this ideal example we clearly get F back and to get the image simply to inverse Fourier Transfer In the real world we don’t really know the exact blurring function H so things are not so easy (a) Input Image CM3106 Chapter (b) Blurred Low-Pass Filtered Image Filtering in the Frequency Domain (c) Deconvolved Image 105 deconv2.m results (a) Input Image (b) Blurred Low-Pass Filtered Image (c) Deconvolved Image CM3106 Chapter Filtering in the Frequency Domain 106 Deconvolution is not always that simple! Origial Image Deconvolved (a) Input Image Image with Noise Added (c) Input Noisy Image CM3106 Chapter (b) Deconvolved Image Deconvolved Noisy Image (d) Deconvolved Noisy Image Filtering in the Frequency Domain 107 ... Responses DSP + Image Proc.: Filters and other processing, Convolution CM3106 Chapter Moving into the Frequency Domain 50 Fourier Theory Introducing The Fourier Transform The tool which converts a... amplitude, frequency and phase When added back together they reconstitute the original signal The Fourier transform is the tool that performs such an operation CM3106 Chapter Moving into the Frequency... b(2)*x(n-1) + + b(nb+1)*x(n-nb) - a(2)*y(n-1) - - a(na+1)*y(n-na) If a(1) is not equal to 1, FILTER normalizes the filter coefficients by a(1) FILTER always operates along the first non-singleton

Ngày đăng: 12/02/2020, 14:09

Xem thêm: