kfr

Fast, modern C++ DSP framework, FFT, Sample Rate Conversion, FIR/IIR/Biquad Filters (SSE, AVX, AVX-512, ARM NEON)
Log | Files | Refs | README

window.cpp (3664B)


      1 /**
      2  * KFR (https://www.kfrlib.com)
      3  * Copyright (C) 2016-2023 Dan Cazarin
      4  * See LICENSE.txt for details
      5  */
      6 
      7 #include <kfr/base.hpp>
      8 #include <kfr/dsp.hpp>
      9 #include <kfr/io.hpp>
     10 
     11 using namespace kfr;
     12 
     13 int main()
     14 {
     15     // Print the version of the KFR library being used
     16     println(library_version());
     17 
     18     // Define options for plotting DSP data
     19     const std::string options = "freqresp=True, dots=True, padwidth=1024, "
     20                                 "log_freq=False, horizontal=False, normalized_freq=True";
     21 
     22     // Declare a univector of type fbase with a size of 64 to hold the window function output
     23     univector<fbase, 64> output;
     24 
     25     // Generate a Hann window function and save the plot
     26     output = window_hann(output.size());
     27     plot_save("window_hann", output, options + ", title='Hann window'");
     28 
     29     // Generate a Hamming window function and save the plot
     30     output = window_hamming(output.size());
     31     plot_save("window_hamming", output, options + ", title='Hamming window'");
     32 
     33     // Generate a Blackman window function and save the plot
     34     output = window_blackman(output.size());
     35     plot_save("window_blackman", output, options + ", title='Blackman window'");
     36 
     37     // Generate a Blackman-Harris window function and save the plot
     38     output = window_blackman_harris(output.size());
     39     plot_save("window_blackman_harris", output, options + ", title='Blackman-Harris window'");
     40 
     41     // Generate a Gaussian window function and save the plot
     42     output = window_gaussian(output.size());
     43     plot_save("window_gaussian", output, options + ", title='Gaussian window'");
     44 
     45     // Generate a Triangular window function and save the plot
     46     output = window_triangular(output.size());
     47     plot_save("window_triangular", output, options + ", title='Triangular window'");
     48 
     49     // Generate a Bartlett window function and save the plot
     50     output = window_bartlett(output.size());
     51     plot_save("window_bartlett", output, options + ", title='Bartlett window'");
     52 
     53     // Generate a Cosine window function and save the plot
     54     output = window_cosine(output.size());
     55     plot_save("window_cosine", output, options + ", title='Cosine window'");
     56 
     57     // Generate a Cosine window function compatible with numpy and save the plot
     58     output = window_cosine_np(output.size());
     59     plot_save("window_cosine_np", output, options + ", title='Cosine window (numpy compatible)'");
     60 
     61     // Generate a Bartlett-Hann window function and save the plot
     62     output = window_bartlett_hann(output.size());
     63     plot_save("window_bartlett_hann", output, options + ", title='Bartlett-Hann window'");
     64 
     65     // Generate a Bohman window function and save the plot
     66     output = window_bohman(output.size());
     67     plot_save("window_bohman", output, options + ", title='Bohman window'");
     68 
     69     // Generate a Lanczos window function and save the plot
     70     output = window_lanczos(output.size());
     71     plot_save("window_lanczos", output, options + ", title='Lanczos window'");
     72 
     73     // Generate a Flat top window function and save the plot
     74     output = window_flattop(output.size());
     75     plot_save("window_flattop", output, options + ", title='Flat top window'");
     76 
     77     // Generate a Kaiser window function with a beta value of 2.5 and save the plot
     78     output = window_kaiser(output.size(), 2.5);
     79     plot_save("window_kaiser", output, options + ", title='Kaiser window'");
     80 
     81     // Generate a Planck-taper window function with an epsilon value of 0.1 and save the plot
     82     output = window_planck_taper(output.size(), 0.1);
     83     plot_save("window_planck_taper", output, options + ", title='Planck-taper window'");
     84 
     85     println("SVG plots have been saved to svg directory");
     86 
     87     return 0;
     88 }