% Filter design for Lab C2 fs_2 = 8000/2; % half sampling rate % lowpass1 f1 = [0 1750 2500 4000]/fs_2; a1 = [1 1 0 0 ]; L1 = 33; h1 = remez(L1-1,f1,a1); clf; stem((0:L1-1),h1); xlabel('discrete time n','fontsize',14); ylabel('lowpass 1, h[n]','fontsize',14); print -depsc lowpass1.eps fid = fopen('lowpass1.txt','wt'); fprintf(fid,'#define FilterLength %d \n',L1); fprintf(fid,'float x[FilterLength]; \n'); fprintf(fid,'float h[FilterLength] = {'); for l = 1:L1-1, fprintf(fid,'%1.6f, ',h1(l)); end; fprintf(fid,'%1.6f};',h1(L1)); fclose(fid); % lowpass2 f2 = [0 500 750 4000]/fs_2; a2 = [1 1 0 0]; L2 = 99; h2 = remez(L2-1,f2,a2); clf; stem((0:L2-1),h2); xlabel('discrete time n','fontsize',14); ylabel('lowpass 2, h[n]','fontsize',14); print -depsc lowpass2.eps fid = fopen('lowpass2.txt','wt'); fprintf(fid,'#define FilterLength %d \n',L2); fprintf(fid,'float x[FilterLength]; \n'); fprintf(fid,'float h[FilterLength] = {'); for l = 1:L2-1, fprintf(fid,'%1.6f, ',h2(l)); end; fprintf(fid,'%1.6f};',h2(L2)); fclose(fid); % highpass1 f3 = [0 1500 2250 4000]/fs_2; a3 = [0 0 1 1]; L3 = 33; h3 = remez(L3-1,f3,a3); clf; stem((0:L3-1),h3); xlabel('discrete time n','fontsize',14); ylabel('highpass 1, h[n]','fontsize',14); print -depsc highpass1.eps fid = fopen('highpass1.txt','wt'); fprintf(fid,'#define FilterLength %d \n',L3); fprintf(fid,'float x[FilterLength]; \n'); fprintf(fid,'float h[FilterLength] = {'); for l = 1:L3-1, fprintf(fid,'%1.6f, ',h3(l)); end; fprintf(fid,'%1.6f};',h3(L3)); fclose(fid); % magnitude response H1 = 20*log10(abs(fft(h1,1024))); H2 = 20*log10(abs(fft(h2,1024))); H3 = 20*log10(abs(fft(h3,1024))); f = (0:511)/512*fs_2; clf; plot(f,H1(1:512)); hold on; plot(f,H2(1:512),'r--'); plot(f,H3(1:512),'k:'); legend('lowpass1','lowpass2','highpass1',4); xlabel('frequency / [Hz]'); ylabel('magnitude response / [dB]'); axis([0 4000 -80 5]); print -depsc FilterDesignMagResp.eps