-
Notifications
You must be signed in to change notification settings - Fork 4
/
DisplaySpectrumSource.cpp
executable file
·76 lines (61 loc) · 1.91 KB
/
DisplaySpectrumSource.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// DisplaySpectrumSource.cpp: implementation of the CDisplaySpectrumSource class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "SpectrumAnalysis.h"
#include "DisplaySpectrumSource.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CDisplaySpectrumSource::CDisplaySpectrumSource()
{
m_pSpectrum = NULL;
}
CDisplaySpectrumSource::CDisplaySpectrumSource(CSignal* in_pSignal)
{
AttachSource(in_pSignal);
InitSource();
}
CDisplaySpectrumSource::~CDisplaySpectrumSource()
{
}
INT CDisplaySpectrumSource::InitSource()
{
if(m_pSpectrum == NULL) return SPA_ERR_INVALID_DPSOURCE;
//set FXaxis dB
SetFXName(SPA_AXIS_UNIT_DB);
SetFXUnitVal(SPA_DECIBEN_UNIT);
SetFXMax(m_pSpectrum->GetMaxSample());
SetFXMin(m_pSpectrum->GetMinSample());
//set Xaxis Hz
SetXName(SPA_AXIS_UNIT_HZ);
SetXUnitVal(SPA_HZ_UNIT);
SetXMin(0);
DOUBLE dMax = 0.5 * m_pSpectrum->GetFrequency();
SetXMax(dMax);
return SPA_NORMAL;
}
//////////////////////////////////////////////////////////////////////////
// return the spectrum sample value at specified frequence
// x: frequency (Hz)
// Fx: Amplitude (dB)
DOUBLE CDisplaySpectrumSource::Fx(DOUBLE x)
{
LONG lSignalSize = m_pSpectrum->GetSignalSize() ;
DOUBLE pos = (x * (DOUBLE)lSignalSize) / (DOUBLE)m_pSpectrum->GetFrequency();
SAMPLE retVal = (*m_pSpectrum)[(LONG)pos];
return retVal;
}
//////////////////////////////////////////////////////////////////////////
INT CDisplaySpectrumSource::AttachSource(CSignal *in_pSignal)
{
m_pSpectrum = in_pSignal;
m_spMax = in_pSignal->GetMaxSample();
m_spMin = in_pSignal->GetMinSample();
return SPA_NORMAL;
}