02.10.2019 Views

UploadFile_6417

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

FIR Filter Designs for Sampling Rate Conversion 515<br />

% Filter Design<br />

[delta1,delta2] = db2delta(Rp,As);<br />

[N,F,A,weights] = firpmord([wp,ws]/pi,[1,0],[delta1,delta2],2); N = ceil(N/2)*2;<br />

h = firpm(N,F,A,weights); delay = N/2; % Delay imparted by the filter<br />

Hf1 = figure(’units’,’inches’,’position’,[1,1,6,4],...<br />

’paperunits’,’inches’,’paperposition’,[0,0,6,4]);<br />

% Input signal x(n) = cos(2*pi*n/16)<br />

n = [0:256]; x = cos(pi*n/8);<br />

n1 = n(1:33); x1 = x(33:65); % for plotting purposes<br />

subplot(2,2,1); Hs1 = stem(n1,x1,’filled’); set(Hs1,’markersize’,2,’color’,’g’);<br />

set(gca,’xtick’,[0:8:32],’ytick’,[-1,0,1]);<br />

axis([-2,34,-1.2,1.2]); ylabel(’Amplitude’,’vertical’,’cap’);<br />

xlabel(’n’,’vertical’,’middle’);<br />

Title(’Input Signal: x(n) = cos(\pin/8)’,’fontsize’,TF,’vertical’,’baseline’);<br />

% Decimation of x(n): D = 2<br />

y = upfirdn(x,h,1,D);<br />

m = delay+1:1:128/D+delay+1; y1 = y(m); m = 0:16; y1 = y1(14:30);<br />

subplot(2,2,3); Hs2 = stem(m,y1,’filled’); set(Hs2,’markersize’,2,’color’,’m’);<br />

axis([-1,17,-1.2,1.2]); set(gca,’xtick’,[0:8:32]/D,’ytick’,[-1,0,1]);<br />

title(’Output signal y(n): D=2’,’fontsize’,TF,’vertical’,’baseline’);<br />

xlabel(’m’,’vertical’,’middle’); ylabel(’Amplitude’,’vertical’,’cap’);<br />

% Filter Design Plots<br />

[Hr,w,a,L] = Hr_Type1(h); Hr_min = min(Hr); w_min = find(Hr == Hr_min);<br />

H = abs(freqz(h,1,w)); Hdb = 20*log10(H/max(H)); min_attn = Hdb(w_min);<br />

subplot(2,2,2); plot(w/pi,Hr,’m’,’linewidth’,1.0); axis([0,1,-0.1,1.1]);<br />

set(gca,’xtick’,[0,wp/pi,ws/pi,1],’ytick’,[0,1]); grid;<br />

ylabel(’Amplitude’,’vertical’,’cap’);<br />

title(’Amplitude Response’,’fontsize’,TF,’vertical’,’baseline’);<br />

xlabel(’Frequency in \pi units’,’vertical’,’middle’);<br />

subplot(2,2,4); plot(w/pi,Hdb,’m’,’linewidth’,1.0); axis([0,1,-60,10]);<br />

set(gca,’xtick’,[0,wp/pi,ws/pi,1],’ytick’,[-60,round(min_attn),0]); grid<br />

ylabel(’Decibels’,’vertical’,’cap’);<br />

xlabel(’Frequency in \pi units’,’vertical’,’middle’);<br />

title(’Log-magnitude Response’,’fontsize’,TF,’vertical’,’baseline’);<br />

The signal stem plots and the filter responses are shown in Figure 9.27. The<br />

designed filter achieves an attenuation of 51 dB, and the decimated signal is<br />

correct.<br />

□<br />

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).<br />

Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!