SLIDE 5 Example 1: MATLAB Code
%================================================ % Plot the Pole Zero Plot of the System %================================================ figure; h = Circle; hold on; h = plot(real(roots(b)),imag(roots(b)),’bo’); set(h,’LineWidth’,1.2); xlim([-1.2 1.2]); ylim([-1.2 1.2]); axis(’square’); title(’AZ System’); box off; %================================================ % Plot the Pole Zero Plot of the Estimator %================================================ figure; h = Circle; hold on; h = plot(real(roots(co)),imag(roots(co)),’go’); set(h,’LineWidth’,1.2); xlim([-1.2 1.2]); ylim([-1.2 1.2]); axis(’square’); title(’Estimator’); box off;
Portland State University ECE 539/639 Optimum FIR Filters
19
Example 1: MATLAB Code
N = 10000; % Number of samples M = 25; % Size of filter b = poly([0.99 0.98*j -0.98*j 0.98*exp(j*0.8*pi) 0.98*exp(-j*0.8*pi)]); % Locations of zeros nz = length(b)-1; % Number of zeros Mmax = 100; % Maximum value to consider %================================================ % Calculate the Auto- and Cross-Correlation %================================================ rx = conv(b,fliplr(b)); % Quick calculation of rx k = -nz:nz; rx = rx(nz+1:end); % Trim off negative lags ryx = rx(2:end); % Cross-correlation one-step ahead %================================================ % Build R and d and Solve for co %================================================ R = zeros(Mmax,Mmax); for c1=1:Mmax, i1 = 1:nz+1; i2 = c1+(0:nz); i1 = i1(find(i2<=Mmax)); i2 = i2(find(i2<=Mmax)); R(c1,i2) = rx(i1); R(i2,c1) = rx(i1).’; end; d = zeros(Mmax,1); for c1=1:nz, d(c1) = rx(c1+1); end;
Portland State University ECE 539/639 Optimum FIR Filters
17
Example 1: MATLAB Code
%================================================ % Plot the Frequency Response %================================================ figure; subplot(2,1,1); [H,w] = freqz(b,1,2^10); h = plot(w/pi,abs(H),’b’); set(h,’LineWidth’,1.2); set(get(gca,’YLabel’),’Interpreter’,’LaTeX’) xlabel(’Frequency (normalized)’); ylabel(’$|H(e^{j\omega})|$’); xlim([0 1]); ylim([0 1.05*max(abs(H))]); subplot(2,1,2); [H,w] = freqz(co,1,2^10); h = plot(w/pi,abs(H),’g’); set(h,’LineWidth’,1.2); set(get(gca,’YLabel’),’Interpreter’,’LaTeX’) xlabel(’Frequency (normalized)’); ylabel(’$|H(e^{j\omega})|$’); xlim([0 1]); ylim([0 1.05*max(abs(H))]); box off;
Portland State University ECE 539/639 Optimum FIR Filters
20
Example 1: MATLAB Code
Po = zeros(Mmax,1); for c1=Mmax:-1:1, Rt = R(1:c1,1:c1); dt = d(1:c1); co = inv(Rt)*dt; Po(c1) = rx(1) - dt’*co; end; %================================================ % Plot the Pole Zero Plot of the System %================================================ figure; h = stem(1:Mmax,Po,’r.’); set(h,’MarkerFaceColor’,’r’); xlabel(’Filter Order’); ylabel(’MMSE’); xlim([0 Mmax+0.5]); box off; %================================================ % Calculate Optimal filter and MMSE %================================================ R = R(1:M,1:M); d = d(1:M); co = inv(R)*d; Po = rx(1) - d’*co; %================================================ % Generate Example %================================================ w = randn(N,1); x = filter(b,1,w); xhp = filter(co,1,x);
Portland State University ECE 539/639 Optimum FIR Filters
18