%18-bit, 16-bit fraction, 2's comp conversion % for assembler version of filtering clear all clc %The scale has to be adjusted so that filter coefficients are % -1.0=0 fprintf('\tb%1d \t1 \t%s \n', i, dec2hex(fix(2^16*b(i)))) ; else fprintf('\tb%1d \t1 \t%s \n', i, dec2hex(bitcmp(fix(2^16*-b(i)),18)+1)); end end for i=2:length(a) if a(i)>=0 fprintf('\ta%1d \t1 \t%s \n', i, dec2hex(fix(2^16*a(i)))) else fprintf('\ta%1d \t1 \t%s \n', i,dec2hex(bitcmp(fix(2^16*-a(i)),18)+1)) end end for i=2:length(b) fprintf('\tx%1d \t1 \t0 \n',i); end for i=2:length(a) fprintf('\ty%1d \t1 \t0 \n',i); end fprintf('; end data section') disp(' ') disp('CHECK scaling! all b''s and a''s <1 absolute value?') disp('BUT as big as possible?') b a %sampling rate on DE2 board % Fs = 48000; % [b,a] = butter(order, freq) ; %figure(1);clf; % [fresponse, ffreq] = freqz(b,a,300); % plot(ffreq/pi*Fs/2,abs(fresponse), 'b', 'linewidth',2); % xlabel('frequency'); ylabel('filter amplitude'); % hold on % b = fix((b*(2^-scale))*2^16) % a = fix((a*(2^-scale))*2^16) % [fresponse, ffreq] = freqz(b,a,300); % plot(ffreq/pi*Fs/2,abs(fresponse), 'r', 'linewidth',2); % legend('exact','scaled 16-bit')