Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How to change the following floating pomint FFT.c into a fixed point FFT.c? fft.h is provided. fft.h: /* This function calculates the Fourier Transform of

How to change the following floating pomint FFT.c into a fixed point FFT.c? fft.h is provided.

fft.h:

/*

This function calculates the Fourier Transform of the sampled input using the Cooley-Tukey algorithm.

before this function is entered,

the static array q must be filled with the floating point values of the sampled input;

w must be a static zero filled array of size samples;

new_ and new_im must be static arrays of size samples;

the functions mult_re, mult_im, sine and cosine must be defined;

Inputs

q - the real part of the sampled input

w - zero filled array used for the imaginary part of the input

n - the number of samples

m - the power of 2 that equals n

f_sample - the sampling frequency

after the function has completed,

q will contain the real parts of the Fourier Transformed values of the input;

w will contain the imaginary parts of the Fourier Transformed values of the input;

the begining half of new_ will contain the squared magnitudes of the first half of the output;

place will contain the bin number containing the greatest squared magnitude;

max will contain the value of the largest squared magnitude;

Returns

frequency - the frequency of the input

*/

#ifndef FFT_H

#define FFT_H

#define PI 3.141592//65358979323846

float fft(float* q, float* w, int n, int m, float sample_f);

#endif

fft.c:

#include "fft.h"

#include "complex.h"

#include "trig.h"

static float new_[128];

static float new_im[128];

float fft(float* q, float* w, int n, int m, float sample_f) {

int a,b,r,d,e,c;

int k,place;

a=n/2;

b=1;

int i,j;

float real=0,imagine=0;

float max,frequency;

// ORdering algorithm

for(i=0; i<(m-1); i++){

d=0;

for (j=0; j

for (c=0; c

e=c+d;

new_[e]=q[(c*2)+d];

new_im[e]=w[(c*2)+d];

new_[e+a]=q[2*c+1+d];

new_im[e+a]=w[2*c+1+d];

}

d+=(n/b);

}

for (r=0; r

q[r]=new_[r];

w[r]=new_im[r];

}

b*=2;

a=n/(2*b);

}

//end ordering algorithm

b=1;

k=0;

for (j=0; j

//MATH

for(i=0; i

if (i%(n/b)==0 && i!=0)

k++;

real=mult_real(q[i+1], w[i+1], cosine(-PI*k/b), sine(-PI*k/b));

imagine=mult_im(q[i+1], w[i+1], cosine(-PI*k/b), sine(-PI*k/b));

new_[i]=q[i]+real;

new_im[i]=w[i]+imagine;

new_[i+1]=q[i]-real;

new_im[i+1]=w[i]-imagine;

}

for (i=0; i

q[i]=new_[i];

w[i]=new_im[i];

}

//END MATH

//REORDER

for (i=0; i

new_[i]=q[2*i];

new_[i+(n/2)]=q[2*i+1];

new_im[i]=w[2*i];

new_im[i+(n/2)]=w[2*i+1];

}

for (i=0; i

q[i]=new_[i];

w[i]=new_im[i];

}

//END REORDER

b*=2;

k=0;

}

//find magnitudes

max=0;

place=1;

for(i=1;i<(n/2);i++) {

new_[i]=q[i]*q[i]+w[i]*w[i];

if(max < new_[i]) {

max=new_[i];

place=i;

}

}

float s=sample_f/n; //spacing of bins

frequency = (sample_f/n)*place;

//curve fitting for more accuarcy

//assumes parabolic shape and uses three point to find the shift in the parabola

//using the equation y=A(x-x0)^2+C

float y1=new_[place-1],y2=new_[place],y3=new_[place+1];

float x0=s+(2*s*(y2-y1))/(2*y2-y1-y3);

x0=x0/s-1;

if(x0 <0 || x0> 2) { //error

return 0;

}

if(x0 <= 1) {

frequency=frequency-(1-x0)*s;

}

else {

frequency=frequency+(x0-1)*s;

}

return frequency;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To Database 2

Authors: Bruce L. Larson

1st Edition

0070232679, 978-0070232679

More Books

Students also viewed these Databases questions

Question

6. Identify characteristics of whiteness.

Answered: 1 week ago