Hello everyone,
I am Marko Kanadi from Mitsuhashi laboratory, UEC, Japan
Currently I am working on signals separation and aim to implement the algorithm
on the C6713 DSK. However since it deals with stereo signals thus I need to
store the sample signals of each channel into two separate buffer (before
it's further processed in FFT block). Moreover, I need to use at least 512
point buffer for each channel according to a constraint in the algorithm. BUT,
if I use 512 point buffer for each channel, the output signals are distorted.
However the distortion is less when I use smaller buffer. Is this because I
wrote an inefficient code or is this a limitation of C6713 DSP machine? I really
hope someone can help me on this problem.
Thank you very much for your concern.
Below written my codes:
//----------------------------------
// FFTiFFT.c : Source code for real-time FFT continued by iFFT
// Aim : Obtain the same result as input even after domain transformation
// Coder : Marko Kanadi
// Starting Date : November 7th, 2009
// Laboratory : Mitsuhashi Laboratory, University of Electro-Communications,
Japan
//-----------------------------------
#include // Contains codes of mathematical functions
#include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_cfftr2_dit.h" //DSP67x
library for FFT
#include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_icfftr2_dif.h" //DSP67x
library for IFFT
#define N 2 // # of points for FFT
#define O 4 // 2 * # of points for FFT
#define PI 3.14159265358979 // PI = 3.14 = 22/7
#include "dsk6713_aic23.h" // codec-DSK support file
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; // Set sampling rate
#define LEFT 0
#define RIGHT 1
union {Uint32 combo; short channel[2];} AIC23_input;
union {Uint32 combo; short channel[2];} AIC23_output;
float iobuffer_left[N], iobuffer_right[N]; // input output buffer
float samples_left[O], samples_right[O]; // primary working buffer
short buffercount = 0;
short flag=0;
short i=0; // general purpose index variable
short j=0; // general purpose even index variable
short k=0; // general purpose odd index variable
float function1_left[O], function1_right[O]; // multipurpose variable for any
function no.1 : just copy the value of variable
main()
{
comm_poll(); // init DSK, codec, McBSP
while(1)
{
while(flag == 0)
{
AIC23_output.channel[LEFT]=iobuffer_left[buffercount];
AIC23_output.channel[RIGHT]=iobuffer_right[buffercount];
output_sample(AIC23_output.combo); //out from iobuffer
AIC23_input.combo = input_sample();
iobuffer_left[buffercount]=(float)(AIC23_input.channel[LEFT]);
iobuffer_right[buffercount]=(float)(AIC23_input.channel[RIGHT]);
buffercount++;
if(buffercount >= N)
{
buffercount = 0;
flag = 1;
}
for (i=0; i
{
j=2*i;
k=(2*i)+1;
samples_left[j]=iobuffer_left[i]; // fill primary working buffer with new
data
samples_right[j]=iobuffer_right[i];
samples_left[k]=0.0; // fill the imaginary part with 0.0
samples_right[k]=0.0;
iobuffer_left[i]=function1_left[j]; // fill buffer with result of
function1
iobuffer_right[i]=function1_right[j];
function1_left[j]=samples_left[j];
function1_left[k]=samples_left[k];
function1_right[j]=samples_right[j];
function1_right[k]=samples_right[k];
}
flag=0;
}
}
}
_____________________________________
distorted output on 512 point stereo buffer
Started by ●November 8, 2009
Reply by ●November 8, 20092009-11-08
Hello, I guess you have a bug somewhere. What do you mean by distortion? Have
you tried using a test signal and compared it with your simulation results?
-----Original Message-----
From: m...@yahoo.com
Sent: 11/9/2009 12:45:09 AM
To: c...
Subject: [c6x] distorted output on 512 point stereo buffer
Hello everyone,
I am Marko Kanadi from Mitsuhashi laboratory, UEC, Japan
Currently I am working on signals separation and aim to implement the algorithm on the C6713 DSK. However since it deals with stereo signals thus I need to store the sample signals of each channel into two separate buffer (before it's further processed in FFT block). Moreover, I need to use at least 512 point buffer for each channel according to a constraint in the algorithm. BUT, if I use 512 point buffer for each channel, the output signals are distorted. However the distortion is less when I use smaller buffer. Is this because I wrote an inefficient code or is this a limitation of C6713 DSP machine? I really hope someone can help me on this problem.
Thank you very much for your concern.
Below written my codes:
//----------------------------------
// FFTiFFT.c : Source code for real-time FFT continued by iFFT
// Aim : Obtain the same result as input even after domain transformation
// Coder : Marko Kanadi
// Starting Date : November 7th, 2009
// Laboratory : Mitsuhashi Laboratory, University of Electro-Communications, Japan
//-----------------------------------
#include // Contains codes of mathematical functions
#include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_cfftr2_dit.h" //DSP67x library for FFT
#include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_icfftr2_dif.h" //DSP67x library for IFFT
#define N 2 // # of points for FFT
#define O 4 // 2 * # of points for FFT
#define PI 3.14159265358979 // PI = 3.14 = 22/7
#include "dsk6713_aic23.h" // codec-DSK support file
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; // Set sampling rate
#define LEFT 0
#define RIGHT 1
union {Uint32 combo; short channel[2];} AIC23_input;
union {Uint32 combo; short channel[2];} AIC23_output;
float iobuffer_left[N], iobuffer_right[N]; // input output buffer
float samples_left[O], samples_right[O]; // primary working buffer
short buffercount = 0;
short flag=0;
short i=0; // general purpose index variable
short j=0; // general purpose even index variable
short k=0; // general purpose odd index variable
float function1_left[O], function1_right[O]; // multipurpose variable for any function no.1 : just copy the value of variable
main()
{
comm_poll(); // init DSK, codec, McBSP
while(1)
{
while(flag == 0)
{
AIC23_output.channel[LEFT]=iobuffer_left[buffercount];
AIC23_output.channel[RIGHT]=iobuffer_right[buffercount];
output_sample(AIC23_output.combo); //out from iobuffer
AIC23_input.combo = input_sample();
iobuffer_left[buffercount]=(float)(AIC23_input.channel[LEFT]);
iobuffer_right[buffercount]=(float)(AIC23_input.channel[RIGHT]);
buffercount++;
if(buffercount >= N)
{
buffercount = 0;
flag = 1;
}
for (i=0; i {
j=2*i;
k=(2*i)+1;
samples_left[j]=iobuffer_left[i]; // fill primary working buffer with new data
samples_right[j]=iobuffer_right[i];
samples_left[k]=0.0; // fill the imaginary part with 0.0
samples_right[k]=0.0;
iobuffer_left[i]=function1_left[j]; // fill buffer with result of function1
iobuffer_right[i]=function1_right[j];
function1_left[j]=samples_left[j];
function1_left[k]=samples_left[k];
function1_right[j]=samples_right[j];
function1_right[k]=samples_right[k];
}
flag=0;
}
}
}
_____________________________________
-----Original Message-----
From: m...@yahoo.com
Sent: 11/9/2009 12:45:09 AM
To: c...
Subject: [c6x] distorted output on 512 point stereo buffer
Hello everyone,
I am Marko Kanadi from Mitsuhashi laboratory, UEC, Japan
Currently I am working on signals separation and aim to implement the algorithm on the C6713 DSK. However since it deals with stereo signals thus I need to store the sample signals of each channel into two separate buffer (before it's further processed in FFT block). Moreover, I need to use at least 512 point buffer for each channel according to a constraint in the algorithm. BUT, if I use 512 point buffer for each channel, the output signals are distorted. However the distortion is less when I use smaller buffer. Is this because I wrote an inefficient code or is this a limitation of C6713 DSP machine? I really hope someone can help me on this problem.
Thank you very much for your concern.
Below written my codes:
//----------------------------------
// FFTiFFT.c : Source code for real-time FFT continued by iFFT
// Aim : Obtain the same result as input even after domain transformation
// Coder : Marko Kanadi
// Starting Date : November 7th, 2009
// Laboratory : Mitsuhashi Laboratory, University of Electro-Communications, Japan
//-----------------------------------
#include // Contains codes of mathematical functions
#include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_cfftr2_dit.h" //DSP67x library for FFT
#include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_icfftr2_dif.h" //DSP67x library for IFFT
#define N 2 // # of points for FFT
#define O 4 // 2 * # of points for FFT
#define PI 3.14159265358979 // PI = 3.14 = 22/7
#include "dsk6713_aic23.h" // codec-DSK support file
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; // Set sampling rate
#define LEFT 0
#define RIGHT 1
union {Uint32 combo; short channel[2];} AIC23_input;
union {Uint32 combo; short channel[2];} AIC23_output;
float iobuffer_left[N], iobuffer_right[N]; // input output buffer
float samples_left[O], samples_right[O]; // primary working buffer
short buffercount = 0;
short flag=0;
short i=0; // general purpose index variable
short j=0; // general purpose even index variable
short k=0; // general purpose odd index variable
float function1_left[O], function1_right[O]; // multipurpose variable for any function no.1 : just copy the value of variable
main()
{
comm_poll(); // init DSK, codec, McBSP
while(1)
{
while(flag == 0)
{
AIC23_output.channel[LEFT]=iobuffer_left[buffercount];
AIC23_output.channel[RIGHT]=iobuffer_right[buffercount];
output_sample(AIC23_output.combo); //out from iobuffer
AIC23_input.combo = input_sample();
iobuffer_left[buffercount]=(float)(AIC23_input.channel[LEFT]);
iobuffer_right[buffercount]=(float)(AIC23_input.channel[RIGHT]);
buffercount++;
if(buffercount >= N)
{
buffercount = 0;
flag = 1;
}
for (i=0; i {
j=2*i;
k=(2*i)+1;
samples_left[j]=iobuffer_left[i]; // fill primary working buffer with new data
samples_right[j]=iobuffer_right[i];
samples_left[k]=0.0; // fill the imaginary part with 0.0
samples_right[k]=0.0;
iobuffer_left[i]=function1_left[j]; // fill buffer with result of function1
iobuffer_right[i]=function1_right[j];
function1_left[j]=samples_left[j];
function1_left[k]=samples_left[k];
function1_right[j]=samples_right[j];
function1_right[k]=samples_right[k];
}
flag=0;
}
}
}
_____________________________________
Reply by ●November 9, 20092009-11-09
Hello Cristophe and everyone, thank you for your reply.
The output is distorted in sense that the output is not clear as if it was scrambled. And it becomes worse if the size of the buffer is bigger. For example if the size of buffer is only 128, the output is distorted but still clear. But, if the size of buffer is 512, the output is unclear.
I really appreciate if you can help me on this. Thank you very much.
_____________________________________
The output is distorted in sense that the output is not clear as if it was scrambled. And it becomes worse if the size of the buffer is bigger. For example if the size of buffer is only 128, the output is distorted but still clear. But, if the size of buffer is 512, the output is unclear.
I really appreciate if you can help me on this. Thank you very much.
_____________________________________
Reply by ●November 9, 20092009-11-09
Marko-
> I am Marko Kanadi from Mitsuhashi laboratory, UEC, Japan
>
> Currently I am working on signals separation and aim to
> implement the algorithm on the C6713 DSK. However since it
> deals with stereo signals thus I need to store the sample
> signals of each channel into two separate buffer (before
> it's further processed in FFT block). Moreover, I need to
> use at least 512 point buffer for each channel according to
> a constraint in the algorithm. BUT, if I use 512 point
> buffer for each channel, the output signals are distorted.
> However the distortion is less when I use smaller buffer.
> Is this because I wrote an inefficient code or is this a
> limitation of C6713 DSP machine? I really hope someone
> can help me on this problem.
I asume that your code is using input_sample() and output_sample() functions that poll McBSP RRDY and XRDY bits, as
shown on pg 15 of this link:
http://users.etech.haw-hamburg.de/users/ITLabor/DV_Lab_R885/Laboraufgaben_Labtasks/DPL_IE6/LAB-1_GettingFamiliar.pdf
If so then try your code as I marked it below with " <--- HERE ".
With the changes, after you fill a buffer (when flag is set to 0) you will have one sample period in which to swap
left and right buffers (i.e. 125 usec at 8 kHz sampling rate) or otherwise do some processing. Whether you hear
distortion or glitch of some type will depend on whether the processing takes more than 125 usec. In the code shown
below, you have N set to 2, which isn't much of a buffer. But even with a small N, you don't actually wait for N
before you process N samples, which is going to cause output distortion.
After you fix the distortion, then you can think about some "useful processing", not just swapping buffers. Before
you can do something useful (but time-consuming) like an FFT, you will have to implement interrupt based operation,
not polling. Then you can process one buffer while the other buffer is being filled (input) or emptied (output) by an
interrupt service routine (ISR). Suggest to search on "dual buffer", "ping pong buffers" in the context of real-time
operation, to learn more about this.
-Jeff
> Below written my codes:
>
> //----------------------------------
> // FFTiFFT.c : Source code for real-time FFT continued by iFFT
> // Aim : Obtain the same result as input even after domain transformation
> // Coder : Marko Kanadi
> // Starting Date : November 7th, 2009
> // Laboratory : Mitsuhashi Laboratory, University of Electro-Communications, Japan
> //-----------------------------------
>
> #include // Contains codes of mathematical functions
> #include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_cfftr2_dit.h" //DSP67x library for FFT
> #include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_icfftr2_dif.h" //DSP67x library for IFFT
> #define N 2 // # of points for FFT
> #define O 4 // 2 * # of points for FFT
> #define PI 3.14159265358979 // PI = 3.14 = 22/7
> #include "dsk6713_aic23.h" // codec-DSK support file
> Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; // Set sampling rate
> #define LEFT 0
> #define RIGHT 1
> union {Uint32 combo; short channel[2];} AIC23_input;
>
> union {Uint32 combo; short channel[2];} AIC23_output;
>
> float iobuffer_left[N], iobuffer_right[N]; // input output buffer
> float samples_left[O], samples_right[O]; // primary working buffer
> short buffercount = 0;
> short flag=0;
> short i=0; // general purpose index variable
> short j=0; // general purpose even index variable
> short k=0; // general purpose odd index variable
>
> float function1_left[O], function1_right[O]; // multipurpose variable for any function no.1 : just copy the value of
> variable
> main()
> {
> comm_poll(); // init DSK, codec, McBSP
>
> while(1)
> {
> while(flag == 0)
> {
> AIC23_output.channel[LEFT]=iobuffer_left[buffercount];
> AIC23_output.channel[RIGHT]=iobuffer_right[buffercount];
> output_sample(AIC23_output.combo); //out from iobuffer
>
> AIC23_input.combo = input_sample();
> iobuffer_left[buffercount]=(float)(AIC23_input.channel[LEFT]);
> iobuffer_right[buffercount]=(float)(AIC23_input.channel[RIGHT]);
> buffercount++;
>
> if(buffercount >= N)
> {
> buffercount = 0;
> flag = 1;
> }
} // fill buffer <--- HERE
> for (i=0; i > {
> j=2*i;
> k=(2*i)+1;
>
> samples_left[j]=iobuffer_left[i]; // fill primary working buffer with new data
> samples_right[j]=iobuffer_right[i];
> samples_left[k]=0.0; // fill the imaginary part with 0.0
> samples_right[k]=0.0;
>
> iobuffer_left[i]=function1_left[j]; // fill buffer with result of function1
> iobuffer_right[i]=function1_right[j];
>
> function1_left[j]=samples_left[j];
> function1_left[k]=samples_left[k];
> function1_right[j]=samples_right[j];
> function1_right[k]=samples_right[k];
> }
>
> flag=0;
// } // go back to while (1) <--- HERE
>
> }
>
> }
_____________________________________
> I am Marko Kanadi from Mitsuhashi laboratory, UEC, Japan
>
> Currently I am working on signals separation and aim to
> implement the algorithm on the C6713 DSK. However since it
> deals with stereo signals thus I need to store the sample
> signals of each channel into two separate buffer (before
> it's further processed in FFT block). Moreover, I need to
> use at least 512 point buffer for each channel according to
> a constraint in the algorithm. BUT, if I use 512 point
> buffer for each channel, the output signals are distorted.
> However the distortion is less when I use smaller buffer.
> Is this because I wrote an inefficient code or is this a
> limitation of C6713 DSP machine? I really hope someone
> can help me on this problem.
I asume that your code is using input_sample() and output_sample() functions that poll McBSP RRDY and XRDY bits, as
shown on pg 15 of this link:
http://users.etech.haw-hamburg.de/users/ITLabor/DV_Lab_R885/Laboraufgaben_Labtasks/DPL_IE6/LAB-1_GettingFamiliar.pdf
If so then try your code as I marked it below with " <--- HERE ".
With the changes, after you fill a buffer (when flag is set to 0) you will have one sample period in which to swap
left and right buffers (i.e. 125 usec at 8 kHz sampling rate) or otherwise do some processing. Whether you hear
distortion or glitch of some type will depend on whether the processing takes more than 125 usec. In the code shown
below, you have N set to 2, which isn't much of a buffer. But even with a small N, you don't actually wait for N
before you process N samples, which is going to cause output distortion.
After you fix the distortion, then you can think about some "useful processing", not just swapping buffers. Before
you can do something useful (but time-consuming) like an FFT, you will have to implement interrupt based operation,
not polling. Then you can process one buffer while the other buffer is being filled (input) or emptied (output) by an
interrupt service routine (ISR). Suggest to search on "dual buffer", "ping pong buffers" in the context of real-time
operation, to learn more about this.
-Jeff
> Below written my codes:
>
> //----------------------------------
> // FFTiFFT.c : Source code for real-time FFT continued by iFFT
> // Aim : Obtain the same result as input even after domain transformation
> // Coder : Marko Kanadi
> // Starting Date : November 7th, 2009
> // Laboratory : Mitsuhashi Laboratory, University of Electro-Communications, Japan
> //-----------------------------------
>
> #include // Contains codes of mathematical functions
> #include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_cfftr2_dit.h" //DSP67x library for FFT
> #include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_icfftr2_dif.h" //DSP67x library for IFFT
> #define N 2 // # of points for FFT
> #define O 4 // 2 * # of points for FFT
> #define PI 3.14159265358979 // PI = 3.14 = 22/7
> #include "dsk6713_aic23.h" // codec-DSK support file
> Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; // Set sampling rate
> #define LEFT 0
> #define RIGHT 1
> union {Uint32 combo; short channel[2];} AIC23_input;
>
> union {Uint32 combo; short channel[2];} AIC23_output;
>
> float iobuffer_left[N], iobuffer_right[N]; // input output buffer
> float samples_left[O], samples_right[O]; // primary working buffer
> short buffercount = 0;
> short flag=0;
> short i=0; // general purpose index variable
> short j=0; // general purpose even index variable
> short k=0; // general purpose odd index variable
>
> float function1_left[O], function1_right[O]; // multipurpose variable for any function no.1 : just copy the value of
> variable
> main()
> {
> comm_poll(); // init DSK, codec, McBSP
>
> while(1)
> {
> while(flag == 0)
> {
> AIC23_output.channel[LEFT]=iobuffer_left[buffercount];
> AIC23_output.channel[RIGHT]=iobuffer_right[buffercount];
> output_sample(AIC23_output.combo); //out from iobuffer
>
> AIC23_input.combo = input_sample();
> iobuffer_left[buffercount]=(float)(AIC23_input.channel[LEFT]);
> iobuffer_right[buffercount]=(float)(AIC23_input.channel[RIGHT]);
> buffercount++;
>
> if(buffercount >= N)
> {
> buffercount = 0;
> flag = 1;
> }
} // fill buffer <--- HERE
> for (i=0; i > {
> j=2*i;
> k=(2*i)+1;
>
> samples_left[j]=iobuffer_left[i]; // fill primary working buffer with new data
> samples_right[j]=iobuffer_right[i];
> samples_left[k]=0.0; // fill the imaginary part with 0.0
> samples_right[k]=0.0;
>
> iobuffer_left[i]=function1_left[j]; // fill buffer with result of function1
> iobuffer_right[i]=function1_right[j];
>
> function1_left[j]=samples_left[j];
> function1_left[k]=samples_left[k];
> function1_right[j]=samples_right[j];
> function1_right[k]=samples_right[k];
> }
>
> flag=0;
// } // go back to while (1) <--- HERE
>
> }
>
> }
_____________________________________
Reply by ●November 9, 20092009-11-09
Cristophe and everyone,
Cristophe is right, I had bug on my program. I mistakenly put one '}' in the bottom of the code so I included unnecessary loop in every iteration, that is why the result was distorted. I have fixed it and now I am ready to insert FFT and IFFT block inside my program.
Thank you for your concern
Hello everyone,
>
>I am Marko Kanadi from Mitsuhashi laboratory, UEC, Japan
>
>Currently I am working on signals separation and aim to implement the algorithm on the C6713 DSK. However since it deals with stereo signals thus I need to store the sample signals of each channel into two separate buffer (before it's further processed in FFT block). Moreover, I need to use at least 512 point buffer for each channel according to a constraint in the algorithm. BUT, if I use 512 point buffer for each channel, the output signals are distorted. However the distortion is less when I use smaller buffer. Is this because I wrote an inefficient code or is this a limitation of C6713 DSP machine? I really hope someone can help me on this problem.
>
>Thank you very much for your concern.
>
>Below written my codes:
>
>//----------------------------------
>// FFTiFFT.c : Source code for real-time FFT continued by iFFT
>// Aim : Obtain the same result as input even after domain transformation
>// Coder : Marko Kanadi
>// Starting Date : November 7th, 2009
>// Laboratory : Mitsuhashi Laboratory, University of Electro-Communications, Japan
>//-----------------------------------
>
>#include // Contains codes of mathematical functions
>#include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_cfftr2_dit.h" //DSP67x library for FFT
>#include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_icfftr2_dif.h" //DSP67x library for IFFT
>#define N 2 // # of points for FFT
>#define O 4 // 2 * # of points for FFT
>#define PI 3.14159265358979 // PI = 3.14 = 22/7
>#include "dsk6713_aic23.h" // codec-DSK support file
>Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; // Set sampling rate
>#define LEFT 0
>#define RIGHT 1
>union {Uint32 combo; short channel[2];} AIC23_input;
>
>union {Uint32 combo; short channel[2];} AIC23_output;
>
>float iobuffer_left[N], iobuffer_right[N]; // input output buffer
>float samples_left[O], samples_right[O]; // primary working buffer
>short buffercount = 0;
>short flag=0;
>short i=0; // general purpose index variable
>short j=0; // general purpose even index variable
>short k=0; // general purpose odd index variable
>
>float function1_left[O], function1_right[O]; // multipurpose variable for any function no.1 : just copy the value of variable
>main()
>{
>comm_poll(); // init DSK, codec, McBSP
>
>while(1)
>{
> while(flag == 0)
> {
> AIC23_output.channel[LEFT]=iobuffer_left[buffercount];
> AIC23_output.channel[RIGHT]=iobuffer_right[buffercount];
> output_sample(AIC23_output.combo); //out from iobuffer
>
> AIC23_input.combo = input_sample();
> iobuffer_left[buffercount]=(float)(AIC23_input.channel[LEFT]);
> iobuffer_right[buffercount]=(float)(AIC23_input.channel[RIGHT]);
> buffercount++;
>
> if(buffercount > = N)
> {
> buffercount = 0;
> flag = 1;
> }
>
> for (i=0; i
_____________________________________
Cristophe is right, I had bug on my program. I mistakenly put one '}' in the bottom of the code so I included unnecessary loop in every iteration, that is why the result was distorted. I have fixed it and now I am ready to insert FFT and IFFT block inside my program.
Thank you for your concern
Hello everyone,
>
>I am Marko Kanadi from Mitsuhashi laboratory, UEC, Japan
>
>Currently I am working on signals separation and aim to implement the algorithm on the C6713 DSK. However since it deals with stereo signals thus I need to store the sample signals of each channel into two separate buffer (before it's further processed in FFT block). Moreover, I need to use at least 512 point buffer for each channel according to a constraint in the algorithm. BUT, if I use 512 point buffer for each channel, the output signals are distorted. However the distortion is less when I use smaller buffer. Is this because I wrote an inefficient code or is this a limitation of C6713 DSP machine? I really hope someone can help me on this problem.
>
>Thank you very much for your concern.
>
>Below written my codes:
>
>//----------------------------------
>// FFTiFFT.c : Source code for real-time FFT continued by iFFT
>// Aim : Obtain the same result as input even after domain transformation
>// Coder : Marko Kanadi
>// Starting Date : November 7th, 2009
>// Laboratory : Mitsuhashi Laboratory, University of Electro-Communications, Japan
>//-----------------------------------
>
>#include // Contains codes of mathematical functions
>#include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_cfftr2_dit.h" //DSP67x library for FFT
>#include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_icfftr2_dif.h" //DSP67x library for IFFT
>#define N 2 // # of points for FFT
>#define O 4 // 2 * # of points for FFT
>#define PI 3.14159265358979 // PI = 3.14 = 22/7
>#include "dsk6713_aic23.h" // codec-DSK support file
>Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; // Set sampling rate
>#define LEFT 0
>#define RIGHT 1
>union {Uint32 combo; short channel[2];} AIC23_input;
>
>union {Uint32 combo; short channel[2];} AIC23_output;
>
>float iobuffer_left[N], iobuffer_right[N]; // input output buffer
>float samples_left[O], samples_right[O]; // primary working buffer
>short buffercount = 0;
>short flag=0;
>short i=0; // general purpose index variable
>short j=0; // general purpose even index variable
>short k=0; // general purpose odd index variable
>
>float function1_left[O], function1_right[O]; // multipurpose variable for any function no.1 : just copy the value of variable
>main()
>{
>comm_poll(); // init DSK, codec, McBSP
>
>while(1)
>{
> while(flag == 0)
> {
> AIC23_output.channel[LEFT]=iobuffer_left[buffercount];
> AIC23_output.channel[RIGHT]=iobuffer_right[buffercount];
> output_sample(AIC23_output.combo); //out from iobuffer
>
> AIC23_input.combo = input_sample();
> iobuffer_left[buffercount]=(float)(AIC23_input.channel[LEFT]);
> iobuffer_right[buffercount]=(float)(AIC23_input.channel[RIGHT]);
> buffercount++;
>
> if(buffercount > = N)
> {
> buffercount = 0;
> flag = 1;
> }
>
> for (i=0; i
_____________________________________
Reply by ●November 9, 20092009-11-09
Marko-
> Cristophe is right, I had bug on my program. I mistakenly put
> one '}' in the bottom of the code so I included
> unnecessary loop in every iteration, that is why the result
> was distorted. I have fixed it and now I am ready to
> insert FFT and IFFT block inside my program.
The " <--- HERE " changes in my previous post implement Cristophe's fix. But after the fix, you will have to keep
your FFT execution time under 125 usec due to polling constraints, otherwise it still won't work. I don't know what
max FFT size can complete under 125 usec on C6713, but it won't be very big, maybe 32-pt or so. And the actual
polling interval limit may need to be less, for example 60 usec, due to the time it takes for the McBSP to shift out a
sample.
When you reach the point of needing interrupt based operation, let us know.
-Jeff
> Hello everyone,
>>
>>I am Marko Kanadi from Mitsuhashi laboratory, UEC, Japan
>>
>>Currently I am working on signals separation and aim to
>> implement the algorithm on the C6713 DSK. However since it
>> deals with stereo signals thus I need to store the sample
>> signals of each channel into two separate buffer (before
>> it's further processed in FFT block). Moreover, I need to
>> use at least 512 point buffer for each channel according to
>> a constraint in the algorithm. BUT, if I use 512 point buffer
>> for each channel, the output signals are distorted.
>> However the distortion is less when I use smaller buffer. Is
>> this because I wrote an inefficient code or is this a
>> limitation of C6713 DSP machine? I really hope someone can
>> help me on this problem.
>>
>>Thank you very much for your concern.
>>
>>Below written my codes:
>>
>>//----------------------------------
>>// FFTiFFT.c : Source code for real-time FFT continued by iFFT
>>// Aim : Obtain the same result as input even after domain transformation
>>// Coder : Marko Kanadi
>>// Starting Date : November 7th, 2009
>>// Laboratory : Mitsuhashi Laboratory, University of Electro-Communications, Japan
>>//-----------------------------------
>>
>>#include // Contains codes of mathematical functions
>>#include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_cfftr2_dit.h" //DSP67x library for FFT
>>#include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_icfftr2_dif.h" //DSP67x library for IFFT
>>#define N 2 // # of points for FFT
>>#define O 4 // 2 * # of points for FFT
>>#define PI 3.14159265358979 // PI = 3.14 = 22/7
>>#include "dsk6713_aic23.h" // codec-DSK support file
>>Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; // Set sampling rate
>>#define LEFT 0
>>#define RIGHT 1
>>union {Uint32 combo; short channel[2];} AIC23_input;
>>
>>union {Uint32 combo; short channel[2];} AIC23_output;
>>
>>float iobuffer_left[N], iobuffer_right[N]; // input output buffer
>>float samples_left[O], samples_right[O]; // primary working buffer
>>short buffercount = 0;
>>short flag=0;
>>short i=0; // general purpose index variable
>>short j=0; // general purpose even index variable
>>short k=0; // general purpose odd index variable
>>
>>float function1_left[O], function1_right[O]; // multipurpose variable for any function no.1 : just copy the value of
>> variable
>>main()
>>{
>>comm_poll(); // init DSK, codec, McBSP
>>
>>while(1)
>>{
>> while(flag == 0)
>> {
>> AIC23_output.channel[LEFT]=iobuffer_left[buffercount];
>> AIC23_output.channel[RIGHT]=iobuffer_right[buffercount];
>> output_sample(AIC23_output.combo); //out from iobuffer
>>
>> AIC23_input.combo = input_sample();
>> iobuffer_left[buffercount]=(float)(AIC23_input.channel[LEFT]);
>> iobuffer_right[buffercount]=(float)(AIC23_input.channel[RIGHT]);
>> buffercount++;
>>
>> if(buffercount > = N)
>> {
>> buffercount = 0;
>> flag = 1;
>> }
>>
>> for (i=0; i
>
>
> _____________________________________
>
_____________________________________
> Cristophe is right, I had bug on my program. I mistakenly put
> one '}' in the bottom of the code so I included
> unnecessary loop in every iteration, that is why the result
> was distorted. I have fixed it and now I am ready to
> insert FFT and IFFT block inside my program.
The " <--- HERE " changes in my previous post implement Cristophe's fix. But after the fix, you will have to keep
your FFT execution time under 125 usec due to polling constraints, otherwise it still won't work. I don't know what
max FFT size can complete under 125 usec on C6713, but it won't be very big, maybe 32-pt or so. And the actual
polling interval limit may need to be less, for example 60 usec, due to the time it takes for the McBSP to shift out a
sample.
When you reach the point of needing interrupt based operation, let us know.
-Jeff
> Hello everyone,
>>
>>I am Marko Kanadi from Mitsuhashi laboratory, UEC, Japan
>>
>>Currently I am working on signals separation and aim to
>> implement the algorithm on the C6713 DSK. However since it
>> deals with stereo signals thus I need to store the sample
>> signals of each channel into two separate buffer (before
>> it's further processed in FFT block). Moreover, I need to
>> use at least 512 point buffer for each channel according to
>> a constraint in the algorithm. BUT, if I use 512 point buffer
>> for each channel, the output signals are distorted.
>> However the distortion is less when I use smaller buffer. Is
>> this because I wrote an inefficient code or is this a
>> limitation of C6713 DSP machine? I really hope someone can
>> help me on this problem.
>>
>>Thank you very much for your concern.
>>
>>Below written my codes:
>>
>>//----------------------------------
>>// FFTiFFT.c : Source code for real-time FFT continued by iFFT
>>// Aim : Obtain the same result as input even after domain transformation
>>// Coder : Marko Kanadi
>>// Starting Date : November 7th, 2009
>>// Laboratory : Mitsuhashi Laboratory, University of Electro-Communications, Japan
>>//-----------------------------------
>>
>>#include // Contains codes of mathematical functions
>>#include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_cfftr2_dit.h" //DSP67x library for FFT
>>#include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_icfftr2_dif.h" //DSP67x library for IFFT
>>#define N 2 // # of points for FFT
>>#define O 4 // 2 * # of points for FFT
>>#define PI 3.14159265358979 // PI = 3.14 = 22/7
>>#include "dsk6713_aic23.h" // codec-DSK support file
>>Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; // Set sampling rate
>>#define LEFT 0
>>#define RIGHT 1
>>union {Uint32 combo; short channel[2];} AIC23_input;
>>
>>union {Uint32 combo; short channel[2];} AIC23_output;
>>
>>float iobuffer_left[N], iobuffer_right[N]; // input output buffer
>>float samples_left[O], samples_right[O]; // primary working buffer
>>short buffercount = 0;
>>short flag=0;
>>short i=0; // general purpose index variable
>>short j=0; // general purpose even index variable
>>short k=0; // general purpose odd index variable
>>
>>float function1_left[O], function1_right[O]; // multipurpose variable for any function no.1 : just copy the value of
>> variable
>>main()
>>{
>>comm_poll(); // init DSK, codec, McBSP
>>
>>while(1)
>>{
>> while(flag == 0)
>> {
>> AIC23_output.channel[LEFT]=iobuffer_left[buffercount];
>> AIC23_output.channel[RIGHT]=iobuffer_right[buffercount];
>> output_sample(AIC23_output.combo); //out from iobuffer
>>
>> AIC23_input.combo = input_sample();
>> iobuffer_left[buffercount]=(float)(AIC23_input.channel[LEFT]);
>> iobuffer_right[buffercount]=(float)(AIC23_input.channel[RIGHT]);
>> buffercount++;
>>
>> if(buffercount > = N)
>> {
>> buffercount = 0;
>> flag = 1;
>> }
>>
>> for (i=0; i
>
>
> _____________________________________
>
_____________________________________
Reply by ●November 9, 20092009-11-09
Marko,
I cannot say much about the actual algorithm,
However, the contents of function1_left and function1_right
are being used before the contents are set.
The actual contents are either from prior data and/or total garbage.
R. Williams
---------- Original Message -----------
From: m...@yahoo.com
To: c...
Sent: Sun, 08 Nov 2009 19:45:09 -0500
Subject: [c6x] distorted output on 512 point stereo buffer
>
>
> Hello everyone,
>
> I am Marko Kanadi from Mitsuhashi laboratory, UEC, Japan
>
> Currently I am working on signals separation and aim to implement the algorithm on the C6713 DSK. However since it deals with stereo signals thus I need to store the sample signals of each channel into two separate buffer (before it's further processed in FFT block). Moreover, I need to use at least 512 point buffer for each channel according to a constraint in the algorithm. BUT, if I use 512 point buffer for each channel, the output signals are distorted. However the distortion is less when I use smaller buffer. Is this because I wrote an inefficient code or is this a limitation of C6713 DSP machine? I really hope someone can help me on this problem.
>
> Thank you very much for your concern.
>
> Below written my codes:
>
> //----------------------
> // FFTiFFT.c : Source code for real-time FFT continued by iFFT
> // Aim : Obtain the same result as input even after domain transformation
> // Coder : Marko Kanadi
> // Starting Date : November 7th, 2009
> // Laboratory : Mitsuhashi Laboratory, University of Electro-Communications, Japan
> //----------------------
>
> #include // Contains codes of mathematical functions
> #include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_cfftr2_dit.h" //DSP67x library for FFT
> #include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_icfftr2_dif.h" //DSP67x library for IFFT
> #define N 2 // # of points for FFT
> #define O 4 // 2 * # of points for FFT
> #define PI 3.14159265358979 // PI = 3.14 = 22/7
> #include "dsk6713_aic23.h" // codec-DSK support file
> Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; // Set sampling rate
> #define LEFT 0
> #define RIGHT 1
> union {Uint32 combo; short channel[2];} AIC23_input;
>
> union {Uint32 combo; short channel[2];} AIC23_output;
>
> float iobuffer_left[N], iobuffer_right[N]; // input output buffer
> float samples_left[O], samples_right[O]; // primary working buffer
> short buffercount = 0;
> short flag=0;
> short i=0; // general purpose index variable
> short j=0; // general purpose even index variable
> short k=0; // general purpose odd index variable
>
> float function1_left[O], function1_right[O]; // multipurpose variable for any function no.1 : just copy the value of variable
> main()
> {
> comm_poll(); // init DSK, codec, McBSP
>
> while(1)
> {
> while(flag == 0)
> {
> AIC23_output.channel[LEFT]=iobuffer_left[buffercount];
> AIC23_output.channel[RIGHT]=iobuffer_right[buffercount];
> output_sample(AIC23_output.combo); //out from iobuffer
>
> AIC23_input.combo = input_sample();
> iobuffer_left[buffercount]=(float)(AIC23_input.channel[LEFT]);
> iobuffer_right[buffercount]=(float)(AIC23_input.channel[RIGHT]);
> buffercount++;
>
> if(buffercount >= N)
> {
> buffercount = 0;
> flag = 1;
> }
>
> for (i=0; i > {
> j=2*i;
> k=(2*i)+1;
>
> samples_left[j]=iobuffer_left[i]; // fill primary working buffer with new data
> samples_right[j]=iobuffer_right[i];
> samples_left[k]=0.0; // fill the imaginary part with 0.0
> samples_right[k]=0.0;
>
> iobuffer_left[i]=function1_left[j]; // fill buffer with result of function1
> iobuffer_right[i]=function1_right[j];
>
> function1_left[j]=samples_left[j];
> function1_left[k]=samples_left[k];
> function1_right[j]=samples_right[j];
> function1_right[k]=samples_right[k];
> }
>
> flag=0;
> }
>
> }
>
> }
------- End of Original Message -------
I cannot say much about the actual algorithm,
However, the contents of function1_left and function1_right
are being used before the contents are set.
The actual contents are either from prior data and/or total garbage.
R. Williams
---------- Original Message -----------
From: m...@yahoo.com
To: c...
Sent: Sun, 08 Nov 2009 19:45:09 -0500
Subject: [c6x] distorted output on 512 point stereo buffer
>
>
> Hello everyone,
>
> I am Marko Kanadi from Mitsuhashi laboratory, UEC, Japan
>
> Currently I am working on signals separation and aim to implement the algorithm on the C6713 DSK. However since it deals with stereo signals thus I need to store the sample signals of each channel into two separate buffer (before it's further processed in FFT block). Moreover, I need to use at least 512 point buffer for each channel according to a constraint in the algorithm. BUT, if I use 512 point buffer for each channel, the output signals are distorted. However the distortion is less when I use smaller buffer. Is this because I wrote an inefficient code or is this a limitation of C6713 DSP machine? I really hope someone can help me on this problem.
>
> Thank you very much for your concern.
>
> Below written my codes:
>
> //----------------------
> // FFTiFFT.c : Source code for real-time FFT continued by iFFT
> // Aim : Obtain the same result as input even after domain transformation
> // Coder : Marko Kanadi
> // Starting Date : November 7th, 2009
> // Laboratory : Mitsuhashi Laboratory, University of Electro-Communications, Japan
> //----------------------
>
> #include // Contains codes of mathematical functions
> #include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_cfftr2_dit.h" //DSP67x library for FFT
> #include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_icfftr2_dif.h" //DSP67x library for IFFT
> #define N 2 // # of points for FFT
> #define O 4 // 2 * # of points for FFT
> #define PI 3.14159265358979 // PI = 3.14 = 22/7
> #include "dsk6713_aic23.h" // codec-DSK support file
> Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; // Set sampling rate
> #define LEFT 0
> #define RIGHT 1
> union {Uint32 combo; short channel[2];} AIC23_input;
>
> union {Uint32 combo; short channel[2];} AIC23_output;
>
> float iobuffer_left[N], iobuffer_right[N]; // input output buffer
> float samples_left[O], samples_right[O]; // primary working buffer
> short buffercount = 0;
> short flag=0;
> short i=0; // general purpose index variable
> short j=0; // general purpose even index variable
> short k=0; // general purpose odd index variable
>
> float function1_left[O], function1_right[O]; // multipurpose variable for any function no.1 : just copy the value of variable
> main()
> {
> comm_poll(); // init DSK, codec, McBSP
>
> while(1)
> {
> while(flag == 0)
> {
> AIC23_output.channel[LEFT]=iobuffer_left[buffercount];
> AIC23_output.channel[RIGHT]=iobuffer_right[buffercount];
> output_sample(AIC23_output.combo); //out from iobuffer
>
> AIC23_input.combo = input_sample();
> iobuffer_left[buffercount]=(float)(AIC23_input.channel[LEFT]);
> iobuffer_right[buffercount]=(float)(AIC23_input.channel[RIGHT]);
> buffercount++;
>
> if(buffercount >= N)
> {
> buffercount = 0;
> flag = 1;
> }
>
> for (i=0; i > {
> j=2*i;
> k=(2*i)+1;
>
> samples_left[j]=iobuffer_left[i]; // fill primary working buffer with new data
> samples_right[j]=iobuffer_right[i];
> samples_left[k]=0.0; // fill the imaginary part with 0.0
> samples_right[k]=0.0;
>
> iobuffer_left[i]=function1_left[j]; // fill buffer with result of function1
> iobuffer_right[i]=function1_right[j];
>
> function1_left[j]=samples_left[j];
> function1_left[k]=samples_left[k];
> function1_right[j]=samples_right[j];
> function1_right[k]=samples_right[k];
> }
>
> flag=0;
> }
>
> }
>
> }
------- End of Original Message -------
Reply by ●November 10, 20092009-11-10
Jeff, Cristophe and Williams,
Thank you a lot Jeff for your detail explanations. I have done as what you suggested me to do and now it works. However, now I am trying to insert FFT and IFFT blocks inside the system. I used the DSP c67x library provided by TI and have found another problem.
What I did is I included the c67x library and inserted some codes of the FFT and IFFT functions, such as:
- DSPF_sp_cfftr2_dit
- DSPF_sp_icfftr2_dif
_ DSPF_sp_bitrev_cplx
as suggested in the "DSPF_sp_icfftr2_dif.h" file of the library. However now my program is written as below, and I have successfully built it yet now the result is harshly distorted no matter how big the size of the buffer is.
// FFTiFFT.c : Source code for real-time FFT continued by iFFT
// Aim : Obtain the same result as input even after domain transformation
// Coder : Marko Kanadi
// Starting Date : November 7th, 2009
// Laboratory : Mitsuhashi Laboratory, University of Electro-Communications, Japan
#include // Contains codes of mathematical functions
#include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_cfftr2_dit.h" //DSP67x library for FFT
#include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_icfftr2_dif.h" //DSP67x library for IFFT
#include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_bitrev_cplx.h"
#define N 512 // # of points for FFT
#define O 1024 // 2 * # of points for FFT
#define PI 3.14159265358979 // PI = 3.14 = 22/7
#include "dsk6713_aic23.h" // codec-DSK support file
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; // Set sampling rate
#define LEFT 0
#define RIGHT 1
union {Uint32 combo; short channel[2];} AIC23_input;
union {Uint32 combo; short channel[2];} AIC23_output;
float iobuffer_left[N], iobuffer_right[N]; // input output buffer
float samples_left[O], samples_right[O]; // primary working buffer
short buffercount = 0;
short flag=0;
short i=0; // general purpose index variable
short j=0; // general purpose even index variable
short k=0; // general purpose odd index variable
float function1_left[O], function1_right[O]; // multipurpose variable for any function no.1 : just copy the value of variable
float w[N];
void tw_genr2fft(float* w, int n);
void bit_rev(float* x, int n);
void divide(float* x, int n);
void DSPF_sp_cfftr2_dit(float* x, float* w, int n);
void DSPF_sp_icfftr2_dif(
float* x,
float* w,
short n
);
main()
{
tw_genr2fft(w,N); // generate twiddle constant
bit_rev(w,N>>1); //
comm_poll(); // init DSK, codec, McBSP
while(1)
{
while(flag == 0)
{
AIC23_output.channel[LEFT]=iobuffer_left[buffercount];
AIC23_output.channel[RIGHT]=iobuffer_right[buffercount];
output_sample(AIC23_output.combo); //out from iobuffer
AIC23_input.combo = input_sample();
iobuffer_left[buffercount]=(float)(AIC23_input.channel[LEFT]);
iobuffer_right[buffercount]=(float)(AIC23_input.channel[RIGHT]);
buffercount++;
if(buffercount >= N)
{
buffercount = 0;
flag = 1;
}
}
for (i=0; i
{
j=2*i;
k=(2*i)+1;
samples_left[j]=iobuffer_left[i]; // fill primary working buffer with new data
samples_right[j]=iobuffer_right[i];
samples_left[k]=0.0; // fill the imaginary part with 0.0
samples_right[k]=0.0;
iobuffer_left[i]=function1_left[j]; // fill buffer with result of function1
iobuffer_right[i]=function1_right[j];
}
DSPF_sp_cfftr2_dit(samples_left, w, N); // FFT on channel left
DSPF_sp_cfftr2_dit(samples_right, w, N); // FFT on right channel
DSPF_sp_icfftr2_dif(samples_left, w, N); // IFFT on left channel
DSPF_sp_icfftr2_dif(samples_right, w, N); // IFFT on right channel
//divide(samples_left, N); // Divide result of left channel IFFT by N
//divide(samples_right,N); // Divide result of right channel IFFT by N
//function 1 : only copy, just for testing buffer
for (i=0; i
{
function1_left[i]=samples_left[i];
function1_right[i]=samples_right[i];
}
flag=0;
}
}
void divide(float* x, int n)
{
int i;
float inv = 1.0/n;
for(i=0;i
{
x[2*i]=inv*x[2*i];
x[2*i+1]=inv*x[2*i+1];
}
}
Jeff, I read some previous posts about ping pong buffer for FFT implementation yet there was no satisfying explanation regarding to it. Furthermore, what's wrong with the poll and what makes interrupt is better than poll. I am sorry if I ask some basic questions. I have experienced only using C6713 for implementing time-based on-line algorithms hence I haven't understood issues regarding to those matters.
Thank you for your helps and concerns.
_____________________________________
Thank you a lot Jeff for your detail explanations. I have done as what you suggested me to do and now it works. However, now I am trying to insert FFT and IFFT blocks inside the system. I used the DSP c67x library provided by TI and have found another problem.
What I did is I included the c67x library and inserted some codes of the FFT and IFFT functions, such as:
- DSPF_sp_cfftr2_dit
- DSPF_sp_icfftr2_dif
_ DSPF_sp_bitrev_cplx
as suggested in the "DSPF_sp_icfftr2_dif.h" file of the library. However now my program is written as below, and I have successfully built it yet now the result is harshly distorted no matter how big the size of the buffer is.
// FFTiFFT.c : Source code for real-time FFT continued by iFFT
// Aim : Obtain the same result as input even after domain transformation
// Coder : Marko Kanadi
// Starting Date : November 7th, 2009
// Laboratory : Mitsuhashi Laboratory, University of Electro-Communications, Japan
#include // Contains codes of mathematical functions
#include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_cfftr2_dit.h" //DSP67x library for FFT
#include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_icfftr2_dif.h" //DSP67x library for IFFT
#include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_bitrev_cplx.h"
#define N 512 // # of points for FFT
#define O 1024 // 2 * # of points for FFT
#define PI 3.14159265358979 // PI = 3.14 = 22/7
#include "dsk6713_aic23.h" // codec-DSK support file
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; // Set sampling rate
#define LEFT 0
#define RIGHT 1
union {Uint32 combo; short channel[2];} AIC23_input;
union {Uint32 combo; short channel[2];} AIC23_output;
float iobuffer_left[N], iobuffer_right[N]; // input output buffer
float samples_left[O], samples_right[O]; // primary working buffer
short buffercount = 0;
short flag=0;
short i=0; // general purpose index variable
short j=0; // general purpose even index variable
short k=0; // general purpose odd index variable
float function1_left[O], function1_right[O]; // multipurpose variable for any function no.1 : just copy the value of variable
float w[N];
void tw_genr2fft(float* w, int n);
void bit_rev(float* x, int n);
void divide(float* x, int n);
void DSPF_sp_cfftr2_dit(float* x, float* w, int n);
void DSPF_sp_icfftr2_dif(
float* x,
float* w,
short n
);
main()
{
tw_genr2fft(w,N); // generate twiddle constant
bit_rev(w,N>>1); //
comm_poll(); // init DSK, codec, McBSP
while(1)
{
while(flag == 0)
{
AIC23_output.channel[LEFT]=iobuffer_left[buffercount];
AIC23_output.channel[RIGHT]=iobuffer_right[buffercount];
output_sample(AIC23_output.combo); //out from iobuffer
AIC23_input.combo = input_sample();
iobuffer_left[buffercount]=(float)(AIC23_input.channel[LEFT]);
iobuffer_right[buffercount]=(float)(AIC23_input.channel[RIGHT]);
buffercount++;
if(buffercount >= N)
{
buffercount = 0;
flag = 1;
}
}
for (i=0; i
{
j=2*i;
k=(2*i)+1;
samples_left[j]=iobuffer_left[i]; // fill primary working buffer with new data
samples_right[j]=iobuffer_right[i];
samples_left[k]=0.0; // fill the imaginary part with 0.0
samples_right[k]=0.0;
iobuffer_left[i]=function1_left[j]; // fill buffer with result of function1
iobuffer_right[i]=function1_right[j];
}
DSPF_sp_cfftr2_dit(samples_left, w, N); // FFT on channel left
DSPF_sp_cfftr2_dit(samples_right, w, N); // FFT on right channel
DSPF_sp_icfftr2_dif(samples_left, w, N); // IFFT on left channel
DSPF_sp_icfftr2_dif(samples_right, w, N); // IFFT on right channel
//divide(samples_left, N); // Divide result of left channel IFFT by N
//divide(samples_right,N); // Divide result of right channel IFFT by N
//function 1 : only copy, just for testing buffer
for (i=0; i
{
function1_left[i]=samples_left[i];
function1_right[i]=samples_right[i];
}
flag=0;
}
}
void divide(float* x, int n)
{
int i;
float inv = 1.0/n;
for(i=0;i
{
x[2*i]=inv*x[2*i];
x[2*i+1]=inv*x[2*i+1];
}
}
Jeff, I read some previous posts about ping pong buffer for FFT implementation yet there was no satisfying explanation regarding to it. Furthermore, what's wrong with the poll and what makes interrupt is better than poll. I am sorry if I ask some basic questions. I have experienced only using C6713 for implementing time-based on-line algorithms hence I haven't understood issues regarding to those matters.
Thank you for your helps and concerns.
_____________________________________
Reply by ●November 10, 20092009-11-10
marko,
the first thing that caught my eye...
The pointer to float variable 'w' must actually point to an existing array, where that array will eventually contain the 'twiddle' factors.
The code does not point 'w' to such an array.
There are probably other similar details, however; this should get you started in the right direction.
BTW:
interrupts need to be used rather than polling because of several reasons including the polling burns CPU cycles that are needed to run the FFT and IFFT transforms
While the actual inputting and outputting of data can be setup then triggered by a EDMA or similar.
The use of 'ping-pong' double buffering of both the input and output data has the following benefits.
(taking the input of data as an example)
Input I/O can be going on in one input buffer instance while the other input buffer instance is being read/processed by the software processing.
(taking the output of data as an example)
Output I/O can be going on in one output buffer instance while the other output buffer instance is being written to by the software processing.
In general, this means the inclusion and usage of variables similar to the following:
// two input buffer instances
InputBuffer[512,2]
// two output buffer instances
OutputBuffer[512,2]
// index/selector for input buffer instances
ActiveInputBufferNum
// index/selector for output buffer instances
ActiveOutputBufferNum
By using the ping-pong (double buffering) technique, approximately twice the data flow rate can be achieved, without losing any data.
This is very important, since data is continually coming in/going out and that data needs to be processed (by FFT and IFFT).
FFT and IFFT are very slow processing due to the huge number of add/multiply/store operations involved.
With some care, if the FFT and IFFT are setup to update the data 'in-place', then a single set of double buffers could be used (thereby eliminating any data copying)
However, *I* would start with the simplier algorithm and get it working before trying to save any RAM space.
I would try to locate all the buffers in L2 space, rather than external RAM to save all those wait states (and thereby greatly speed up the overall processing/data through put.
R. Williams
---------- Original Message -----------
From: m...@yahoo.com
To: c...
Sent: Tue, 10 Nov 2009 03:21:46 -0500
Subject: [c6x] Re: distorted output on 512 point stereo buffer
>
>
> Jeff, Cristophe and Williams,
>
> Thank you a lot Jeff for your detail explanations. I have done as what you suggested me to do and now it works. However, now I am trying to insert FFT and IFFT blocks inside the system. I used the DSP c67x library provided by TI and have found another problem.
>
> What I did is I included the c67x library and inserted some codes of the FFT and IFFT functions, such as:
> - DSPF_sp_cfftr2_dit
> - DSPF_sp_icfftr2_dif
> _ DSPF_sp_bitrev_cplx
> as suggested in the "DSPF_sp_icfftr2_dif.h" file of the library. However now my program is written as below, and I have successfully built it yet now the result is harshly distorted no matter how big the size of the buffer is.
>
> // FFTiFFT.c : Source code for real-time FFT continued by iFFT
>
> // Aim : Obtain the same result as input even after domain transformation
>
> // Coder : Marko Kanadi
>
> // Starting Date : November 7th, 2009
>
> // Laboratory : Mitsuhashi Laboratory, University of Electro-Communications, Japan
>
> #include // Contains codes of mathematical functions
>
> #include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_cfftr2_dit.h" //DSP67x library for FFT
>
> #include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_icfftr2_dif.h" //DSP67x library for IFFT
>
> #include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_bitrev_cplx.h"
>
> #define N 512 // # of points for FFT
>
> #define O 1024 // 2 * # of points for FFT
>
> #define PI 3.14159265358979 // PI = 3.14 = 22/7
>
> #include "dsk6713_aic23.h" // codec-DSK support file
>
> Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; // Set sampling rate
>
> #define LEFT 0
>
> #define RIGHT 1
>
> union {Uint32 combo; short channel[2];} AIC23_input;
>
> union {Uint32 combo; short channel[2];} AIC23_output;
>
> float iobuffer_left[N], iobuffer_right[N]; // input output buffer
>
> float samples_left[O], samples_right[O]; // primary working buffer
>
> short buffercount = 0;
>
> short flag=0;
>
> short i=0; // general purpose index variable
>
> short j=0; // general purpose even index variable
>
> short k=0; // general purpose odd index variable
>
> float function1_left[O], function1_right[O]; // multipurpose variable for any function no.1 : just copy the value of variable
>
> float w[N];
>
> void tw_genr2fft(float* w, int n);
>
> void bit_rev(float* x, int n);
>
> void divide(float* x, int n);
>
> void DSPF_sp_cfftr2_dit(float* x, float* w, int n);
>
> void DSPF_sp_icfftr2_dif(
>
> float* x,
>
> float* w,
>
> short n
>
> );
>
> main()
>
> {
>
> tw_genr2fft(w,N); // generate twiddle constant
>
> bit_rev(w,N>>1); //
>
> comm_poll(); // init DSK, codec, McBSP
>
> while(1)
>
> {
>
> while(flag == 0)
>
> {
>
> AIC23_output.channel[LEFT]=iobuffer_left[buffercount];
>
> AIC23_output.channel[RIGHT]=iobuffer_right[buffercount];
>
> output_sample(AIC23_output.combo); //out from iobuffer
>
> AIC23_input.combo = input_sample();
>
> iobuffer_left[buffercount]=(float)(AIC23_input.channel[LEFT]);
>
> iobuffer_right[buffercount]=(float)(AIC23_input.channel[RIGHT]);
>
> buffercount++;
>
> if(buffercount >= N)
>
> {
>
> buffercount = 0;
>
> flag = 1;
>
> }
>
> }
>
> for (i=0; i >
> {
>
> j=2*i;
>
> k=(2*i)+1;
>
> samples_left[j]=iobuffer_left[i]; // fill primary working buffer with new data
>
> samples_right[j]=iobuffer_right[i];
>
> samples_left[k]=0.0; // fill the imaginary part with 0.0
>
> samples_right[k]=0.0;
>
> iobuffer_left[i]=function1_left[j]; // fill buffer with result of function1
>
> iobuffer_right[i]=function1_right[j];
>
> }
>
> DSPF_sp_cfftr2_dit(samples_left, w, N); // FFT on channel left
>
> DSPF_sp_cfftr2_dit(samples_right, w, N); // FFT on right channel
>
> DSPF_sp_icfftr2_dif(samples_left, w, N); // IFFT on left channel
>
> DSPF_sp_icfftr2_dif(samples_right, w, N); // IFFT on right channel
>
> //divide(samples_left, N); // Divide result of left channel IFFT by N
>
> //divide(samples_right,N); // Divide result of right channel IFFT by N
>
> //function 1 : only copy, just for testing buffer
>
> for (i=0; i >
> {
>
> function1_left[i]=samples_left[i];
>
> function1_right[i]=samples_right[i];
>
> }
>
> flag=0;
>
> }
>
> }
>
> void divide(float* x, int n)
>
> {
>
> int i;
>
> float inv = 1.0/n;
>
> for(i=0;i >
> {
>
> x[2*i]=inv*x[2*i];
>
> x[2*i+1]=inv*x[2*i+1];
>
> }
>
> }
>
> Jeff, I read some previous posts about ping pong buffer for FFT implementation yet there was no satisfying explanation regarding to it. Furthermore, what's wrong with the poll and what makes interrupt is better than poll. I am sorry if I ask some basic questions. I have experienced only using C6713 for implementing time-based on-line algorithms hence I haven't understood issues regarding to those matters.
>
> Thank you for your helps and concerns.
the first thing that caught my eye...
The pointer to float variable 'w' must actually point to an existing array, where that array will eventually contain the 'twiddle' factors.
The code does not point 'w' to such an array.
There are probably other similar details, however; this should get you started in the right direction.
BTW:
interrupts need to be used rather than polling because of several reasons including the polling burns CPU cycles that are needed to run the FFT and IFFT transforms
While the actual inputting and outputting of data can be setup then triggered by a EDMA or similar.
The use of 'ping-pong' double buffering of both the input and output data has the following benefits.
(taking the input of data as an example)
Input I/O can be going on in one input buffer instance while the other input buffer instance is being read/processed by the software processing.
(taking the output of data as an example)
Output I/O can be going on in one output buffer instance while the other output buffer instance is being written to by the software processing.
In general, this means the inclusion and usage of variables similar to the following:
// two input buffer instances
InputBuffer[512,2]
// two output buffer instances
OutputBuffer[512,2]
// index/selector for input buffer instances
ActiveInputBufferNum
// index/selector for output buffer instances
ActiveOutputBufferNum
By using the ping-pong (double buffering) technique, approximately twice the data flow rate can be achieved, without losing any data.
This is very important, since data is continually coming in/going out and that data needs to be processed (by FFT and IFFT).
FFT and IFFT are very slow processing due to the huge number of add/multiply/store operations involved.
With some care, if the FFT and IFFT are setup to update the data 'in-place', then a single set of double buffers could be used (thereby eliminating any data copying)
However, *I* would start with the simplier algorithm and get it working before trying to save any RAM space.
I would try to locate all the buffers in L2 space, rather than external RAM to save all those wait states (and thereby greatly speed up the overall processing/data through put.
R. Williams
---------- Original Message -----------
From: m...@yahoo.com
To: c...
Sent: Tue, 10 Nov 2009 03:21:46 -0500
Subject: [c6x] Re: distorted output on 512 point stereo buffer
>
>
> Jeff, Cristophe and Williams,
>
> Thank you a lot Jeff for your detail explanations. I have done as what you suggested me to do and now it works. However, now I am trying to insert FFT and IFFT blocks inside the system. I used the DSP c67x library provided by TI and have found another problem.
>
> What I did is I included the c67x library and inserted some codes of the FFT and IFFT functions, such as:
> - DSPF_sp_cfftr2_dit
> - DSPF_sp_icfftr2_dif
> _ DSPF_sp_bitrev_cplx
> as suggested in the "DSPF_sp_icfftr2_dif.h" file of the library. However now my program is written as below, and I have successfully built it yet now the result is harshly distorted no matter how big the size of the buffer is.
>
> // FFTiFFT.c : Source code for real-time FFT continued by iFFT
>
> // Aim : Obtain the same result as input even after domain transformation
>
> // Coder : Marko Kanadi
>
> // Starting Date : November 7th, 2009
>
> // Laboratory : Mitsuhashi Laboratory, University of Electro-Communications, Japan
>
> #include // Contains codes of mathematical functions
>
> #include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_cfftr2_dit.h" //DSP67x library for FFT
>
> #include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_icfftr2_dif.h" //DSP67x library for IFFT
>
> #include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_bitrev_cplx.h"
>
> #define N 512 // # of points for FFT
>
> #define O 1024 // 2 * # of points for FFT
>
> #define PI 3.14159265358979 // PI = 3.14 = 22/7
>
> #include "dsk6713_aic23.h" // codec-DSK support file
>
> Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; // Set sampling rate
>
> #define LEFT 0
>
> #define RIGHT 1
>
> union {Uint32 combo; short channel[2];} AIC23_input;
>
> union {Uint32 combo; short channel[2];} AIC23_output;
>
> float iobuffer_left[N], iobuffer_right[N]; // input output buffer
>
> float samples_left[O], samples_right[O]; // primary working buffer
>
> short buffercount = 0;
>
> short flag=0;
>
> short i=0; // general purpose index variable
>
> short j=0; // general purpose even index variable
>
> short k=0; // general purpose odd index variable
>
> float function1_left[O], function1_right[O]; // multipurpose variable for any function no.1 : just copy the value of variable
>
> float w[N];
>
> void tw_genr2fft(float* w, int n);
>
> void bit_rev(float* x, int n);
>
> void divide(float* x, int n);
>
> void DSPF_sp_cfftr2_dit(float* x, float* w, int n);
>
> void DSPF_sp_icfftr2_dif(
>
> float* x,
>
> float* w,
>
> short n
>
> );
>
> main()
>
> {
>
> tw_genr2fft(w,N); // generate twiddle constant
>
> bit_rev(w,N>>1); //
>
> comm_poll(); // init DSK, codec, McBSP
>
> while(1)
>
> {
>
> while(flag == 0)
>
> {
>
> AIC23_output.channel[LEFT]=iobuffer_left[buffercount];
>
> AIC23_output.channel[RIGHT]=iobuffer_right[buffercount];
>
> output_sample(AIC23_output.combo); //out from iobuffer
>
> AIC23_input.combo = input_sample();
>
> iobuffer_left[buffercount]=(float)(AIC23_input.channel[LEFT]);
>
> iobuffer_right[buffercount]=(float)(AIC23_input.channel[RIGHT]);
>
> buffercount++;
>
> if(buffercount >= N)
>
> {
>
> buffercount = 0;
>
> flag = 1;
>
> }
>
> }
>
> for (i=0; i >
> {
>
> j=2*i;
>
> k=(2*i)+1;
>
> samples_left[j]=iobuffer_left[i]; // fill primary working buffer with new data
>
> samples_right[j]=iobuffer_right[i];
>
> samples_left[k]=0.0; // fill the imaginary part with 0.0
>
> samples_right[k]=0.0;
>
> iobuffer_left[i]=function1_left[j]; // fill buffer with result of function1
>
> iobuffer_right[i]=function1_right[j];
>
> }
>
> DSPF_sp_cfftr2_dit(samples_left, w, N); // FFT on channel left
>
> DSPF_sp_cfftr2_dit(samples_right, w, N); // FFT on right channel
>
> DSPF_sp_icfftr2_dif(samples_left, w, N); // IFFT on left channel
>
> DSPF_sp_icfftr2_dif(samples_right, w, N); // IFFT on right channel
>
> //divide(samples_left, N); // Divide result of left channel IFFT by N
>
> //divide(samples_right,N); // Divide result of right channel IFFT by N
>
> //function 1 : only copy, just for testing buffer
>
> for (i=0; i >
> {
>
> function1_left[i]=samples_left[i];
>
> function1_right[i]=samples_right[i];
>
> }
>
> flag=0;
>
> }
>
> }
>
> void divide(float* x, int n)
>
> {
>
> int i;
>
> float inv = 1.0/n;
>
> for(i=0;i >
> {
>
> x[2*i]=inv*x[2*i];
>
> x[2*i+1]=inv*x[2*i+1];
>
> }
>
> }
>
> Jeff, I read some previous posts about ping pong buffer for FFT implementation yet there was no satisfying explanation regarding to it. Furthermore, what's wrong with the poll and what makes interrupt is better than poll. I am sorry if I ask some basic questions. I have experienced only using C6713 for implementing time-based on-line algorithms hence I haven't understood issues regarding to those matters.
>
> Thank you for your helps and concerns.
Reply by ●November 10, 20092009-11-10
Marko-
> Thank you a lot Jeff for your detail explanations. I have
> done as what you suggested me to do and now it works.
> However, now I am trying to insert FFT and IFFT blocks
> inside the system. I used the DSP c67x library provided by
> TI and have found another problem.
>
> What I did is I included the c67x library and inserted
> some codes of the FFT and IFFT functions, such as:
> - DSPF_sp_cfftr2_dit
> - DSPF_sp_icfftr2_dif
> _ DSPF_sp_bitrev_cplx
> as suggested in the "DSPF_sp_icfftr2_dif.h" file of the
> library. However now my program is written as below, and
> I have successfully built it yet now the result is
> harshly distorted no matter how big the size of the
> buffer is.
To debug, I suggest this:
-point the FFT at "other" buffers,
i.e. not the ones you were using
for AIC23 I/O testing
-run again
The idea is to separate two (2) possible issues: a) whether you have a data buffer or pointer problem (as suggested
by Richard), or b) if just the act of calling the FFT takes too long (more than 60 o 125 usec).
-Jeff
>
> // FFTiFFT.c : Source code for real-time FFT continued by iFFT
>
> // Aim : Obtain the same result as input even after domain transformation
>
> // Coder : Marko Kanadi
>
> // Starting Date : November 7th, 2009
>
> // Laboratory : Mitsuhashi Laboratory, University of Electro-Communications, Japan
>
> #include // Contains codes of mathematical functions
>
> #include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_cfftr2_dit.h" //DSP67x library for FFT
>
> #include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_icfftr2_dif.h" //DSP67x library for IFFT
>
> #include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_bitrev_cplx.h"
>
> #define N 512 // # of points for FFT
>
> #define O 1024 // 2 * # of points for FFT
>
> #define PI 3.14159265358979 // PI = 3.14 = 22/7
>
> #include "dsk6713_aic23.h" // codec-DSK support file
>
> Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; // Set sampling rate
>
> #define LEFT 0
>
> #define RIGHT 1
>
> union {Uint32 combo; short channel[2];} AIC23_input;
>
> union {Uint32 combo; short channel[2];} AIC23_output;
>
> float iobuffer_left[N], iobuffer_right[N]; // input output buffer
>
> float samples_left[O], samples_right[O]; // primary working buffer
>
> short buffercount = 0;
>
> short flag=0;
>
> short i=0; // general purpose index variable
>
> short j=0; // general purpose even index variable
>
> short k=0; // general purpose odd index variable
>
> float function1_left[O], function1_right[O]; // multipurpose variable for any function no.1 : just copy the value of
> variable
>
> float w[N];
>
> void tw_genr2fft(float* w, int n);
>
> void bit_rev(float* x, int n);
>
> void divide(float* x, int n);
>
> void DSPF_sp_cfftr2_dit(float* x, float* w, int n);
>
> void DSPF_sp_icfftr2_dif(
>
> float* x,
>
> float* w,
>
> short n
>
> );
>
> main()
>
> {
>
> tw_genr2fft(w,N); // generate twiddle constant
>
> bit_rev(w,N>>1); //
>
> comm_poll(); // init DSK, codec, McBSP
>
> while(1)
>
> {
>
> while(flag == 0)
>
> {
>
> AIC23_output.channel[LEFT]=iobuffer_left[buffercount];
>
> AIC23_output.channel[RIGHT]=iobuffer_right[buffercount];
>
> output_sample(AIC23_output.combo); //out from iobuffer
>
> AIC23_input.combo = input_sample();
>
> iobuffer_left[buffercount]=(float)(AIC23_input.channel[LEFT]);
>
> iobuffer_right[buffercount]=(float)(AIC23_input.channel[RIGHT]);
>
> buffercount++;
>
> if(buffercount >= N)
>
> {
>
> buffercount = 0;
>
> flag = 1;
>
> }
>
> }
>
> for (i=0; i >
> {
>
> j=2*i;
>
> k=(2*i)+1;
>
> samples_left[j]=iobuffer_left[i]; // fill primary working buffer with new data
>
> samples_right[j]=iobuffer_right[i];
>
> samples_left[k]=0.0; // fill the imaginary part with 0.0
>
> samples_right[k]=0.0;
>
> iobuffer_left[i]=function1_left[j]; // fill buffer with result of function1
>
> iobuffer_right[i]=function1_right[j];
>
> }
>
> DSPF_sp_cfftr2_dit(samples_left, w, N); // FFT on channel left
>
> DSPF_sp_cfftr2_dit(samples_right, w, N); // FFT on right channel
>
> DSPF_sp_icfftr2_dif(samples_left, w, N); // IFFT on left channel
>
> DSPF_sp_icfftr2_dif(samples_right, w, N); // IFFT on right channel
>
> //divide(samples_left, N); // Divide result of left channel IFFT by N
>
> //divide(samples_right,N); // Divide result of right channel IFFT by N
>
> //function 1 : only copy, just for testing buffer
>
> for (i=0; i >
> {
>
> function1_left[i]=samples_left[i];
>
> function1_right[i]=samples_right[i];
>
> }
>
> flag=0;
>
> }
>
> }
>
> void divide(float* x, int n)
>
> {
>
> int i;
>
> float inv = 1.0/n;
>
> for(i=0;i >
> {
>
> x[2*i]=inv*x[2*i];
>
> x[2*i+1]=inv*x[2*i+1];
>
> }
>
> }
>
> Jeff, I read some previous posts about ping pong buffer for FFT implementation yet there was no satisfying explanation
> regarding to it. Furthermore, what's wrong with the poll and what makes interrupt is better than poll. I am sorry if I
> ask some basic questions. I have experienced only using C6713 for implementing time-based on-line algorithms hence I
> haven't understood issues regarding to those matters.
>
> Thank you for your helps and concerns.
_____________________________________
> Thank you a lot Jeff for your detail explanations. I have
> done as what you suggested me to do and now it works.
> However, now I am trying to insert FFT and IFFT blocks
> inside the system. I used the DSP c67x library provided by
> TI and have found another problem.
>
> What I did is I included the c67x library and inserted
> some codes of the FFT and IFFT functions, such as:
> - DSPF_sp_cfftr2_dit
> - DSPF_sp_icfftr2_dif
> _ DSPF_sp_bitrev_cplx
> as suggested in the "DSPF_sp_icfftr2_dif.h" file of the
> library. However now my program is written as below, and
> I have successfully built it yet now the result is
> harshly distorted no matter how big the size of the
> buffer is.
To debug, I suggest this:
-point the FFT at "other" buffers,
i.e. not the ones you were using
for AIC23 I/O testing
-run again
The idea is to separate two (2) possible issues: a) whether you have a data buffer or pointer problem (as suggested
by Richard), or b) if just the act of calling the FFT takes too long (more than 60 o 125 usec).
-Jeff
>
> // FFTiFFT.c : Source code for real-time FFT continued by iFFT
>
> // Aim : Obtain the same result as input even after domain transformation
>
> // Coder : Marko Kanadi
>
> // Starting Date : November 7th, 2009
>
> // Laboratory : Mitsuhashi Laboratory, University of Electro-Communications, Japan
>
> #include // Contains codes of mathematical functions
>
> #include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_cfftr2_dit.h" //DSP67x library for FFT
>
> #include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_icfftr2_dif.h" //DSP67x library for IFFT
>
> #include "C:/CCStudio_v3.1/c6700/dsplib/include/DSPF_sp_bitrev_cplx.h"
>
> #define N 512 // # of points for FFT
>
> #define O 1024 // 2 * # of points for FFT
>
> #define PI 3.14159265358979 // PI = 3.14 = 22/7
>
> #include "dsk6713_aic23.h" // codec-DSK support file
>
> Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; // Set sampling rate
>
> #define LEFT 0
>
> #define RIGHT 1
>
> union {Uint32 combo; short channel[2];} AIC23_input;
>
> union {Uint32 combo; short channel[2];} AIC23_output;
>
> float iobuffer_left[N], iobuffer_right[N]; // input output buffer
>
> float samples_left[O], samples_right[O]; // primary working buffer
>
> short buffercount = 0;
>
> short flag=0;
>
> short i=0; // general purpose index variable
>
> short j=0; // general purpose even index variable
>
> short k=0; // general purpose odd index variable
>
> float function1_left[O], function1_right[O]; // multipurpose variable for any function no.1 : just copy the value of
> variable
>
> float w[N];
>
> void tw_genr2fft(float* w, int n);
>
> void bit_rev(float* x, int n);
>
> void divide(float* x, int n);
>
> void DSPF_sp_cfftr2_dit(float* x, float* w, int n);
>
> void DSPF_sp_icfftr2_dif(
>
> float* x,
>
> float* w,
>
> short n
>
> );
>
> main()
>
> {
>
> tw_genr2fft(w,N); // generate twiddle constant
>
> bit_rev(w,N>>1); //
>
> comm_poll(); // init DSK, codec, McBSP
>
> while(1)
>
> {
>
> while(flag == 0)
>
> {
>
> AIC23_output.channel[LEFT]=iobuffer_left[buffercount];
>
> AIC23_output.channel[RIGHT]=iobuffer_right[buffercount];
>
> output_sample(AIC23_output.combo); //out from iobuffer
>
> AIC23_input.combo = input_sample();
>
> iobuffer_left[buffercount]=(float)(AIC23_input.channel[LEFT]);
>
> iobuffer_right[buffercount]=(float)(AIC23_input.channel[RIGHT]);
>
> buffercount++;
>
> if(buffercount >= N)
>
> {
>
> buffercount = 0;
>
> flag = 1;
>
> }
>
> }
>
> for (i=0; i >
> {
>
> j=2*i;
>
> k=(2*i)+1;
>
> samples_left[j]=iobuffer_left[i]; // fill primary working buffer with new data
>
> samples_right[j]=iobuffer_right[i];
>
> samples_left[k]=0.0; // fill the imaginary part with 0.0
>
> samples_right[k]=0.0;
>
> iobuffer_left[i]=function1_left[j]; // fill buffer with result of function1
>
> iobuffer_right[i]=function1_right[j];
>
> }
>
> DSPF_sp_cfftr2_dit(samples_left, w, N); // FFT on channel left
>
> DSPF_sp_cfftr2_dit(samples_right, w, N); // FFT on right channel
>
> DSPF_sp_icfftr2_dif(samples_left, w, N); // IFFT on left channel
>
> DSPF_sp_icfftr2_dif(samples_right, w, N); // IFFT on right channel
>
> //divide(samples_left, N); // Divide result of left channel IFFT by N
>
> //divide(samples_right,N); // Divide result of right channel IFFT by N
>
> //function 1 : only copy, just for testing buffer
>
> for (i=0; i >
> {
>
> function1_left[i]=samples_left[i];
>
> function1_right[i]=samples_right[i];
>
> }
>
> flag=0;
>
> }
>
> }
>
> void divide(float* x, int n)
>
> {
>
> int i;
>
> float inv = 1.0/n;
>
> for(i=0;i >
> {
>
> x[2*i]=inv*x[2*i];
>
> x[2*i+1]=inv*x[2*i+1];
>
> }
>
> }
>
> Jeff, I read some previous posts about ping pong buffer for FFT implementation yet there was no satisfying explanation
> regarding to it. Furthermore, what's wrong with the poll and what makes interrupt is better than poll. I am sorry if I
> ask some basic questions. I have experienced only using C6713 for implementing time-based on-line algorithms hence I
> haven't understood issues regarding to those matters.
>
> Thank you for your helps and concerns.
_____________________________________






