Sign in

username:

password:



Not a member?

Search Online Books



Search tips

Free Online Books

Ads

Chapters

Chapter Contents:

Search Introduction to Digital Filters

  

Book Index | Global Index


Would you like to be notified by email when Julius Orion Smith III publishes a new entry into his blog?

  

Software Implementation in C++

Figure 3.3 gives a C++ program for implementing the same filter using the Synthesis Tool Kit (STK). The example writes a sound file containing white-noise followed by filtered-noise from the example filter.

Figure 3.3: C++ main program for computing filtered noise using the example digital filter. The Synthesis Tool Kit (STK), version 4.2, supplies the Noise and Filter classes used.

 
/* main.cpp - filtered white noise example */

#include "Noise.h"  /* Synthesis Tool Kit (STK) class */
#include "Filter.h" /* STK class */
#include "FileWvOut.h"  /* STK class */
#include <cmath>   /* for pow() */
#include <vector>

int main()
{
  Noise *theNoise = new Noise(); // Noise source

  /* Set up the filter */
  StkFloat bCoefficients[5] = {1,0,0,pow(0.5,3)}; 
  std::vector<StkFloat> b(bCoefficients, bCoefficients+5);
  StkFloat aCoefficients[7] = {1,0,0,0,0,pow(0.9,5)};
  std::vector<StkFloat> a(aCoefficients, aCoefficients+7);
  Filter *theFilter = new Filter;
  theFilter->setNumerator(b);
  theFilter->setDenominator(a);

  FileWvOut output("main");  /* write to main.wav */

  /* Generate one second of white noise */
  StkFloat amp = 0.1; // noise amplitude
  for (long i=0;i<SRATE;i++)   {
    output.tick(amp*theNoise->tick());
  }

  /* Generate filtered noise for comparison */
  for (long i=0;i<SRATE;i++)   {
    output.tick(theFilter->tick(amp*theNoise->tick()));
  }
}


Order a Hardcopy of Introduction to Digital Filters

Previous: Sample-Level Implementation in Matlab
Next: Software Implementation in Faust

written by Julius Orion Smith III
Julius Smith's background is in electrical engineering (BS Rice 1975, PhD Stanford 1983). He is presently Professor of Music and Associate Professor (by courtesy) of Electrical Engineering at Stanford's Center for Computer Research in Music and Acoustics (CCRMA), teaching courses and pursuing research related to signal processing applied to music and audio systems. See http://ccrma.stanford.edu/~jos/ for details.


Comments


No comments yet for this page


Add a Comment
You need to login before you can post a comment (best way to prevent spam). ( Not a member? )