function dsp_filter(N,F,A,file_name) % DSP_FILTER creates a length N+1 linear phase (real, symmetric % coefficients) FIR filter. F is a vector of frequency band % edges in pairs, in ascending order between 0 and 1. A is a % real vector the same size as F which specifies the desired % amplitude of the frequency response of the resultant filter. % % Arguments of DSP_FILTER are passed to the Remez exchange % algorithm and the resulting coefficients are output to a % file. % % (Jesse & Sambit 10-1-00) % run the Remez exchange algorithm B = remez(N,F,A); [H,w] = freqz(B,1,256); % plot the coefficients figure(1) stem(0:N,B) % mag and phase plots figure(2) subplot(2,1,1) plot(w/pi,20*log10(abs(H))) title('Magnitude response') xlabel('\omega/\pi') ylabel('Magnitude in dB') subplot(2,1,2) plot(w/pi,abs(H)) xlabel('\omega/\pi') ylabel('Linear Magnitude') %plot(w/pi,unwrap(angle(H))) %title('Phase response') %xlabel('\omega/\pi') %ylabel('Phase') % open a file to output results file_name = strcat(file_name,'.h'); fid = fopen(file_name,'w'); for i = 1:N+1 % output coef with 12 decimal places % and add spacing to make file readable fprintf(fid,'%13.12f',B(i)); if i ~= N+1 fprintf(fid,','); end end % done writing to file fclose(fid);