ProteoWizard
SavitzkyGolaySmoother.hpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Matt Chambers <matt.chambers <a.t> vanderbilt.edu>
6//
7// Copyright 2008 Spielberg Family Center for Applied Proteomics
8// Cedars-Sinai Medical Center, Los Angeles, California 90048
9//
10// Licensed under the Apache License, Version 2.0 (the "License");
11// you may not use this file except in compliance with the License.
12// You may obtain a copy of the License at
13//
14// http://www.apache.org/licenses/LICENSE-2.0
15//
16// Unless required by applicable law or agreed to in writing, software
17// distributed under the License is distributed on an "AS IS" BASIS,
18// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19// See the License for the specific language governing permissions and
20// limitations under the License.
21//
22
23
24#ifndef _SAVITZKYGOLAYSMOOTHER_HPP_
25#define _SAVITZKYGOLAYSMOOTHER_HPP_
26
27
29#include <vector>
30
31
32namespace pwiz {
33namespace analysis {
34
35
36template <typename T>
38{
39 public:
40 static std::vector<T> smooth_copy(const std::vector<T>& data)
41 {
42 if (data.size() < 9)
43 return data;
44 typename std::vector<T>::const_iterator start;
45 typename std::vector<T> smoothedData(data.begin(), data.begin()+4);
46 for (start = data.begin();
47 (start+8) != data.end();
48 ++start)
49 {
50 T sum = 59 * *(start+4) + 54 * (*(start+3) + *(start+5)) +
51 39 * (*(start+2) + *(start+6)) + 14 * (*(start+1) + *(start+7)) -
52 21 * (*start + *(start+8));
53 smoothedData.push_back(sum / 231);
54 }
55 smoothedData.insert(smoothedData.end(), data.end()-4, data.end());
56 return smoothedData;
57 }
58};
59
60} // namespace analysis
61} // namespace pwiz
62
63#endif // _SAVITZKYGOLAYSMOOTHER_HPP_
static std::vector< T > smooth_copy(const std::vector< T > &data)