Skip to content

Commit 342ff03

Browse files
author
Tony Kirke
committed
Add rectangular window, put window normalizing into qt_window app
1 parent 7f80f29 commit 342ff03

File tree

4 files changed

+21
-22
lines changed

4 files changed

+21
-22
lines changed

qt_window/make_filter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ double make_filter::update(double *w) {
9393
case Kaiser: taps = design_window("kaiser", kaiser_taps, kaiser_beta); break;
9494
case None: for (int i = 0; i < pts; i++) w[i] = 1.0; break;
9595
}
96-
/*
97-
std::cout << "Taps[] = {";
98-
for (size_t i=0;i<taps.size();i++) std::cout << taps[i] << " ";
99-
std::cout << "}\n";
100-
*/
96+
// Normalize for Frequency plots
97+
float_type sum = 0;
98+
for (size_t i=0;i<taps.size();i++) sum += taps[i];
99+
for (size_t i=0;i<taps.size();i++) taps[i] /= sum;
100+
101101
fir_freq(taps, pts, w, 1.0);
102102
return (0);
103103
}

spuce/filters/design_window.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,9 @@ std::vector<float_type> design_window(const std::string& fir_type, int order, fl
2424
} else if (fir_type == "chebyshev") {
2525
win = cheby(order, beta);
2626
} else {
27-
std::cout << "Invalid type " << fir_type << "\n";
27+
win = rectangular(order);
2828
}
2929

30-
// Normalize DC response to 1.0
31-
float_type sum = 0;
32-
for (size_t i=0;i<win.size();i++) sum += win[i];
33-
for (size_t i=0;i<win.size();i++) win[i] /= sum;
3430
return win;
3531
}
3632
} // namespace spuce

spuce/filters/window.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ float_type io(float_type x) {
7171
}
7272
return (e);
7373
}
74+
std::vector<float_type> rectangular(long nf) {
75+
std::vector<float_type> w(nf);
76+
for (int i = 0; i < nf; i++) w[i] = 1.0;
77+
return (w);
78+
}
7479
//! \ingroup fir
7580
//! \brief hamming window \f$ w(n) = 0.54 - 0.46*cos( 2*\pi*n/(nf-1) )\f$
7681
std::vector<float_type> hamming(long nf) {

spuce/filters/window.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,32 @@ namespace spuce {
66
//! \file
77
//! \brief Various FIR window functions: hamming,hanning,blackman,kaiser, chebyshev
88
//
9-
//! \brief bessel function for kaiser window
10-
//! \author Tony Kirke
11-
//! \ingroup functions fir
12-
float_type io(float_type x);
9+
//! \brief rectangular window \f$ w(n) = 1;\f$
10+
//! \ingroup functions fir
11+
std::vector<float_type> rectangular(long nf);
1312
//! \brief hamming window \f$ w(n) = 0.54 - 0.46*cos( 2*\pi*n/(nf-1) )\f$
14-
//! \author Tony Kirke
1513
//! \ingroup functions fir
1614
std::vector<float_type> hamming(long nf);
1715
//! \brief hanning window \f$ w(n) = 0.5( 1 - cos( 2*\pi*n/(nf-1) )\f$
18-
//! \author Tony Kirke
1916
//! \ingroup functions fir
2017
std::vector<float_type> hann(long nf);
18+
//! \ingroup functions fir
2119
std::vector<float_type> hanning(long nf);
2220
//! \brief Blackman Window \f$ w[x] = 0.42 - 0.5*cos(2*\pi*x/nf) + 0.08*cos(2*\pi*x/nf)\f$
23-
//! \author Tony Kirke
2421
//! \ingroup functions fir
2522
std::vector<float_type> blackman(long nf);
2623
//! \brief kaiser window
27-
//! \author Tony Kirke
2824
//! \ingroup functions fir
2925
std::vector<float_type> kaiser(long nf, float_type beta);
30-
//! \brief calculate beta for kaiser window for a given ripple
31-
float_type kaiser_beta(float_type beta);
3226
//! \brief dolph chebyshev window design
33-
//! \author Tony Kirke
3427
//! \ingroup functions fir
3528
std::vector<float_type> cheby(int nf, float_type alpha);
36-
//
3729
//! \brief bartlett window design
30+
//! \ingroup functions fir
3831
std::vector<float_type> bartlett(long nf);
32+
//! \brief calculate beta for kaiser window for a given ripple
33+
float_type kaiser_beta(float_type beta);
34+
//! \brief bessel function for kaiser window
35+
float_type io(float_type x);
36+
3937
} // namespace spuce

0 commit comments

Comments
 (0)