Nsound  0.9.4
FilterLeastSquaresFIR.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: FilterLeastSquaresFIR.h 874 2014-09-08 02:21:29Z weegreenblobbie $
4 //
5 // Nsound is a C++ library and Python module for audio synthesis featuring
6 // dynamic digital filters. Nsound lets you easily shape waveforms and write
7 // to disk or plot them. Nsound aims to be as powerful as Csound but easy to
8 // use.
9 //
10 // Copyright (c) 2010 - Present Nick Hilton
11 //
12 // weegreenblobbie_yahoo_com (replace '_' with '@' and '.')
13 //
14 //-----------------------------------------------------------------------------
15 
16 //-----------------------------------------------------------------------------
17 //
18 // This program is free software; you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation; either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 // This program is distributed in the hope that it will be useful,
24 // but WITHOUT ANY WARRANTY; without even the implied warranty of
25 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 // GNU Library General Public License for more details.
27 //
28 // You should have received a copy of the GNU General Public License
29 // along with this program; if not, write to the Free Software
30 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 //
32 //-----------------------------------------------------------------------------
33 #ifndef _NSOUND_FILTER_LEAST_SQUARES_FIR_H_
34 #define _NSOUND_FILTER_LEAST_SQUARES_FIR_H_
35 
36 #include <Nsound/Filter.h>
37 #include <Nsound/WindowType.h>
38 
39 #include <set>
40 
41 namespace Nsound
42 {
43 
44 //-----------------------------------------------------------------------------
46 //
49 {
50  public:
51 
53  const float64 & sample_rate,
54  uint32 kernel_size,
55  const Buffer & freq_axis,
56  const Buffer & amplitude_axis,
57  const float64 & beta = 5.0);
58 
60 
61  virtual ~FilterLeastSquaresFIR();
62 
63  Buffer
64  getKernel() const;
65 
66  void
67  setKernel(const Buffer & k);
68 
69  Buffer
71 
72  Buffer
74 
76  filter(const AudioStream & x);
77 
78  // ! This filter type does not support dynamic frequency response.
80  filter(const AudioStream & x, const float64 & frequency)
81  { return filter(x); };
82 
83  // ! This filter type does not support dynamic frequency response.
85  filter(const AudioStream & x, const Buffer & frequencies)
86  { return filter(x); };
87 
88  Buffer
89  filter(const Buffer & x);
90 
91  // ! This filter type does not support dynamic frequency response.
92  Buffer
93  filter(const Buffer & x, const float64 & frequency)
94  { return filter(x); };
95 
96  // ! This filter type does not support dynamic frequency response.
97  Buffer
98  filter(const Buffer & x, const Buffer & frequencies)
99  { return filter(x); };
100 
101  virtual
102  float64
103  filter(const float64 & x);
104 
105  // ! This filter type does not support dynamic frequency response.
106  float64
107  filter(const float64 & x, const float64 & frequency_Hz)
108  { return filter(x); };
109 
111  Buffer
113  {return Filter::getImpulseResponse();};
114 
116  operator=(const FilterLeastSquaresFIR & rhs);
117 
118  void
119  plot(boolean show_fc = true, boolean show_phase = false);
120 
123  void
124  reset();
125 
126  void
127  setWindow(WindowType type);
128 
129  void
130  makeKernel(
131  const Buffer & freq_axis,
132  const Buffer & amplitude_axis);
133 
134  protected:
135 
138 
142 
145 
146 }; // LowPassFilter
147 
148 }; // Nsound
149 
150 // :mode=c++: jEdit modeline
151 #endif
unsigned int uint32
Definition: Nsound.h:153
void makeKernel(const Buffer &freq_axis, const Buffer &amplitude_axis)
AudioStream filter(const AudioStream &x)
void plot(boolean show_fc=true, boolean show_phase=false)
AudioStream filter(const AudioStream &x, const Buffer &frequencies)
double float64
Definition: Nsound.h:146
Buffer getImpulseResponse(const uint32 n_samples=8192)
Definition: Filter.cc:225
Base class for IIR Filters, defines the interface.
Definition: Filter.h:49
Buffer filter(const Buffer &x, const Buffer &frequencies)
FilterLeastSquaresFIR(const float64 &sample_rate, uint32 kernel_size, const Buffer &freq_axis, const Buffer &amplitude_axis, const float64 &beta=5.0)
FilterLeastSquaresFIR & operator=(const FilterLeastSquaresFIR &rhs)
AudioStream filter(const AudioStream &x, const float64 &frequency)
Buffer filter(const Buffer &x, const float64 &frequency)
A Buffer for storing audio samples.
Definition: Buffer.h:60
A FIR filter that is defined as the least square error to the desired requency response.
float64 filter(const float64 &x, const float64 &frequency_Hz)
WindowType
Definition: WindowType.h:39