Frequency Space
Frequency Space
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
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
263
Back Close
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
265
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
268
Back Close
269
Back Close
270
Back Close
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
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
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
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
275
f ( x) =
F (u)e2ixu du,
which is rather similar, except that theexponential term has the opposite sign. not negative
1
Back Close
276
1
Back Close
F (u) =
1
f (x)e2ixu dx 1e
1 2ixu
dx
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
278
Back Close
279
F (u, v ) =
f (x, y ) =
Back Close
280
Back Close
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
282
N 1 M 1
Back Close
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
284
Back Close
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
286
Back Close
287
Back Close
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
12
14
16
1
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
290
Back Close
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
Back Close
293
Back Close
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
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
296
u0
Back Close
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
H (u, v ) =
1 if u2 + v 2 w0 0 otherwise,
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
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
300
301
Back Close
302
Back Close
303
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
305
Back Close
306
H (u, v ) =
1 , 2 n ] 1 + [(u2 + v 2)/w0
1
Back Close
307
.0
u0
308
w0
Back Close
309
310
Ideal Low-Pass
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
312
313
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
315
(b) Deconvolved Noisy Image (Low Cut Off) High Cut off Frequency Low Pass Filtered Image
1
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
316
Convolution
Several important audio and optical effects can be described in terms of convolutions.
CM0268 MATLAB DSP GRAPHICS
317
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
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,
g ( ) =
1/2 if 0 1 0 otherwise.
Back Close
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
g () is the reection of
this function in the vertical axis,
1.0
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
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
322
Back Close
323
-5.0
0.0
5.0
324
-5.0
0.0
5.0
Back Close
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).
Back Close
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.
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
328
Back Close
deconv2.m results
329
Back Close
330
Back Close
331