www.gusucode.com > signal 案例源码程序 matlab代码 > signal/ArbitraryMagnitudeFilterExample.m
%% Arbitrary Magnitude Filter % Design an FIR filter with the following frequency response: % Copyright 2015 The MathWorks, Inc. %% % * A sinusoid between 0 and $0.18\pi$ rad/sample. F1 = 0:0.01:0.18; A1 = 0.5+sin(2*pi*7.5*F1)/4; %% % * A piecewise linear section between $0.2\pi$ rad/sample and $0.78\pi$ % rad/sample. F2 = [0.2 0.38 0.4 0.55 0.562 0.585 0.6 0.78]; A2 = [0.5 2.3 1 1 -0.2 -0.2 1 1]; %% % * A quadratic section between $0.79\pi$ rad/sample and the Nyquist % frequency. F3 = 0.79:0.01:1; A3 = 0.2+18*(1-F3).^2; %% % Design the filter using a Hamming window. Specify a filter order of 50. N = 50; FreqVect = [F1 F2 F3]; AmplVect = [A1 A2 A3]; ham = fir2(N,FreqVect,AmplVect); %% % Repeat the calculation using a Kaiser window that has a shape parameter % of 3. kai = fir2(N,FreqVect,AmplVect,kaiser(N+1,3)); %% % Redesign the filter using the |designfilt| function. |designfilt| uses a % rectangular window by default. Compute the zero-phase response of the % filter over 1024 points. d = designfilt('arbmagfir','FilterOrder',N, ... 'Frequencies',FreqVect,'Amplitudes',AmplVect); [zd,wd] = zerophase(d,1024); %% % Display the zero-phase responses of the three filters. Overlay the ideal % response. zerophase(ham,1) hold on zerophase(kai,1) plot(wd/pi,zd) plot(FreqVect,AmplVect,'k:') legend('Hamming','Kaiser','designfilt','ideal')