0% found this document useful (0 votes)
84 views71 pages

Frequency Space

Moving into the Frequency Domain discusses transforming signals from the time or spatial domain to the frequency domain using the Fourier transform. The Fourier transform decomposes signals into constituent sinusoidal frequency components, allowing analysis and processing in the frequency domain before transforming back. For example, an audio signal can be described by amplitude over time or by the amplitudes of different frequency components over time. The document provides examples of how this applies to 1D signals like audio and 2D signals like images.

Uploaded by

Hafid Scooterist
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views71 pages

Frequency Space

Moving into the Frequency Domain discusses transforming signals from the time or spatial domain to the frequency domain using the Fourier transform. The Fourier transform decomposes signals into constituent sinusoidal frequency components, allowing analysis and processing in the frequency domain before transforming back. For example, an audio signal can be described by amplitude over time or by the amplitudes of different frequency components over time. The document provides examples of how this applies to 1D signals like audio and 2D signals like images.

Uploaded by

Hafid Scooterist
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 71

Moving into the Frequency Domain

Frequency domains can be obtained through the transformation from one (Time or Spatial) domain to the other (Frequency) via Fourier Transform (FT)
CM0268 MATLAB DSP GRAPHICS

261

Fourier Transform (FT) MPEG Audio Related Discrete Cosine Transform (DCT) Heart of JPEG and
MPEG Video, (alt.) MPEG Audio. Not Studied here CM0340 Multimedia (YEAR 3)
1

Back Close

1D Example
Lets consider a 1D (e.g. Audio) example to see what the different domains mean: Consider a complicated sound such as the noise of a car horn. We can describe this sound in two related ways: Sample the amplitude of the sound many times a second, which gives an approximation to the sound as a function of time.
1

CM0268 MATLAB DSP GRAPHICS

262

Analyse the sound in terms of the pitches of the notes, or frequencies, which make the sound up, recording the amplitude of each frequency.

Back Close

An 8 Hz Sine Wave
In the example (next slide): A signal that consists of a sinusoidal wave at 8 Hz. 8 Hz means that wave is completing 8 cycles in 1 second The frequency of that wave (8 Hz). From the frequency domain we can see that the composition of our signal is one wave (one peak) occurring with a frequency of 8 Hz with a magnitude/fraction of 1.0 i.e. it is the whole signal.
1

CM0268 MATLAB DSP GRAPHICS

263

Back Close

An 8 Hz Sine Wave (Cont.)

CM0268 MATLAB DSP GRAPHICS

264

Back Close

2D Image Example
Now images are no more complex really: Brightness along a line can be recorded as a set of values measured at equally spaced distances apart, Or equivalently, at a set of spatial frequency values. Each of these frequency values is a frequency component. An image is a 2D array of pixel measurements. We form a 2D grid of spatial frequencies. A given frequency component now species what contribution is made by data which is changing with specied x and y direction spatial frequencies.
Back Close
1

CM0268 MATLAB DSP GRAPHICS

265

What do frequencies mean in an image?


Large values at high frequency components then the data is changing rapidly on a short distance scale. e.g. a page of text Large low frequency components then the large scale features of the picture are more important. e.g. a single fairly simple object which occupies most of the image.
1

CM0268 MATLAB DSP GRAPHICS

266

Back Close

How to Filter?
Low pass lter Ignore high frequency noise components make zero or a very low value. Only store lower frequency components
CM0268 MATLAB DSP GRAPHICS

267

Back Close

Visualising Frequency Domain Transforms


Any function (signal) can be decomposed into purely sinusoidal components (sine waves of different size/shape) When added together make up our original signal. Fourier transform is the tool that performs such an operation
CM0268 MATLAB DSP GRAPHICS

268

Back Close

Summing Sine Waves


Digital signals are composite signals made up of many sinusoidal frequencies
CM0268 MATLAB DSP GRAPHICS

269

Back Close

Summing Sine Waves to give a Square(ish) Wave


We can take the previous example a step further: A 200Hz digital signal (square(ish) wave) may be a composed of 200, 600, 1000, 1400, 1800, 2200, 2600, 3000, 3400 and 3800 sinusoidal signals which sum to give:

CM0268 MATLAB DSP GRAPHICS

270

Back Close

So What Does All This Mean?


Transforming a signal into the frequency domain allows us To see what sine waves make up our underlying signal E.g. One part sinusoidal wave at 50 Hz and Second part sinusoidal wave at 200 Hz. More complex signals will give more complex graphs but the idea is exactly the same.
1

CM0268 MATLAB DSP GRAPHICS

271

Filtering now involves attenuating or removing certain frequencies easily performed. The graph of the frequency domain is called the frequency spectrum more soon
Back Close

Visualising Frequency Domain: Think Graphic Equaliser


An easy way to visualise what is happening is to think of a graphic equaliser on a stereo system (or some software audio players, e.g. iTunes).

CM0268 MATLAB DSP GRAPHICS

272

Back Close

Fourier Theory The tool which converts a spatial (real space) description of audio/image data into one in terms of its frequency components is called the Fourier transform The new version is usually referred to as the Fourier space description of the data. We then essentially process the data: E.g. for ltering basically this means attenuating or setting certain frequencies to zero We then need to convert data back to real audio/imagery to use in our applications. The corresponding inverse transformation which turns a Fourier space description back into a real space one is called the inverse Fourier transform.
1

CM0268 MATLAB DSP GRAPHICS

273

Back Close

Fourier Transform
1D Case (e.g. Audio Signal) Considering a continuous function f (x) of a single variable x representing distance. The Fourier transform of that function is denoted F (u), where u represents spatial frequency is dened by

CM0268 MATLAB DSP GRAPHICS

274

F (u) =

f (x)e2ixu dx.
1

Note: In general F (u) will be a complex quantity even though the original data is purely real. The meaning of this is that not only is the magnitude of each frequency present important, but that its phase relationship is too.

Back Close

Inverse 1D Fourier Transform The inverse Fourier transform for regenerating f (x) from F (u) is given by

CM0268 MATLAB DSP GRAPHICS

275

f ( x) =

F (u)e2ixu du,

which is rather similar, except that theexponential term has the opposite sign. not negative
1

Back Close

Example Fourier Transform


Lets see how we compute a Fourier Transform: consider a particular function f (x) dened as f (x ) = 1 if |x| 1 0 otherwise,
CM0268 MATLAB DSP GRAPHICS

276

1
Back Close

So its Fourier transform is:

F (u) =
1

f (x)e2ixu dx 1e
1 2ixu

dx

CM0268 MATLAB DSP GRAPHICS

1 2iu = (e e2iu) 2iu sin 2u = . u In this case F (u) is purely real, which is a consequence of the original data being symmetric in x and x.

277

A graph of F (u) is shown overleaf. This function is often referred to as the Sinc function.
Back Close

The Sync Function The Fourier transform of a top hat function:


CM0268 MATLAB DSP GRAPHICS

278

Back Close

2D Case (e.g. Image data)


If f (x, y ) is a function, for example the brightness in an image, its Fourier transform is given by

CM0268 MATLAB DSP GRAPHICS

279

F (u, v ) =

f (x, y )e2i(xu+yv) dx dy,

and the inverse transform, as might be expected, is


1

f (x, y ) =

F (u, v )e2i(xu+yv) du dv.

Back Close

But All Our Audio and Image data are Digitised!!


Thus, we need a discrete formulation of the Fourier transform: Which takes such regularly spaced data values, and Returns the value of the Fourier transform for a set of values in frequency space which are equally spaced. This is done quite naturally by replacing the integral by a summation, to give the discrete Fourier transform or DFT for short. In 1D it is convenient now to assume that x goes up in steps of 1, and that there are N samples, at values of x from 0 to N 1.

CM0268 MATLAB DSP GRAPHICS

280

Back Close

1D Discrete Fourier transform


So the DFT takes the form 1 F (u) = N while the inverse DFT is
N 1 N 1
CM0268 MATLAB DSP GRAPHICS

f (x)e2ixu/N ,
x=0

281

f (x ) =
x=0

F (u)e2ixu/N .
1

NOTE: Minor changes from the continuous case are a factor of 1/N in the exponential terms, and also the factor 1/N in front of the forward transform which does not appear in the inverse transform.

Back Close

2D Discrete Fourier transform


The 2D DFT works is similar. So for an N M grid in x and y we have 1 F (u, v ) = NM and f (x, y ) =
u=0 v =0 N 1 M 1
CM0268 MATLAB DSP GRAPHICS

282

f (x, y )e2i(xu/N +yv/M ),


x=0 y =0

N 1 M 1

F (u, v )e2i(xu/N +yv/M ).

Back Close

Balancing the 2D DFT


Often N = M , and it is then it is more convenient to redene F (u, v ) by multiplying it by a factor of N , so that the forward and inverse transforms are more symmetrical:
CM0268 MATLAB DSP GRAPHICS

283

1 F (u, v ) = N and

N 1 N 1

f (x, y )e2i(xu+yv)/N ,
x=0 y =0

1 f (x, y ) = N

N 1 N 1

F (u, v )e2i(xu+yv)/N .
u=0 v =0
Back Close

Visualising the Fourier Transform


Its useful to visualise the Fourier Transform Standard tools Easily plotted in MATLAB
CM0268 MATLAB DSP GRAPHICS

284

Back Close

The Magnitude Spectrum of Fourier Transform


Recall that the Fourier Transform of even our real audio/image data is always complex. How can we visualise a complex data array? Compute the absolute value of the complex data: |F (k )| =
2 (k ) + F 2 (k ) for k = 0, 1, . . . , N 1 FR I

CM0268 MATLAB DSP GRAPHICS

285

where FR (k ) is the real part and FI (k ) of the N sampled Fourier Transform, F (k ). This is called the magnitude spectrum of the Fourier Transform Easy in MATLAB: Sp = abs(fft(X,N))/N; (Normalised form)

Back Close

The Phase Spectrum of the Fourier Transform


The Fourier Transform also represent phase, the phase spectrum is given by: = arctan FI (k ) for k = 0, 1, . . . , N 1 FR (k )

CM0268 MATLAB DSP GRAPHICS

286

Back Close

Relating a Sample Point to a Frequency Point


When plotting graphs of FT Spectra and doing other FT processing we may wish to plot the x-axis in Hz (Frequency) rather than sample point number k = 0, 1, . . . , N 1 There is a simple relation between the two: The sample points go in steps k = 0, 1, . . . , N 1 For a given sample point k the frequency relating to this is given by: fs fk = k N where fs is the sampling frequency and N the number of samples. s Thus we have equidistant frequency steps of f N ranging from 1 0 Hz to NN fs Hz

CM0268 MATLAB DSP GRAPHICS

287

Back Close

MATLAB Fourier Frequency Spectra Example


The following code (fourierspectraeg.m):
N=16; x=cos(2*pi*2*(0:1:N-1)/N); figure(1) subplot(3,1,1);stem(0:N-1,x,.); axis([-0.2 N -1.2 1.2]); legend(Cosine signal x(n)); ylabel(a)); xlabel(n \rightarrow); X=abs(fft(x,N))/N; subplot(3,1,2);stem(0:N-1,X,.); axis([-0.2 N -0.1 1.1]); legend(Magnitude spectrum |X(k)|); ylabel(b)); xlabel(k \rightarrow) N=1024; x=cos(2*pi*(2*1024/16)*(0:1:N-1)/N); FS=40000; f=((0:N-1)/N)*FS; X=abs(fft(x,N))/N; subplot(3,1,3);plot(f,X); axis([-0.2*44100/16 max(f) -0.1 1.1]); legend(Magnitude spectrum |X(f)|); ylabel(c)); xlabel(f in Hz \rightarrow) figure(2) subplot(3,1,1); plot(f,20*log10(X./(0.5))); axis([-0.2*44100/16 max(f) ... -45 20]); legend(Magnitude spectrum |X(f)| ... in dB); ylabel(|X(f)| in dB \rightarrow); xlabel(f in Hz \rightarrow)

CM0268 MATLAB DSP GRAPHICS

288

Back Close

MATLAB Fourier Frequency Spectra Example (Cont.) The above code produces the following:
1 a) 0 1 0 2 4 6 8 n 10 12 14 16 Cosine signal x(n)
CM0268 MATLAB DSP GRAPHICS

289

1 b) 0.5 0 0 2 4 6 8 k 10

Magnitude spectrum |X(k)|

12

14

16
1

1 0.5 0 0 0.5 1 1.5 2 f in Hz 2.5 c)

Magnitude spectrum |X(f)|

3.5 x 10
4

Back Close

Magnitude Spectrum in dB
Note: It is common to plot both spectra magnitude (also frequency ranges not show here) on a dB/log scale: (Last Plot in above code)
|X(f)| in dB 20 0 20 40 0 0.5 1 1.5 2 f in Hz 2.5 3 3.5 x 10
4
1

CM0268 MATLAB DSP GRAPHICS

290

Magnitude spectrum |X(f)| in dB

Back Close

Time-Frequency Representation: Spectrogram


It is often useful to look at the frequency distribution over a short-time: Split signal into N segments Do a windowed Fourier Transform Window needed to reduce leakage effect of doing a short sample FFT.

CM0268 MATLAB DSP GRAPHICS

291

Apply a Blackman, Hamming or Hanning Window MATLAB function does the job: Spectrogram see help spectrogram See also MATLABs specgramdemo
Back Close

MATLAB Example
The code:
load(handel) [N M] = size(y); figure(1) spectrogram(fft(y,N),512,20,1024,Fs);
CM0268 MATLAB DSP GRAPHICS

292

Produces the following:

Back Close

Filtering in the Frequency Domain


Low Pass Filter
Example: Frequencies above the Nyquist Limit, Noise:
CM0268 MATLAB DSP GRAPHICS

293

The idea with noise Filtering is to reduce various spurious effects


of a local nature in the image, caused perhaps by noise in the acquisition system, arising as a result of transmission of the data, for example from a space probe utilising a low-power transmitter.

Back Close

Frequency Space Filtering Methods


Noise = High Frequencies:
CM0268 MATLAB DSP GRAPHICS

In audio data many spurious peaks in over a short timescale. In an image means there are many rapid transitions (over a short
distance) in intensity from high to low and back again or vice versa, as faulty pixels are encountered.

294

Not all high frequency data noise though!


Therefore noise will contribute heavily to the high frequency components of the image when it is considered in Fourier space. Thus if we reduce the high frequency components Low-Pass Filter, we should reduce the amount of noise in the data.
Back Close
1

(Low-pass) Filtering in the Fourier Space


We thus create a new version of the image in Fourier space by computing

G(u, v ) = H (u, v )F (u, v )


where:

CM0268 MATLAB DSP GRAPHICS

295

F (u, v ) is the Fourier transform of the original image, H (u, v ) is a lter function, designed to reduce high frequencies,
and

G(u, v ) is the Fourier transform of the improved image.


1

Inverse Fourier transform G(u, v ) to get g (x, y ) our improved


image

Note: Discrete Cosine Transform approach identical, sub. FT with


DCT
Back Close

Ideal Low-Pass Filter


The simplest sort of lter to use is an ideal low-pass lter, which in one dimension appears as :
2.0 H(u)
CM0268 MATLAB DSP GRAPHICS

296

u0

Back Close

Ideal Low-Pass Filter (Cont.)


2.0 H(u)
CM0268 MATLAB DSP GRAPHICS

297

u0

u
1

This is a top hat function which is 1 for u between 0 and u0 , the cut-off frequency, and zero elsewhere.

So All frequency space space information above u0 is thrown away, and all information below u0 is kept. A very simple computational process.
Back Close

Ideal 2D Low-Pass Filter


The two dimensional analogue of this is the function

H (u, v ) =

1 if u2 + v 2 w0 0 otherwise,

CM0268 MATLAB DSP GRAPHICS

298

where w0 is now the cut-off frequency. Thus, all frequencies inside a radius w0 are kept, and all others discarded.
1

w0

Back Close

Not So Ideal Low-Pass Filter?


The problem with this lter is that as well as the noise:
CM0268 MATLAB DSP GRAPHICS

In audio: plenty of other high frequency content In Images: edges (places of rapid transition from light to dark)
also signicantly contribute to the high frequency components. Thus an ideal low-pass lter will tend to blur the data:

299

High audio frequencies become mufed Edges in images become blurred.


The lower the cut-off frequency is made, the more pronounced this effect becomes in useful data content
Back Close

Ideal Low Pass Filter Example 1

CM0268 MATLAB DSP GRAPHICS

300

(a) Input Image

(b) Image Spectra

(c) Ideal Low Pass Filter

(d) Filtered Image


Back Close

Ideal Low-Pass Filter Example 1 MATLAB Code


low pass.m:
% Create a white box on a black background image M = 256; N = 256; image = zeros(M,N) box = ones(64,64); %box at centre image(97:160,97:160) = box; % Show Image figure(1); imshow(image); % compute fft and display its spectra
1

CM0268 MATLAB DSP GRAPHICS

301

F=fft2(double(image)); figure(2); imshow(abs(fftshift(F)));

Back Close

Ideal Low-Pass Filter Example 1 MATLAB Code (Cont.)


%compute Ideal Low Pass Filter u0 = 20; % set cut off frequency u=0:(M-1); v=0:(N-1); idx=find(u>M/2); u(idx)=u(idx)-M; idy=find(v>N/2); v(idy)=v(idy)-N; [V,U]=meshgrid(v,u); D=sqrt(U.2+V.2); H=double(D<=u0); % display figure(3); imshow(fftshift(H)); % Apply filter and do inverse FFT G=H.*F; g=real(ifft2(double(G))); % Show Result figure(4); imshow(g);
CM0268 MATLAB DSP GRAPHICS

302

Back Close

Ideal Low-Pass Filter Example 2

CM0268 MATLAB DSP GRAPHICS

303

(a) Input Image

(b) Image Spectra

(c) Ideal Low-Pass Filter

(d) Filtered Image


Back Close

Ideal Low-Pass Filter Example 2 MATLAB Code


lowpass2.m:
% read in MATLAB demo text image image = imread(text.png); [M N] = size(image)
CM0268 MATLAB DSP GRAPHICS

304

% Show Image figure(1); imshow(image); % compute fft and display its spectra F=fft2(double(image)); figure(2); imshow(abs(fftshift(F))/256);

Back Close

Ideal Low-Pass Filter Example 2 MATLAB Code (Cont.)


%compute Ideal Low Pass Filter u0 = 50; % set cut off frequency u=0:(M-1); v=0:(N-1); idx=find(u>M/2); u(idx)=u(idx)-M; idy=find(v>N/2); v(idy)=v(idy)-N; [V,U]=meshgrid(v,u); D=sqrt(U.2+V.2); H=double(D<=u0); % display figure(3); imshow(fftshift(H)); % Apply filter and do inverse FFT G=H.*F; g=real(ifft2(double(G))); % Show Result figure(4); imshow(g);
CM0268 MATLAB DSP GRAPHICS

305

Back Close

Low-Pass Butterworth Filter


Another lter sometimes used is the Butterworth low pass lter. In the 2D case, H (u, v ) takes the form
CM0268 MATLAB DSP GRAPHICS

306

H (u, v ) =

1 , 2 n ] 1 + [(u2 + v 2)/w0
1

where n is called the order of the lter.

Back Close

Low-Pass Butterworth Filter (Cont.)


This keeps some of the high frequency information, as illustrated by the second order one dimensional Butterworth lter:
.0 H(u)

CM0268 MATLAB DSP GRAPHICS

307

.0

u0

Consequently reduces the blurring.


Back Close

Low-Pass Butterworth Filter (Cont.)


The 2D second order Butterworth lter looks like this:
CM0268 MATLAB DSP GRAPHICS

308

w0

Back Close

Butterworth Low Pass Filter Example 1

CM0268 MATLAB DSP GRAPHICS

309

(a) Input Image

(b) Image Spectra

(c) Butterworth Low-Pass Filter (d) Filtered Image


Back Close

Butterworth Low-Pass Filter Example 1 (Cont.)


Comparison of Ideal and Butterworth Low Pass Filter:
CM0268 MATLAB DSP GRAPHICS

310

Ideal Low-Pass

Butterworth Low Pass


Back Close

Butterworth Low-Pass Filter Example 1 MATLAB Code


butterworth.m:
% Load Image and Compute FFT as in Ideal Low Pass Filter % Example 1 ....... % Compute Butterworth Low Pass Filter u0 = 20; % set cut off frequency u=0:(M-1); v=0:(N-1); idx=find(u>M/2); u(idx)=u(idx)-M; idy=find(v>N/2); v(idy)=v(idy)-N; [V,U]=meshgrid(v,u);
1

CM0268 MATLAB DSP GRAPHICS

311

for i = 1: M for j = 1:N %Apply a 2nd order Butterworth UVw = double((U(i,j)*U(i,j) + V(i,j)*V(i,j))/(u0*u0)); H(i,j) = 1/(1 + UVw*UVw); end end % Display Filter and Filtered Image as before

Back Close

Butterworth Low-Pass Butterworth Filter Example 2

CM0268 MATLAB DSP GRAPHICS

312

(a) Input Image

(b) Image Spectra

(c) Butterworth Low-Pass Filter

(d) Filtered Image


Back Close

Butterworth Low-Pass Filter Example 2 (Cont.)


Comparison of Ideal and Butterworth Low-Pass Filter:
CM0268 MATLAB DSP GRAPHICS

313

Ideal Low Pass

Butterworth Low Pass


Back Close

Butterworth Low Pass Filter Example 2 MATLAB Code


butterworth2.m:
% Load Image and Compute FFT as in Ideal Low Pass Filter % Example 2 ....... % Compute Butterworth Low Pass Filter u0 = 50; % set cut off frequency u=0:(M-1); v=0:(N-1); idx=find(u>M/2); u(idx)=u(idx)-M; idy=find(v>N/2); v(idy)=v(idy)-N; [V,U]=meshgrid(v,u);
1

CM0268 MATLAB DSP GRAPHICS

314

for i = 1: M for j = 1:N %Apply a 2nd order Butterworth UVw = double((U(i,j)*U(i,j) + V(i,j)*V(i,j))/(u0*u0)); H(i,j) = 1/(1 + UVw*UVw); end end % Display Filter and Filtered Image as before

Back Close

Low Pass Filtering Noisy Images


Use Matlab function, imnoise() to add noise to image (lowpass.m, lowpass2.m):
Image with Noise Added Low Pass Filtered Noisy Image

CM0268 MATLAB DSP GRAPHICS

315

(a) Input Noisy Image Image with Noise Added

(b) Deconvolved Noisy Image (Low Cut Off) High Cut off Frequency Low Pass Filtered Image
1

(c) Input Noisy Image

(d) Deconvolved Noisy Image (Higher Cut Off)

Back Close

Other Filters
High-Pass Filters opposite of low-pass, select high frequencies, attenuate those below u0 Band-pass allow frequencies in a range u0 . . . u1 attenuate those outside this range Band-reject opposite of band-pass, attenuate frequencies within u0 . . . u1 select those outside this range Notch attenuate frequencies in a narrow bandwidth around cut-off frequency, u0 Resonator amplify frequencies in a narrow bandwidth around cut-off frequency, u0 Other lters exist that are a combination of the above
Back Close
1

CM0268 MATLAB DSP GRAPHICS

316

Convolution
Several important audio and optical effects can be described in terms of convolutions.
CM0268 MATLAB DSP GRAPHICS

In fact the above Fourier ltering is applying convolutions of low


pass lter where the equations are Fourier Transforms of real space equivalents.

317

Deblurring high pass ltering Reverb more soon.


1

Back Close

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 dened by the integral

CM0268 MATLAB DSP GRAPHICS

318

f (x ) g (x ) =

f ()g (x ) d.

Back Close

1D Convolution Example
For example, let us take two top hat functions of the type described earlier. Let f () be the top hat function shown:
CM0268 MATLAB DSP GRAPHICS

319

f ( ) =

1 if || 1 0 otherwise,

and let g () be as shown in next slide, dened by

g ( ) =

1/2 if 0 1 0 otherwise.

Back Close

1D Convolution Example (Cont.)


1.0 1.0
CM0268 MATLAB DSP GRAPHICS

320

-5.0

0.0

5.0

-5.0

0.0

5.0

f ( ) =

1 if || 1 0 otherwise,

g ( ) =

1/2 if 0 1 0 otherwise.
Back Close

1D Convolution Example (Cont.)

g () is the reection of
this function in the vertical axis,

1.0

CM0268 MATLAB DSP GRAPHICS

321

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.
1

An example is shown for x in the range 1 x 0


opposite
-5.0 x 0.0 5.0
Back Close

1D Convolution Example (cont.)


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 0 the area of overlap steadily increases from 0 to 1/2; As x increases from 0 to 1, the overlap area remains at 1/2; Finally as x increases from 1 to 2, the overlap area steadily decreases again from 1/2 to 0. Thus the convolution of f (x) and g (x), f (x) g (x), in this case
has the form shown on next slide

CM0268 MATLAB DSP GRAPHICS

322

Back Close

1D Convolution Example (cont.)


1.0
CM0268 MATLAB DSP GRAPHICS

323

-5.0

0.0

5.0

Result of f (x) g (x)


Back Close

1D Convolution Example (cont.)


Mathematically the convolution is expressed by:
CM0268 MATLAB DSP GRAPHICS

(x + 1)/2 if 1 x 0 1/2 if 0 x 1 f ( x) g ( x) = 1 x/2 if 1 x 2 0 otherwise.


1.0

324

-5.0

0.0

5.0

Back Close

Fourier Transforms and Convolutions


MATLAB One major reason that Fourier transforms are so important in signal/image DSP GRAPHICS processing is the convolution theorem which states that: CM0268

325

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).

Recall our Low Pass Filter Example (MATLAB CODE)


% Apply filter G=H.*F; Where F was the Fourier transform of the image, H the lter

Back Close

Computing Convolutions with the Fourier Transform


E.g.:

CM0268 MATLAB DSP GRAPHICS

To apply some reverb to an audio signal, example later To compensate for a less than ideal image capture system:
To do this fast convolution we simply:

326

Take the Fourier transform of the audio/imperfect image, Take the Fourier transform of the function describing the effect of
the system,
1

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 audio/ideal image.


This process is sometimes referred to as deconvolution.
Back Close

Image Deblurring Deconvolution Example


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:

CM0268 MATLAB DSP GRAPHICS

Our computed butterworth low pass lter, 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 lter
Ghigh = G./H; ghigh=real(ifft2(double(Ghigh))); figure(5) imshow(ghigh)

327

in this ideal example we clearly get F back and to get the image
simply to inverse Fourier Transfer.

In the real world we dont really know the exact blurring function H so things are not so easy.

Back Close

deconv.m results

CM0268 MATLAB DSP GRAPHICS

328

(a) Input Image

(b) Blurred Low-Pass Filtered Image (c) Deconvolved Image

Back Close

deconv2.m results

CM0268 MATLAB DSP GRAPHICS

329

(a) Input Image

(b) Blurred Low-Pass Filtered Image (c) Deconvolved Image

Back Close

Deconvolution is not always that simple!


Origial Image Deconvolved

CM0268 MATLAB DSP GRAPHICS

330

(a) Input Image


Image with Noise Added

(b) Deconvolved Image


Deconvolved Noisy Image

(c) Input Noisy Image

(d) Deconvolved Noisy Image

Back Close

High Pass Filtering


A High Pass Filter is usually dened as 1 - low pass = 1 H :
Original image High Pass Filtered

CM0268 MATLAB DSP GRAPHICS

331

(a) Input Image


Image with Noise Added

(b) High Pass Filtered Image


High Pass Filter Noisy Image

(c) Input Noisy Image

(d) High Pass Filtered Noisy Image


Back Close

You might also like