Plotting window functions

8 kwietnia 2010 00:33 tags:

This is a very simple way to get a preview of window function shape. The example uses Aquila::TextPlot as a drawing tool. Windows are drawn as simple asterisk patterns.

#include "aquila/source/window/BarlettWindow.h"
#include "aquila/source/window/BlackmanWindow.h"
#include "aquila/source/window/FlattopWindow.h"
#include "aquila/source/window/HammingWindow.h"
#include "aquila/source/window/HannWindow.h"
#include "aquila/source/window/RectangularWindow.h"
#include "aquila/tools/TextPlot.h"

int main(int argc, char *argv[])
{
    const std::size_t LENGTH = 65;
    Aquila::TextPlot plot;

    Aquila::BarlettWindow barlett(LENGTH);
    plot.setTitle("Barlett");
    plot.plot(barlett);

    Aquila::BlackmanWindow blackman(LENGTH);
    plot.setTitle("Blackman");
    plot.plot(blackman);

    Aquila::FlattopWindow flattop(LENGTH);
    plot.setTitle("Flattop");
    plot.plot(flattop);

    Aquila::HammingWindow hamming(LENGTH);
    plot.setTitle("Hamming");
    plot.plot(hamming);

    Aquila::HannWindow hann(LENGTH);
    plot.setTitle("Hann");
    plot.plot(hann);

    Aquila::RectangularWindow rect(LENGTH);
    plot.setTitle("Rectangular");
    plot.plot(rect);

    return 0;
}

The windows are plotted below for comparison. Note: the rectangular window is improperly scaled at the moment and looks like it's all zeros. It isn't, that is a constant 1.

Barlett
                               ***                               
                             **   **                             
                           **       **                           
                         **           **                         
                       **               **                       
                     **                   **                     
                   **                       **                   
                 **                           **                 
               **                               **               
             **                                   **             
           **                                       **           
         **                                           **         
       **                                               **       
     **                                                   **     
   **                                                       **   
***                                                           ***

Blackman
                            *********                            
                           *         *                           
                         **           **                         
                        *               *                        
                       *                 *                       
                      *                   *                      
                     *                     *                     
                    *                       *                    
                  **                         **                  
                 *                             *                 
                *                               *                
               *                                 *               
             **                                   **             
           **                                       **           
        ***                                           ***        
********                                                 ********

Flat-top
                              *****                              
                             *     *                             
                            *       *                            
                           *         *

                          *           *                          
                         *             *

                        *               *                        
                       *                 *

                      *                   *                      
                     *                     *                     
                    *                       *                    
****              **                         **              ****
    **************                             **************

Hamming
                           ***********                           
                         **           **                         
                       **               **                       
                      *                   *                      
                    **                     **                    
                   *                         *                   
                  *                           *                  
                 *                             **                
               **                                *               
              *                                   *              
             *                                     *             
           **                                       **           
          *                                           *          
        **                                             **        
      **                                                 **      
******                                                     ******

Hann
                           ***********                           
                         **           **                         
                       **               **                       
                      *                   *                      
                    **                     **                    
                   *                         *                   
                  *                           *                  
                 *                             **                
               **                                *               
              *                                   *              
             *                                     *             
           **                                       **           
          *                                           *          
        **                                             **        
      **                                                 **      
******                                                     ******

Rectangular















*****************************************************************
« Return to list