No BSD License  

Highlights from
Fixed-point signal processing in M

image thumbnail
from Fixed-point signal processing in M by Tom Bryan
Functions accompanying MATLAB News & Notes article "Fixed-point Signal Processing: Getting Started"

fi_signal_processing_example.m
% This M-code was used to produce the plots in the News and Notes article
% Fixed-point Signal Processing: Getting Started, by Darel A. Linebarger 
% and Thomas A. Bryan, 2004.
%
% The Fixed-Point Toolbox and the Signal Processing Toolbox are required to
% run this example.

% Set word sizes
Wprod=32; Wacc=40; Wb=16; Wx=12; Wy=16;
% 
% Initialize floating-point variables
%
[L,fo,mo,w] = firpmord([1500 2000],[1 0],[0.01 0.1], 8000);
b_flt = firpm(L,fo,mo,w);
N = 100; t = (0:N-1)';
x_flt = sin(2*pi*0.1*t) + sin(2*pi*0.2885*t);
y_flt = zeros(size(x_flt));
%
% Initialize fixed-point variables
%
b_fi = fi(b_flt, 1, Wb);
x_fi = fi(x_flt, 1, Wx);
y_fi = fi(zeros(size(x_fi)), 1, Wy, ...
          Wy-innerprodintbits(b_fi,x_fi));
%
% Configure fixed-point arithmetic (fimath)
%
    F = fimath('ProductMode','KeepLSB', 'ProductWordLength',Wprod,...
           'SumMode','KeepLSB', 'SumWordLength',Wacc);
    b.fimath = F; x.fimath = F;
    % Run fixed- and floating-point algorithms
    y_fi  = fir_filter(b_fi, x_fi, y_fi);
    y_flt = fir_filter(b_flt, x_flt, y_flt);


subplot(411); plot(t,x_flt); title('Original signal','fontsize',14);set(gca,'fontsize',14);
subplot(412); plot(t,y_flt); title('Floating-point output','fontsize',14);set(gca,'fontsize',14);
subplot(413); plot(t,y_fi);  title('Fixed-point output','fontsize',14);set(gca,'fontsize',14);
subplot(414); plot(t,double(y_fi)-y_flt); title('Difference between fixed and float','fontsize',14);set(gca,'fontsize',14);
  

Contact us at files@mathworks.com