www.gusucode.com > images 案例代码 matlab源码程序 > images/CreateFilterBasedOnDesiredFrequencyResponseExample.m

    %% Create Filter Using Frequency Sampling Method
% This example shows how to use the frequency sampling method to create a
% filter based on a desired frequency response. Given a matrix of points
% that define the shape of the frequency response, the frequency sampling
% method creates a filter whose frequency response passes through those
% points. Frequency sampling places no constraints on the behavior of the
% frequency response between the given points. Usually, the response
% ripples in these areas. (Ripples are oscillations around a constant
% value. The frequency response of a practical filter often has ripples
% where the frequency response of an ideal filter is flat.)
%%
% Calculate the two-dimensional frequency response of a filter. The example
% creates an 11-by-11 filter using the |fsamp2| function and plots the
% frequency response of the resulting filter. |fsamp2| returns the filter
% |h| with a frequency response that passes through the
% points in the input matrix |Hd| .

% Copyright 2015 The MathWorks, Inc.

Hd = zeros(11,11); 
Hd(4:8,4:8) = 1;
[f1,f2] = freqspace(11,'meshgrid');
mesh(f1,f2,Hd)
axis([-1 1 -1 1 0 1.2])
colormap(jet(64))
h = fsamp2(Hd);
figure
freqz2(h,[32 32])
axis([-1 1 -1 1 0 1.2])