DSP Interpolation and decimation
본 자료는 7페이지 의 미리보기를 제공합니다. 이미지를 클릭하여 주세요.
닫기
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
해당 자료는 7페이지 까지만 미리보기를 제공합니다.
7페이지 이후부터 다운로드 후 확인할 수 있습니다.

소개글

DSP Interpolation and decimation에 대한 보고서 자료입니다.

본문내용

code (2번 문제)
#include
#include
#define N 1024 // the number of given data
#define M 4 // interpolation factor
#define m_PI 3.141592
#define FORWARD 0
#define INVERSE 1
void fft(double *fr, double *fi, int n, int inv);
//Main Function
void main(void)
{
int i=0, j=0;
int n=0;
double x[N]; // for x_n or X_real
double y[N]= {0.0}; // for X_imaginary
double x_p[N]={0.0}; //for x_p or X_p real
double y_p[N]={0.0}; //for X_p imaginary
double x_d[N/M]={0.0}; //for x_d or X_d real
double y_d[N/M]={0.0}; //for X_d imaginary
double zero[N]={0.0};
double input;
FILE *ifp, *ofp, *ofp1, *ofp2, *ofp3, *ofp4, *ofp5, *ofp6, *ofp7;
ifp = fopen("hw2.txt","r");
ofp = fopen("x_n.xls","w");
ofp1 = fopen("X_k.xls","w");
ofp2 = fopen("x_p_n.xls","w");
ofp3 = fopen("X_p_k.xls","w");
ofp4 = fopen("x_d_n.xls","w");
ofp5 = fopen("X_d_k.xls","w");
ofp6 = fopen("inverse_x_n.xls","w");
ofp7 = fopen("Hz_k.xls","w");
// input file
while (fscanf(ifp, "%lf", &input) == 1)
{
x[i] = input;
i++;
}
//fft processing
fft(x,y,1024,FORWARD);
//anti-aliasing filter Hz
double Hz[N] = {0.0};
for(i=0;i {
if((i>=0 && i=(N-N/(2*M))&&i Hz[i] = 1.0;
fprintf(ofp7, "%lf\n", Hz[i]);
}
for(i=0;i {
x[i] = x[i]*Hz[i];
y[i] = y[i]*Hz[i];
fprintf(ofp1, "%lf\n", sqrt(x[i]*x[i]+y[i]*y[i]));
}
fft(x,y,N,INVERSE); //Inverse FT
for(i=0;i fprintf(ofp, "%lf\n", x[i]);
// prodicing x_p and x_d
for(i=0;i {
if(i%M==0)
{
x_p[i] = x[i];
x_d[i/M] = x[i];
fprintf(ofp4,"%lf\n",x_d[i/M]);
}
else
x_p[i] = 0.0;
}
//for(i=0;i //fprintf(ofp4,"%lf\n",x_d[i]);
for(i=0;i fprintf(ofp2,"%lf\n",x_p[i]);
// fft processing
fft(x_p,y_p,N,FORWARD);
fft(x_d,y_d,N/M,FORWARD);
// printing X_p
for(i=0;i fprintf(ofp3, "%lf\n", sqrt(x_p[i]*x_p[i]+y_p[i]*y_p[i]));
// printing X_d
for(i=0;i fprintf(ofp5, "%lf\n", sqrt(x_d[i]*x_d[i]+y_d[i]*y_d[i]));
//Inverse
fft(x_d,y_d,N/M,INVERSE);
// printing x_d
for(i=0;i fprintf(ofp6, "%lf\n", x_d[i]);
//
}/////////end main
// FFT Function
void fft(double *fr, double *fi, int n, int inv)
{
int i, j, j1, j2, k, iter, irem, s, m, n1, n2, nxp, mxp, nxp2;
double arg, wr, wi, tr, ti, wpwr;
iter = 0;
irem = n;
while ((irem / 2) >= 1) {
iter++;
irem /= 2;
}
s = (inv ? 1 : -1);
nxp2 = n;
for (i = 0; i < iter; i++) {
nxp = nxp2;
nxp2 = nxp / 2;
wpwr = m_PI / (double)nxp2;
for (m = 0; m < nxp2; m++) {
arg = (double)m * wpwr;
wr = cos(arg);
wi = s * sin(arg);
for (mxp = nxp; mxp <= n ; mxp += nxp) {
j1 = mxp - nxp + m;
j2 = j1 + nxp2;
tr = fr[j1] - fr[j2];
ti = fi[j1] - fi[j2];
fr[j1] = fr[j1] + fr[j2];
fi[j1] = fi[j1] + fi[j2];
fr[j2] = tr * wr - ti * wi;
fi[j2] = tr * wi + ti * wr;
}}}
n2 = n / 2;
n1 = n - 1;
j = 1;
for (i = 1; i <= n1; i++) {
if (i < j) {
tr = fr[j - 1];
ti = fi[j - 1];
fr[j - 1] = fr[i - 1];
fi[j - 1] = fi[i - 1];
fr[i - 1] = tr;
fi[i - 1] = ti;
}
k = n2;
while (k < j) {
j -= k;
k /= 2;
} j += k;
}
if (inv)
for (i = 0; i < n; i++) {
fr[i] /= n;
fi[i] /= n;
}
}
  • 가격1,000
  • 페이지수21페이지
  • 등록일2007.06.25
  • 저작시기2007.4
  • 파일형식한글(hwp)
  • 자료번호#416682
본 자료는 최근 2주간 다운받은 회원이 없습니다.
청소해
다운로드 장바구니