关于DSP数字锁相放大器的设计
/*****************head file********************/
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
#include "math.h"
#include "stdio.h"
#include "stdlib.h"
// Determine when the shift to right justify the data takes place
// Only one of these should be defined as 1.
// The other two should be defined as 0.
#define POST_SHIFT 0 // Shift results after the entire sample table is full
#define INLINE_SHIFT 1 // Shift results as the data is taken from the results regsiter
#define NO_SHIFT 0 // Do not shift the results
// ADC start parameters
#if (CPU_FRQ_150MHZ) // Default - 150 MHz SYSCLKOUT
#define ADC_MODCLK 0x3 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 150/(2*3) = 25.0 MHz
#endif
#if (CPU_FRQ_100MHZ)
#define ADC_MODCLK 0x2 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 100/(2*2) = 25.0 MHz
#endif
#define ADC_CKPS 0x0 // ADC module clock = HSPCLK/1 = 25.5MHz/(1) = 25.0 MHz
#define ADC_SHCLK 0x1 // S/H width in ADC module periods = 2 ADC cycle
#define AVG 1000 // Average sample limit
#define ZOFFSET 0x00 // Average Zero offset
#define BUF_SIZE 512 // Sample buffer size
#define N 180
#define M 140
#define pi 3.1416
#define b 34 //h(n)的序列长度
#define a 40 //h(n)的序列长度
#define c 2*N+b-1
float array_sin[180];
float array_cos[180];
float SampleTable1[BUF_SIZE]={0};
float SampleTable2[BUF_SIZE]={0};
float SampleTable3[BUF_SIZE]={0};
Uint16 SampleTable[BUF_SIZE];
float SampleValue[BUF_SIZE];
float y1[N-1]={0.0}; //输出序列
float y2[c]={0.0};
void InitEPwm1Example();
volatile unsigned int adconvover=0;
interrupt void epwm1_timer_isr(void);
Uint16 EPwm1TimerIntCount;
Uint16 array_index;
const float L[34] = {
0, 0.0002864978729488, 0.001264624162909, 0.003083310527426,
0.005841204980407, 0.009575017244339, 0.01425214897781, 0.01976834915372,
0.02595074975146, 0.03256621452731, 0.03933450837311, 0.0459454018102,
0.05207849738032, 0.05742432989344, 0.06170517100719, 0.06469397151492,
0.06623000282249, 0.06623000282249, 0.06469397151492, 0.06170517100719,
0.05742432989344, 0.05207849738032, 0.0459454018102, 0.03933450837311,
0.03256621452731, 0.02595074975146, 0.01976834915372, 0.01425214897781,
0.009575017244339, 0.005841204980407, 0.003083310527426, 0.001264624162909,
0.0002864978729488,0
};
const float H[40] = {
-0.001305096054213,-0.001478350963911, -0.00188527402024,-0.002559610054874,
-0.003537780947164,-0.004860232357888,-0.006573547322234,-0.008733738690038,
-0.01141141434653, -0.01470003343206, -0.01872949362692, -0.02368939446207,
-0.02987095372283, -0.03774760142235, -0.0481434027665, -0.06262584473804,
-0.08457160676635, -0.1227895346972, -0.2096342344354, -0.6364784631899,
0.6364784631899, 0.2096342344354, 0.1227895346972, 0.08457160676635,
0.06262584473804, 0.0481434027665, 0.03774760142235, 0.02987095372283,
0.02368939446207, 0.01872949362692, 0.01470003343206, 0.01141141434653,
0.008733738690038, 0.006573547322234, 0.004860232357888, 0.003537780947164,
0.002559610054874, 0.00188527402024, 0.001478350963911, 0.001305096054213
};
void LinearConvolution();
void sin_start()
{
int n=0;
float interval =2*pi/180;
for (n=0;n >4);
SampleValue[array_index] = SampleTable[array_index]*3.0/4096;
// If 40 conversions have been logged, start over
if(array_index == 140)
{
LinearConvolution(M,a,SampleValue,H,y1);//线性卷积
mode=0;
for(k = 0;k 0;i--) //将*h作为被乘数
{
l=k;
for(j=xn-1;j>0;j--) //数组x[n]的1~(xn-1)与h[i]逐一相乘
{
y[l]+=h[i]*x[j];
l--;
}
y[l]+=x[0]*h[i];
k--;
}
l=k;
for(j=xn-1;j>0;j--)
{
y[l]+=h[0]*x[j];
l--;
}
y[l]+=x[0]*h[0];
}
//===========================================================================
// No more.
//===========================================================================
我也想弄个,你现在做出来了没,分享点经验吧
