






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Solutions to Take-Home Exam #
Solution: To suppress a particular frequency, we would want to use a bandstop filter. For this problem, we desire circular symmetry (or in the absence of that, 8-fold symmetry). The sampling spacing is T = 1/64 cm and the RF corruption is has a period of 0.05 cm or a frequency of 20 cm-1. The peak unaliased frequency is 1/2 T = 32 cm- (corresponding to +/- π ). The stopband should be at ω = (20/32) π =1.96 (+/- 2%). Naturally, the transition bands surrounding this stopband will depend on the size of the filter.
b. Design a 7x7 filter function to suppress this corruption (there is more than one correct answer here, but please justify your chosen method). Use imagesc to show the frequency response. Include a colorbar and please make sure your axes are labeled and correct.
Solution: The ideal filter will have response near zero in the region of the stopband and near one at other frequencies. Since a 7x7 support region is rather small, we will have to choose a filter with very large transitions. There are many possible solutions here, but I will give just one (however, many students designed better performing filters than this one). In HW#4, problem 3 we designed a nice 7x7 bandpass filter and we know that bandstop filters can be derived from bandpass filters. We have to do three things differently than we did for the homework: 1) we need to choose a different passband frequency, 2) we need to adjust the amplitude so that it peaks at 1 (rather than 0.5), and 3) we then subtract the filter from from 1 in the Fourier domain or from δ ( n , m ) to produce the bandstop filter. Thus we have
32
20 2
1 2
1 32
20 2
1 2 ( )= 1 − ( )= 1 −^1 − cos 2 = + cos 2 H (^) bs Hbp. See plots below. Important : About using H (^) bs ( ω )= 1 − Hbp ( ω )or h (^) bs ( n , m )= δ ( n , m )− hbp ( n , m ). This relationship works only if H (^) bp ( ω )is nearly 1 in the passband. If you design a filter with too narrow of a passband, then it may need to be scaled so that the frequency response is close to 1 prior to applying the above relationships. E.g., you may need to do: H (^) bs ( ω )= 1 − αHbp ( ω ), where α is chosen to make the bandpass filter peak near 1. This is also true for design of high-pass from low-pass filters, etc.
c. Apply this filter using conv2 and create an image showing the result. Make sure you label the axes (in cm) and make sure that the filter had zero phase.
See plots below.
d. Create a separable 2D filter in which the 1D component has length 9. Display the frequency response.
Solution: For the 1D filter, we used the same approach we did for the 2D filter, but
32
20 2
1 2 ( )= 1 + cos 2. The find the 2D response, we made a separable 2D filter. See plots below.
e. Apply this filter by applying the 1D convolution in two directions and create an image showing the result.
See plots below.
f. Create a 2D frequency domain filter (no restrictions on size) and display this function.
Solution: For this part we designed an ideal stop band filter in the Fourier domain. We needed to carefully scale our axes in order to make this work properly. Finally, we expanded our stopband since there was some bleeding of the artifact signal outside the +/- 2% tolerances. See plots below.
g. Apply the filter (in frequency domain) and create an image showing the result.
See plots below.
h. Comment on which methods are best and why. Comment on computational issues in addition to performance issues.
Solution: For this particular problem and my solutions, there appears to be little benefit to using the 2D filter over the 1D filter – this stems from the rather wide transition regions of the filter that I chose – for other filters, the 2D filter might be better. The computational advantages of the 1D separable filters would make these most desirable. The Fourier filter had the best suppression of the corruption, but was computationally the most expensive. It also had edge effects due to circular convolution. This is especially so given that the image size (480x720) did not lend itself to very fast FFT’s.
Matlab code: % Exam 1, Problem 1 load exam_image [s1 s2] = size(exam_image); y = [0:s1-1]./64; x = [0:s2-1]./64; [nn,mm] = ndgrid([-32:31]);
∞
=−∞
∞
=−∞
∞
=−∞
∞
=−∞
n m n m
p ( x , y ) δ ( x 2 nT , y 2 mT ) δ ( x 2 nT T , y 2 mT T )
a. Describe the spectrum of object sampled by the original array, given some object spectrum X ( u , v )(or X ( ω (^) x , ωy ), if you prefer). What are the conditions for prevention of aliasing?
Solution: The original sampling function was:
∞
=−∞
∞
= −∞ T
y T
x comb T
p x y x nT y mT n m
( , ) δ ( , ) 2. The sampled spectrum is:
∞
=−∞
∞
=−∞
∞
=−∞
∞
=−∞
n m
n m
n v T
n X u T
n v T
n u T
F x x y p x y X uv combTuTv X uv
2
2 δ .
This is a replication of X ( u , v )in the u and v directions with spacing 1/ T.
The conditions to prevent aliasing are that the original spectrum, X ( u , v ), must be
bandlimited to the region T
u 2
< and T
v 2
< , corresponding to the square in the above
figure.
= − =−
1
1
1
1
k l
ynm xk nl m
Solution: This function is linear , but the response is reflected about the origin and is thus space variant. The impulse response is:
= − =−
1
1
1
1
k l
h nmn m Sδ n n m m δ k n n l m m. Observe again,
that this is not a function of ( n − n ', m − m ')and is thus not space invariant. b. ( , ) max ( , ) , ( 1 , 0 , 1 )
y nm xn k m l kl
∈− Solution: This function chooses a local maximum. It is not linear (consider the case where we scale the input by a where a < 0). This system is, however, space invariant – clearly shifting the input by ( n ' , m ')will lead to a similarly shifted output. c. y ( n , m )= x ( n , m )+ x ( 2 n , m )+ x ( n , 2 m )+ x ( 2 n , 2 m ) Solution: This system is linear , but space variant. The impulse response is:
n n m m n n m m n n m m n n m m
hnmn m S n n m m = − − + − − + − − + − −
δ δ δ δ
δ .
Observe again, that this is not a function of ( n − n ', m − m ')and is thus not space invariant. d. y ( n , m )= x ( n , m )+ x ( n − 2 , m )+ x ( n , m − 2 )+ x ( n − 2 , m − 2 ) Solution: This function is both linear and space invariant. The impulse response is:
h ( n , m ) δ ( n , m ) δ ( n 2 , m ) δ ( n , m 2 ) δ ( n 2 , m 2 ).
e. y ( n , m )= x ( m , n ) Solution: This function is linear , but the response is transposed and is thus space variant. The impulse response is:
f. y ( n , m )= x^2 ( n , m ) Solution: This function is non-linear , but space invariant.
−
=
−
=
0
1
0
( ,) ( , )exp 2
M
m
N
n M
ml N
nk X kl xnm i π and
−
=
−
=
−
=
1
0
1
0
1
0
( ) ( )exp 2 ( )exp 2
M
m
N
n
NM
p NM
n mNq yn mN i NM
pq Y q y p i π π.
Substituting for X’ and x we get:
−
=
−
=
−
=
−
=
1
0
1
0
1
0
1
0
( , )exp 2
'( ,) ( , )exp 2
M
m
N
n
M
m
N
n
mk NM
nl M
ml N
nk xnm i
n mN kM l X kl xnm i
π
π
Observe that the mk term is always an integer and thus exp(- i 2 πmk ) = 1, so this term can be discarded. Also observe that nl term represents a linear phase term in n (and has no effect on the FT in m ). This results in a shift of the of the output image by an amount
'( ,) ( , )exp 2 exp 2
1
0
1
0 X k l M l
nk l M i M
ml X kl xnm i
M
m
N
n = +
−
=
−
=
π π
This appears as a shearing ( l dependent shift in k ) of the true Fourier data.
b. For a 32x32 image size and image data defined by x ( n , m )= sinc( n / 4 )sinc( m / 2 ), write a Matlab script to compare X '( k , l )and X ( k , l ). For both of these let the origin of the input and output system at the (17,17) location. Display the images and include real and imaginary parts if appropriate. Please attach the Matlab script and all images.
Solution: We create a Matlab function: function xp=new2dft(x) % function to perform 2D fft by a 1D fft [sx,sy]=size(x); y = x(:); Y=fft(y); xp = reshape(Y,sy,sx).';
And with fftshift:
In this case the fftshift moves the shift discontinuity to the center of the image. The most common mistake made in this part was implementation of the fftshift on the 1D data vs. the 2D data (the correct approach).
c. How close to being correct was the coffee shop assertion?
Solution: The 1D equivalent is quite similar to the 2D FFT. All shifts are less than 1 pixel in size. When using with fftshift, however, the discontinuity in the shift from N-1 to 0 is move to center of the image creating a discontinuity in the image. We could create an alternate fftshift that would produced the expected image with no discontinuity at the origin and then the only effects would be the skewing and the non- realness of the new method.