Floating-point fixed-point operation in DSP--an example and _c language in programming

Source: Internet
Author: User

5. Examples and the experience in programming

5. 1 examples

"The 3rd chapter of DSP Chip fixed-point operation. doc" This article gives a very simple example that can explain the problem, do not want to move the brain, directly cited here as follows.

This is a speech signal (0.3khz~3.4khz) Low-pass filtering of the C language program, Low-pass filter cut-off frequency of 800Hz, filter using 19 points of the finite impact response fir filter. The sample frequency of the speech signal is 8kHz, and each voice sample is stored in the Insp.dat file according to the 16-bit integer number.

Example 3.7 speech signal 800Hz 19 Point Fir Low-pass filter C-language floating-point program

Copy Code code as follows:
#include <stdio.h>
const int length = 180/* Speech frame length is 180 point =22.5ms@8khz sampling * *
void filter (int xin[],int xout[],int n,float h[]); /* Filter subroutine Description * *
/*19 Point Filter Coefficient * *
static float h[19]=
{0.01218354,-0.009012882,-0.02881839,-0.04743239,-0.04584568,
-0.008692503,0.06446265,0.1544655,0.2289794,0.257883,
0.2289794,0.1544655,0.06446265,-0.008692503,-0.04584568,
-0.04743239,-0.02881839,-0.009012882,0.01218354};
static int x1[length+20];
* Low-pass filter floating point program * *
void filter (int xin[],int xout[],int n,float h[])
{
int i,j;
float sum;
for (i=0;i<length;i++) x1[n+i-1]=xin[i];
for (i=0;i<length;i++)
{
sum=0.0;
for (j=0;j<n;j++) sum+=h[j]*x1[i-j+n-1];
xout[i]= (int) sum;
}
For (i=0;i< (n-1); i++) x1[n-i-2]=xin[length-1-i];
}

/* Main program * *
void Main ()
{
FILE *FP1,*FP2;
int frame,indata[length],outdata[length];
Fp1=fopen (Insp.dat, "RB"); /* Input Voice file * *
Fp2=fopen (Outsp.dat, "WB"); /* Filtered Voice file * *

frame=0;
while (feof (FP1) ==0)
{
frame++;
printf ("frame=%d/n", frame);
for (i=0;i<length;i++) INDATA[I]=GETW (FP1); /* Take a frame of voice data * *
Filter (INDATA,OUTDATA,19,H); /* Call Low pass filter subroutine * *
for (i=0;i<length;i++) PUTW (OUTDATA[I],FP2); /* The filtered sample value is written to the file * *
}
Fcloseall (); /* Close File/*
return (0);
}

Example 3.8 speech signal 800Hz 19 Point Fir Low pass filter C language fixed-point program

Copy Code code as follows:
#include <stdio.h>
const int length=180;
void filter (int xin[],int xout[],int n,int h[]);
static int h[19]={399,-296,-945,-1555,-1503,-285,2112,5061,7503,8450,
7503,5061,2112,-285,-1503,-1555,-945,-296,399}; /*q15*/
static int x1[length+20];
/* Low-pass Filter fixed-point subroutine * *
void filter (int xin[],int xout[],int n,int h[])
{
int i,j;
Long sum;
for (i=0;i<length;i++) x1[n+i-1]=xin[i];
for (i=0;i<length;i++)
{
sum=0;
for (j=0;j<n;j++) sum+= (long) h[j]*x1[i-j+n-1];
xout[i]=sum>>15;
}
For (i=0;i< (n-1); i++) x1[n-i-2]=xin[length-i-1];
}

The main program is exactly the same as floating point.

5. 2 Experience in programming

Through the above example, I believe that we all have a general understanding of the process of conversion. A function module So, a large software project conversion is nothing more. The difference is that for a project, there are very few separate modules, generally are a few or several modules have links, Qian Yi hair and move the whole body, so, before the conversion, it is best to clarify the relationship between the various software modules.

Coordination, coordination, and coordination.

Here, with Afreez. Study on floating-point fixed-point operation in DSP the discussion of the problem can finally be put to a pen. Procrastination, pulled for 3 months, and now finally can be the guilt of their own. Starting from the third part, write a hurry, because there is not enough time to write, but also want to finish the rest, can only be so solved. I think, the article just give the scholar a train of thought, if oneself later encounter such question, still need oneself to explore, have no once and for all article, after all the question all different.

The article inevitably has the improper place, welcome everybody criticism correction!

The above is the entire content of this article, I hope to give you a reference, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.