Main Content

fwind2

2-D FIR filter using 2-D window method

Description

The fwind2 function designs 2-D FIR filters using the window method. fwind2 uses a 2-D window specification to design a 2-D FIR filter based on the desired frequency response. fwind2 works with 2-D windows only. Use fwind1 to create a 2-D FIR filter from a 1-D window.

You can apply the 2-D FIR filter to images by using the filter2 function.

h = fwind2(Hd,win) creates a 2-D FIR filter h by using an inverse Fourier transform of the desired frequency response Hd and multiplication by the window win.

example

h = fwind2(f1,f2,Hd,win) lets you specify the desired frequency response Hd at arbitrary frequencies f1 and f2 along the x- and y-axes.

Examples

collapse all

This example shows how to design an approximately circularly symmetric two-dimensional bandpass filter using a 2-D window method.

Create the frequency range vectors f1 and f2 using freqspace. These vectors have length 21.

[f1,f2] = freqspace(21,'meshgrid');

Compute the distance of each position from the center frequency.

r = sqrt(f1.^2 + f2.^2);

Create a matrix Hd that contains the desired bandpass response. In this example, the desired passband is between 0.1 and 0.5 (normalized frequency, where 1.0 corresponds to half the sampling frequency, or π radians).

Hd = ones(21); 
Hd((r<0.1)|(r>0.5)) = 0;

Display the ideal bandpass response.

colormap(parula(64))
mesh(f1,f2,Hd)

Figure contains an axes object. The axes object contains an object of type surface.

Create a 2-D Gaussian window using fspecial. Normalize the window.

win = fspecial('gaussian',21,2);
win = win ./ max(win(:));

Display the window.

mesh(win)

Figure contains an axes object. The axes object contains an object of type surface.

Using the 2-D window, design the filter that best produces the desired frequency response

h = fwind2(Hd,win);

Display the actual frequency response of this filter.

freqz2(h)

Figure contains an axes object. The axes object with xlabel F indexOf x baseline F_x, ylabel F indexOf y baseline F_y contains an object of type surface.

Input Arguments

collapse all

Desired frequency response at equally spaced points in the Cartesian plane, specified as a numeric matrix. For accurate results, create Hd by using the freqspace function.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

2-D window, specified as a numeric matrix.

Data Types: single | double

Desired frequency along the x-axis. The frequency vector should be in the range [-1, 1], where 1.0 corresponds to half the sampling frequency, or π radians.

Data Types: single | double

Desired frequency along the y-axis. The frequency vector should be in the range [-1, 1], where 1.0 corresponds to half the sampling frequency, or π radians.

Data Types: single | double

Output Arguments

collapse all

2-D FIR filter, returned as a numeric matrix of the same size as win.

Data Types: double

Algorithms

fwind2 computes h using an inverse Fourier transform and multiplication by the two-dimensional window win.

hd(n1,n2)=1(2π)2ππππHd(ω1,ω2)ejω1n1ejω2n2dω1dω2

h(n1,n2)=hd(n1,n2)w(n1,n2)

References

[1] Lim, Jae S., Two-Dimensional Signal and Image Processing, Englewood Cliffs, NJ, Prentice Hall, 1990, pp. 202-213.

Version History

Introduced before R2006a