~ubuntu-branches/ubuntu/trusty/gsl-ref-html/trusty

« back to all changes in this revision

Viewing changes to DWT-Examples.html

  • Committer: Bazaar Package Importer
  • Author(s): Dirk Eddelbuettel
  • Date: 2006-04-12 19:46:32 UTC
  • mfrom: (1.3.1 upstream) (3.1.1 dapper)
  • Revision ID: james.westby@ubuntu.com-20060412194632-c9lodpl075pv9si3
Tags: 1.8-1
* New upstream release 1.8
* As with previous releases, the sources were obtained from the FSF web 
  pages by means of a wget call (c.f. the debian/rules target 'upstream')

* debian/control: Standards-Version increased to 3.6.2
* debian/copyright: Updated FSF address
* debian/rules: Set DH_COMPAT=4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<html lang="en">
 
2
<head>
 
3
<title>DWT Examples - GNU Scientific Library -- Reference Manual</title>
 
4
<meta http-equiv="Content-Type" content="text/html">
 
5
<meta name="description" content="GNU Scientific Library -- Reference Manual">
 
6
<meta name="generator" content="makeinfo 4.8">
 
7
<link title="Top" rel="start" href="index.html#Top">
 
8
<link rel="up" href="Wavelet-Transforms.html#Wavelet-Transforms" title="Wavelet Transforms">
 
9
<link rel="prev" href="DWT-Transform-Functions.html#DWT-Transform-Functions" title="DWT Transform Functions">
 
10
<link rel="next" href="DWT-References.html#DWT-References" title="DWT References">
 
11
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
 
12
<!--
 
13
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 The GSL Team.
 
14
 
 
15
Permission is granted to copy, distribute and/or modify this document
 
16
under the terms of the GNU Free Documentation License, Version 1.2 or
 
17
any later version published by the Free Software Foundation; with the
 
18
Invariant Sections being ``GNU General Public License'' and ``Free Software
 
19
Needs Free Documentation'', the Front-Cover text being ``A GNU Manual'',
 
20
and with the Back-Cover Text being (a) (see below).  A copy of the
 
21
license is included in the section entitled ``GNU Free Documentation
 
22
License''.
 
23
 
 
24
(a) The Back-Cover Text is: ``You have freedom to copy and modify this
 
25
GNU Manual, like GNU software.''-->
 
26
<meta http-equiv="Content-Style-Type" content="text/css">
 
27
<style type="text/css"><!--
 
28
  pre.display { font-family:inherit }
 
29
  pre.format  { font-family:inherit }
 
30
  pre.smalldisplay { font-family:inherit; font-size:smaller }
 
31
  pre.smallformat  { font-family:inherit; font-size:smaller }
 
32
  pre.smallexample { font-size:smaller }
 
33
  pre.smalllisp    { font-size:smaller }
 
34
  span.sc    { font-variant:small-caps }
 
35
  span.roman { font-family:serif; font-weight:normal; } 
 
36
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
 
37
--></style>
 
38
</head>
 
39
<body>
 
40
<div class="node">
 
41
<p>
 
42
<a name="DWT-Examples"></a>
 
43
Next:&nbsp;<a rel="next" accesskey="n" href="DWT-References.html#DWT-References">DWT References</a>,
 
44
Previous:&nbsp;<a rel="previous" accesskey="p" href="DWT-Transform-Functions.html#DWT-Transform-Functions">DWT Transform Functions</a>,
 
45
Up:&nbsp;<a rel="up" accesskey="u" href="Wavelet-Transforms.html#Wavelet-Transforms">Wavelet Transforms</a>
 
46
<hr>
 
47
</div>
 
48
 
 
49
<h3 class="section">30.4 Examples</h3>
 
50
 
 
51
<p>The following program demonstrates the use of the one-dimensional
 
52
wavelet transform functions.  It computes an approximation to an input
 
53
signal (of length 256) using the 20 largest components of the wavelet
 
54
transform, while setting the others to zero.
 
55
 
 
56
<pre class="example"><pre class="verbatim">     #include &lt;stdio.h>
 
57
     #include &lt;math.h>
 
58
     #include &lt;gsl/gsl_sort.h>
 
59
     #include &lt;gsl/gsl_wavelet.h>
 
60
     
 
61
     int
 
62
     main (int argc, char **argv)
 
63
     {
 
64
       int i, n = 256, nc = 20;
 
65
       double *data = malloc (n * sizeof (double));
 
66
       double *abscoeff = malloc (n * sizeof (double));
 
67
       size_t *p = malloc (n * sizeof (size_t));
 
68
     
 
69
       gsl_wavelet *w;
 
70
       gsl_wavelet_workspace *work;
 
71
     
 
72
       w = gsl_wavelet_alloc (gsl_wavelet_daubechies, 4);
 
73
       work = gsl_wavelet_workspace_alloc (n);
 
74
     
 
75
       FILE *f = fopen (argv[1], "r");
 
76
       for (i = 0; i &lt; n; i++)
 
77
         {
 
78
           fscanf (f, "%lg", &amp;data[i]);
 
79
         }
 
80
       fclose (f);
 
81
     
 
82
       gsl_wavelet_transform_forward (w, data, 1, n, work);
 
83
     
 
84
       for (i = 0; i &lt; n; i++)
 
85
         {
 
86
           abscoeff[i] = fabs (data[i]);
 
87
         }
 
88
       
 
89
       gsl_sort_index (p, abscoeff, 1, n);
 
90
       
 
91
       for (i = 0; (i + nc) &lt; n; i++)
 
92
         data[p[i]] = 0;
 
93
       
 
94
       gsl_wavelet_transform_inverse (w, data, 1, n, work);
 
95
       
 
96
       for (i = 0; i &lt; n; i++)
 
97
         {
 
98
           printf ("%g\n", data[i]);
 
99
         }
 
100
     }
 
101
</pre></pre>
 
102
   <p class="noindent">The output can be used with the <span class="sc">gnu</span> plotutils <code>graph</code> program,
 
103
 
 
104
<pre class="example">     $ ./a.out ecg.dat &gt; dwt.dat
 
105
     $ graph -T ps -x 0 256 32 -h 0.3 -a dwt.dat &gt; dwt.ps
 
106
</pre>
 
107
   </body></html>
 
108