Lemma is an Electromagnetics API
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

WindowFilter.cpp 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* This file is part of Lemma, a geophysical modelling and inversion API */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. /**
  6. @file
  7. @author Trevor Irons
  8. @date 07/20/2010
  9. @version $Id: windowfilter.cpp 87 2013-09-05 22:44:05Z tirons $
  10. **/
  11. #include "WindowFilter.h"
  12. namespace Lemma {
  13. // ==================== LIFECYCLE =======================
  14. WindowFilter::WindowFilter( ) : Filter( ),
  15. Width(0), SamplingRate(0), Bandwidth(0), Coefficients(),
  16. Type(RECTANGULAR) {}
  17. std::shared_ptr< WindowFilter > WindowFilter::NewSP() {
  18. std::shared_ptr<WindowFilter> sp(new WindowFilter( ), LemmaObjectDeleter() );
  19. return sp;
  20. }
  21. WindowFilter::~WindowFilter() {
  22. }
  23. // ==================== OPERATIONS =======================
  24. void WindowFilter::SetWindowType(const WINDOWTYPE &type) {
  25. Type = type;
  26. }
  27. void WindowFilter::SetBandwidth(const Real& width) {
  28. Bandwidth = width;
  29. }
  30. void WindowFilter::SetSamplingInterval(const Real& rate) {
  31. SamplingRate = rate;
  32. }
  33. int WindowFilter::GetNumberOfFrequencyBins() {
  34. return this->Nw;
  35. }
  36. void WindowFilter::SetNumberOfSamples(const int& nt) {
  37. Nt = nt;
  38. Nw = Nt%2 ? (Nt-1)/2+1 : (Nt)/2+1; // odd , even
  39. }
  40. VectorXr WindowFilter::GetFilterCoefficients() {
  41. Real Nyquist = .5/SamplingRate;
  42. std::cout << "Window nyquist " << Nyquist << std::endl;
  43. std::cout << "Window Nw " << Nw << std::endl;
  44. Real df = (Nyquist)/((Real)(Nw)); // df Hz per bin
  45. Width = Bandwidth/df;
  46. Coefficients.resize(Width);
  47. switch (Type) {
  48. case HAMMING:
  49. for (int n=0; n<Width; ++n) {
  50. Coefficients(n) = 0.5 * (1.- std::cos( (2.*PI*(Real)(n)) /
  51. ((Real)(Width)-1.) ) );
  52. }
  53. break;
  54. case HANNING:
  55. for (int n=0; n<Width; ++n) {
  56. Coefficients(n) = 0.54 - 0.46 *
  57. std::cos( (2.*PI*(Real)(n)) /
  58. ((Real)(Width)-1.) ) ;
  59. }
  60. break;
  61. case RECTANGULAR:
  62. Coefficients.setOnes();
  63. break;
  64. }
  65. return Coefficients;
  66. }
  67. } // ----- end of Lemma name -----