Next  |  Prev  |  Up  |  Top  |  JOS Index  |  JOS Pubs  |  JOS Home  |  Search

Printing/Plotting the Output Signal(s)

Sometimes, beyond inspecting the block diagram, it may be necessary to verify the output signal(s) in more detail. For this purpose, FAUST has a useful ``architecture file'' named plot.cpp which results in generation of a main C++ program that simply prints the output signal(s) to the standard output. This printout can be used to plot the output (using, e.g., gnuplot) or compare it to the output of some other program. A similar architecture file, matlabplot.cpp, results in a program that outputs an input file for Matlab or Octave that will define a matlab matrix containing each FAUST output signal in a column of the matrix. These techniques are discussed further in the following subsections.

This section gives an example of comparing the impulse response of the filter in Fig.5 to the output of a matlab version. Specifically, we will compare the printed output from the Faust-generated program to the output of the matlab test program shown in Fig.10.

Figure 10: Constant Peak-Gain Resonator--matlab version

 
SR = 44100; % Sampling rate

fr = 1000;  % Resonant frequency
bw = 100;   % Bandwidth
g  = 1;     % Peak gain
N = 10;     % Samples to generate in test

R = exp(-pi*bw/SR); % pole radius
A = 2*pi*fr/SR;     % pole angle (radians)
firpart = g * [1 0 -1] * (1-R^2)/2;
feedback = [1 -2*R*cos(A) R^2]; % freq-domain coeffs
freqz(firpart,feedback);        % freq-response display
format long;
h = impz(firpart,feedback,N)    % print impulse response

In our FAUST program, we need a test impulse, e.g.,

  process = 1-1' : firpart : + ~ feedback
  with { ... <same as before> ... };
The signal $ \texttt{1}=[1,1,1,\ldots]$ is the unit-step signal consisting of all ones, and $ \texttt{1'}=[0,1,1,\ldots]$ is the unit step delayed by one sample. Therefore, 1-1' is the impulse signal $ \delta = [1,0,0,\ldots]$ .

Suppose the file cpgrir.dsp (``Constant-Peak-Gain Resonator Impulse-Response'') contains our test FAUST program. Then we can generate the impulse-response printout as follows at the command line:

  > faust -a plot.cpp -o cpgrir-print.cpp cpgrir.dsp
  > g++ -Wall -g -lm -lpthread cpgrir-print.cpp -o cpgrir-print
  > cpgrir-print -n 10
(Commands similar to the first two lines above are carried out more conveniently using the faust2plot utility distributed with Faust.) The first line generates the C++ program cpgrir.cpp from the FAUST source file cpgrir.dsp using the architecture file plot.cpp. The second line compiles the C++ file to produce the executable program cpgrir-print. Finally, the third line generates and prints the first 10 samples of the output signal (anything more than the number of filter coefficients is usually enough), which is our desired impulse response:15
   h = [    0.00707331  0.0139039   0.013284
            0.012405    0.0112882   0.00995947
            0.00844865  0.00678877  0.00501544
            0.00316602      ... ]
The matlab version produces the following impulse response:
h =
 [ 0.00707328459864603 0.01390382707778288 0.01328399389241600
   0.01240496991806334 0.01128815312793390 0.00995943544693653
   0.00844861689634155 0.00678874919376101 0.00501542304704597
   0.00316601431505539 ... ]
Since matlab uses double-precision floating-point while FAUST used single-precision floats in this example, we see differences after six or so decimal digits. The precision of the float type in FAUST can be extended to double or quad by changing the compile line as follows:
  > faust -double ...
  > faust -quad ...


Next  |  Prev  |  Up  |  Top  |  JOS Index  |  JOS Pubs  |  JOS Home  |  Search

Download aspf.pdf
[Comment on this page via email]

``Audio Signal Processing in Faust'', by Julius O. Smith III
Copyright © 2023-08-16 by Julius O. Smith III
Center for Computer Research in Music and Acoustics (CCRMA),   Stanford University
CCRMA