Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <math.h>
- #include <stdio.h>
- #include <conio.h>
- double X(double t) {
- return(1.0*sin(2.0*M_PI*10000.0*t)*cos(2.0*M_PI*20000.0*t));
- }
- struct complexx {
- double Re;
- double Im;
- };
- struct complexx cmplx(double A, double B) {
- struct complexx result;
- result.Re=A;
- result.Im=B;
- return(result);
- }
- struct complexx cMult(struct complexx A, struct complexx B) {
- struct complexx result;
- result.Re=A.Re*B.Re-A.Im*B.Im;
- result.Im=A.Re*B.Im+A.Im*B.Re;
- return(result);
- }
- struct complexx cDiv(struct complexx nr, struct complexx d) {
- double btm, re_top, im_top;
- struct complexx result;
- btm=d.Re*d.Re+d.Im*d.Im;
- re_top=nr.Re*d.Re+nr.Im*d.Im;
- im_top=nr.Im*d.Re-nr.Re*d.Im;
- result.Re=re_top/btm;
- result.Im=im_top/btm;
- return(result);
- }
- struct complexx cAdd(struct complexx A, struct complexx B) {
- struct complexx result;
- result.Re=A.Re+B.Re;
- result.Im=A.Im+B.Im;
- return(result);
- }
- int main(void) {
- //clrscr();
- double x[8];
- struct complexx z[8];
- int N=8;
- int n,m;
- struct complexx sXz=cmplx((double)0.0, (double)0.0);
- double re,im;
- double h,fs;
- fs=80000;
- h=1.0/fs;
- double sX;
- double sY;
- double XX[8],YY[8];
- for(m=0;m<N;m=m+1) {
- sX=0.0;
- sY=0.0;
- for(n=0;n<N;n=n+1) {
- sX=sX+X(n*h)*cos(2.0*M_PI*(double)n*(double)m/(double)N);
- sY=sY-X(n*h)*sin(2.0*M_PI*(double)n*(double)m/(double)N);
- }
- XX[m]=sX;
- YY[m]=sY;
- printf("\n DFT X(%d)=%12.4f",m,*(XX+m));
- printf(" Y(%d)=%12.4f",m,*(YY+m));
- }
- for(n=0;n<N;n=n+1) {
- sXz=cmplx(0.0, 0.0);
- for(m=0;m<N;m=m+1) {
- sXz=cAdd(sXz,cMult(cmplx(XX[m],YY[m]),cmplx(cos(2.0*M_PI*n*m/N),sin(2.0*M_PI*n*m/N))));
- }
- printf("\n IDFT");
- printf(" x(%d) %12.4f ",n,cDiv(sXz,cmplx(N,0.0)));
- }
- printf("\n probki sygnalu");
- for(n=0;n<N;n=n+1) printf("\n x[%d]=%12.4f ",n,X(n/fs));
- int abc;
- scanf("%d", &abc);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement