Matlab HW Example
Matlab HW Example
Matlab HW Example
Assignment № 1
For this assignment discrete Fourier transform of several functions is computed using fft algorithm
in MATLAB. Furthermore, the functions are reconstructed using inverse discrete Fourier transform
algorithm (ifft).
As given in Listing 1, the frequencies of the periodic sinusoidal and square waves are defined as
100 s−1 and sampling frequencies are defined as 2000 s−1 . Figure 1 shows the defined signals.
Assignment № 1 Page 1
2019801003
Zero padding means padding zeros to the end of the signal in one domain to increase the
length of the signal. Zero padding is preferable for some reasons. One is to increase the size
of the signal to increase the resolution in the frequency domain and the other is to increase the
computation speed as fft algorithm works fast when the length of the signal is power of two.
(a)
(b)
Figure 2: (a) FFT with zero padding, (b) FFT without zero padding.
Figure 2 shows the difference between the fft results of zero padded signals and original signals.
As can be seen, the resolution is higher for the zero padded case.
Assignment № 1 Page 2
2019801003
The sinusoidal and square waves are recomposed by inverse fast fourier transform of the zero
padded signals in the frequency domain. Inverse fft computations for sinusoidal and square waves
are given below:
Furthermore, recomposed signals are given in Figure 3. Additional zeros at the end of the signals
can be seen for these waves which are recomposed from the frequency domain.
FFT is an important image processing tool for processing digital images. For this assignment FFT
is used for basic image processing applications.
First, fft2 algorithm is used to transform the image in spatial domain to the frequency domain.
Assignment № 1 Page 3
2019801003
MATLAB computation for Fourier transform of the digital image is given in Listing 4. Furthermore,
fft2 result for an example image is given in Figure 4.
(a)
(b)
For Assignment №1, frequency separation of the example image is applied using the Fourier
Transform to separate the texture data from the color and luminance data of an image. MATLAB
computations for the filters can be seen in Listing 5. Here, Butterworth low pass filter is used to
obtain for low frequency information (color and luminance data).
Assignment № 1 Page 4
2019801003
As can be seen in Listing 5 Cut of frequencies of the filters are determined as 50 and the orders
of the filters are chosen as 5. The obtained filters in the frequency domain can be seen in Figure
5.
(a) (b)
Low pass filter and high pass filter are applied to an image by multiplication in the frequency
domain. The low pass filtered and high pass filtered image are reconstructed by inverse discrete
fourier transform in MATLAB. MATLAB computations for ifft2 can be seen in Listing 6.
Furthermore, the original signal is recomposed by inverse discrete fourier transform of the sum-
mation of low pass filtered and high pass filtered images in the frequency domain. Recomposed
low pass filtered image which carries color and luminescence information, high pass filtered image
which carries texture information and summation of the images can be seen in Figure 6.
Assignment № 1 Page 5
2019801003
(a)
(b)
(c)
Figure 6: (a) LP filtered image, (b) HP filtered image, (c) The image reconstructed by inverse
transformation of summation of filtered images in the frequency domain.
Assignment № 1 Page 6
2019801003
For this assignment, basic filter is applied to an image in the frequency domain to change the
sharpness of the figure. In this manner, high frequency component of the example image is
scaled up for sharpening and scaled down for blurring effect. Then, manipulated high frequency
component is added to a low frequency component and image is recomposed by inverse discrete
fourier transform.
Listing 7: Sample Bash code.
1 Blurfilter = Hi.*0.5 ;
2 Sharpfilter = Hi.*2 ;
3 %%Blurring
4 Softer_image = M*N*ifft2(ifftshift(A1.*(Lo + Blurfilter)) ;
5 %%Sharpening
6 Sharper_image = M*N*ifft2(ifftshift(A1.*(Lo + Sharpfilter)) ;
MATLAB computations for the explained filter application is given in Listing 7. Furthermore, ob-
tained blurred and sharpened images are given in Figure 7.
(a)
(b)
Assignment № 1 Page 7