00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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;
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