%IDEAL_RESPONSE_ZP Design an ideal zero phase filter in the frequency % domain using the specifications given in the text file "filename". % % filename: the full path to the text file containing the specifications % for the frequency response of the ideal filter. The first two columns % of the text file contains the horizontal and the vertical frequency % components of the points located on pass band(S) and stop band(S) of % frequency response and the third column contains their respected % values. NOTE: since this is a zero phase filter, the user only needs to % provide the specifications for one half-plane of the frequency response % of the ideal filter. % % Npt: the number of points to be used in the frequency response (64 is % recommended). % Hd: the frequency response of the output filter. % % A general suggestion when designing the ideal filter is to truncate the % sharp corners located on the bands of the frequency response of the % filter. This would allow for a better solution when using % filter_design_zp_unc or filter_design_zp_con to design a filter based % on this ideal filter. The following example makes use of this % suggestion. % % Example % ------- % Design a simple zero phase low pass filter located 45 degreess % diagonally in the frequency domain. % The filter specifications are given in the following textfile: % Content of "zerophase.txt" % 0 0 1 % 0.1 0 1 % 0.2 0.1 1 % 0.3 0.2 1 % 0.3 0.25 1 % 0.275 0.275 1 % 0.25 0.3 1 % 0.2 0.3 1 % 0.1 0.2 1 % 0 0.1 1 % -0.1 0 1 % 0.2 0 0 % 0.3 0.1 0 % 0.4 0.2 0 % 0.4 0.3 0 % 0.35 0.35 0 % 0.3 0.4 0 % 0.2 0.4 0 % 0.1 0.3 0 % 0 0.2 0 % -0.1 0.1 0 % -0.2 0 0 % 0.5 0 0 % 0 0.5 0 % 0.5 0.5 0 % -0.5 0 0 % -0.5 0.5 0 % ------------------------------------------- % Hd_zp=ideal_response_zp('zerophase.txt',64); % function Hd = ideal_response(filename,Npt) %filename contains the (full path if not in the same work folder) %filename of the text file. %Npt = number of points in ideal response in each dimension. a = textread(filename); X = [a(:,1)' -a(:,1)']*2; Y = [a(:,2)' -a(:,2)']*2; Z = [a(:,3)' a(:,3)']; [f1,f2] = freqspace(Npt); Hd = griddata(X,Y,Z,f1,f2'); [F1,F2] = meshgrid(f1,f2);