Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

VrChirpSource.h

Go to the documentation of this file.
00001 /* -*- Mode: c++ -*- */ 00002 00003 /* 00004 * Copyright 2001 Free Software Foundation, Inc. 00005 * 00006 * This file is part of GNU Radio 00007 * 00008 * GNU Radio is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2, or (at your option) 00011 * any later version. 00012 * 00013 * GNU Radio is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with GNU Radio; see the file COPYING. If not, write to 00020 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00021 * Boston, MA 02111-1307, USA. 00022 */ 00023 00024 #ifndef _VRCHIRPSOURCE_H_ 00025 #define _VRCHIRPSOURCE_H_ 00026 00027 extern "C" { 00028 #include <math.h> 00029 #include <sys/time.h> 00030 #include <unistd.h> 00031 #include <stdio.h> 00032 } 00033 00034 #include <VrSource.h> 00035 00036 00037 template<class oType> 00038 class VrChirpSource : public VrSource<oType> { 00039 00040 public: 00041 virtual const char *name () { return "VrChirpSource"; } 00042 00043 virtual int work2(VrSampleRange output, void *o[]); 00044 00045 VrChirpSource (double sample_freq, 00046 double amplitude, 00047 double chirp_sweep_freq); 00048 00049 virtual void initialize (); 00050 00051 00052 protected: 00053 double sampling_freq; // Hz 00054 double amplitude; 00055 double phase; 00056 00057 double chirp_sweep_freq; 00058 double chirp_incr; 00059 double chirp_min_freq; 00060 double chirp_max_freq; 00061 double chirp_current_freq; 00062 }; 00063 00064 template<class oType> 00065 VrChirpSource<oType>::VrChirpSource (double a_sampling_freq, 00066 double a_amplitude, 00067 double a_chirp_sweep_freq) 00068 { 00069 sampling_freq = a_sampling_freq; 00070 setSamplingFrequency (sampling_freq); 00071 amplitude = a_amplitude; 00072 chirp_sweep_freq = a_chirp_sweep_freq; 00073 phase = 0.0; 00074 } 00075 00076 template<class oType> void 00077 VrChirpSource<oType>::initialize() 00078 { 00079 chirp_min_freq = 0; 00080 chirp_max_freq = sampling_freq / 2; 00081 chirp_current_freq = chirp_min_freq; 00082 00083 chirp_incr = (((chirp_max_freq - chirp_min_freq) * chirp_sweep_freq / 2) 00084 / sampling_freq); 00085 #if 1 00086 printf ("chirp_min_freq = %g\n", chirp_min_freq); 00087 printf ("chirp_max_freq = %g\n", chirp_max_freq); 00088 printf ("chirp_current_freq = %g\n", chirp_current_freq); 00089 printf ("chirp_incr = %g\n", chirp_incr); 00090 #endif 00091 } 00092 00093 template<class oType> int 00094 VrChirpSource<oType>::work2(VrSampleRange output, void *ao[]) 00095 { 00096 oType **ov = (oType **)ao; 00097 oType *o = ov[0]; 00098 unsigned int size = output.size; 00099 00100 sync (output.index); 00101 00102 double two_pi_over_sf = 2 * M_PI / sampling_freq; 00103 00104 00105 while (size-- > 0) { 00106 *o++ = (oType) (amplitude * sin (phase)); 00107 phase += two_pi_over_sf * chirp_current_freq; 00108 00109 chirp_current_freq += chirp_incr; 00110 if (chirp_current_freq >= chirp_max_freq) 00111 chirp_current_freq = chirp_min_freq; 00112 } 00113 00114 return output.size; 00115 } 00116 00117 #endif

Generated on Wed Aug 4 02:22:05 2004 for GNU Radio by doxygen 1.3.8