代码里已经给出来 fft后,在c5515的显示屏上出现了bargraph的图案,转到了频域。如何再调用dsplib里的rifft()和cbrev()转回时域,并且在显示屏上出来正弦波?``代码如下,如果我再写一个ifft的子函数,我是不是要新定义一个buffer 然后input是calculate_power 的buffer?
#include "stdio.h"
#include "usbstk5515.h"
#include "usbstk5515_led.h"
#include "aic3204.h"
#include "PLL.h"
#include "bargraph.h"
#include "oled.h"
#include "pushbuttons.h"
#include "stereo.h"
#include "dsplib.h"
Int16 left_input;
Int16 right_input;
Int16 left_output;
Int16 right_output;
Int16 mono_input;
#define SAMPLES_PER_SECOND 8000
/* Use 20 for guitar */
#define GAIN_IN_dB 0
unsigned long int i = 0;
unsigned int Step = 0;
unsigned int LastStep = 99;
int j = 0;
int k = 0;
int m = 0;
int display_counter = 0;
int waveform_counter;
long delay;
DATA input_buffer[1024]; /* Must be declared as DATA for dsplib compatibility */
DATA buffer2[1024];
int display_buffer[96];
int buffer1[96];
/*****************************************************************************/
/* calculate_power() /
/---------------------------------------------------------------------------*/
/* /
/ Parameter 1: Real term a. /
/ Parameter 2: Immaginary term jb. /
/ /
/ RETURNS: a*a + b*b. Result will always be positive. /
/ /
/****************************************************************************/
int calculate_power (int a, int b)
{
return ( (int) ( ( (long)a * a + (long) b * b) >> 14) );
}
/*****************************************************************************/
/* calculate_FFT() /
/---------------------------------------------------------------------------*/
/* /
/ Parameter 1: Latest audio input (real value). /
/ Parameter 2: size of FFT e.g. 128, 512 and 1024 elements. /
/ /
/ RETURNS: None. /
/ /
/****************************************************************************/
void calculate_FFT(int input, int size)
{
static int i = 0;
static int counter = 0;
buffer2[i] = input; /* Store as a real value /
i++;
buffer2[i] = 0; / Store with an imaginary value of 0 */
i++;
if ( i >= size-1)
{
i = 0;
/* Perform complex FFT using N real and N imaginary values */
cfft (&buffer2[0], size/2, SCALE);
cbrev(&buffer2[0], &buffer2[0], size/2);
for ( j = 0 ; j < 96 ; j ++)
{
display_buffer[j] = calculate_power((int) buffer2[2*j], (int)buffer2[2*j+1]);
}
counter++;
if ( counter >= 1)
{
/* Slow down the number of updates to make display easier to see */
counter = 0;
oled_display_bargraph( &display_buffer[0]);
}
}
}
/* ------------------------------------------------------------------------ *
------------------------------------------------------------------------ /
void main( void )
{
/ Initialize BSL */
USBSTK5515_init( );
/* Initialize PLL */
pll_frequency_setup(120);
/* Initialise hardware interface and I2C for code */
aic3204_hardware_init();
/* Initialise the AIC3204 codec */
aic3204_init();
/* Turn off the 4 coloured LEDs */
USBSTK5515_ULED_init();
/* Initialise the OLED LCD display /
oled_init();
SAR_init();
/ Flush display buffer */
oled_display_message(" ", " ");
printf("\n\nRunning Project Spectrum Analyser\n");
printf( "<-> Audio Loopback from Microphone In --> to Headphones/Lineout\n\n" );
/* Setup sampling frequency and 30dB gain for microphone */
set_sampling_frequency_and_gain(SAMPLES_PER_SECOND, GAIN_IN_dB);
oled_display_message("Application 20 ", "Spectrum Analyser ");
/* New. Add descriptive text */
puts("\n Bargraph at 6dB intervals");
puts("\n Press SW1 for DOWN, SW2 for UP, SW1 + SW2 for reset\n");
puts(" Step 1 = Straight through, no signal processing. Set levels");
puts(" Step 2 = Waveform view");
puts(" Step 3 = FFT 1024 Display. Calculate power and display as bargraph");
puts(" Step 4 = FFT 512 Display. Calculate power and display as bargraph");
/* Default to XF LED off */
asm(" bclr XF");
for ( i = 0 ; i < SAMPLES_PER_SECOND * 600L ;i++ )
{
aic3204_codec_read(&left_input, &right_input); // Configured for one interrupt per two channels.
mono_input = stereo_to_mono(left_input, right_input);
Step = pushbuttons_read(4);
if ( Step == 1 )
{
if ( Step != LastStep )
{
oled_display_message("STEP1 No Processing", "Set Levels ");
LastStep = Step;
}
left_output = left_input; // Straight trough. No processing.
right_output = right_input;
}
else if ( Step == 2)
{
if ( Step != LastStep)
{
oled_display_message("STEP2 ", " Waveform View");
LastStep = Step;
display_counter = 0;
waveform_counter = 0;
}
if ( display_counter < 8000)
{
display_counter++;
}
if (display_counter >= 8000)
{
buffer1[k] = mono_input;
k++;
if ( k >= 96)
{
k = 0;
waveform_counter++;
if ( waveform_counter >= 6)
{
waveform_counter = 0;
oled_display_waveform(&buffer1[0]);
delay = 0xFFFFFF;
while ( delay--)
{
/* Wait */
}
}
}
}
}
else if ( Step == 3)
{
if ( Step != LastStep)
{
oled_display_message("STEP3 ", " FFT 1024 Display");
LastStep = Step;
display_counter = 0;
}
if ( display_counter < 8000)
{
display_counter++;
}
if (display_counter >= 8000)
{
calculate_FFT(mono_input, 1024);
}
}
else if ( Step == 4)
{
if ( Step != LastStep)
{
oled_display_message("STEP4 ", " FFT 512 Display");
LastStep = Step;
display_counter = 0;
}
if ( display_counter < 8000)
{
display_counter++;
}
if (display_counter >= 8000)
{
calculate_FFT(mono_input, 512);
}
}
aic3204_codec_write(left_output, right_output);
if ( Step == 1)
{
/* Only display bargraph when setting up. Distracting otherwise */
bargraph_6dB(left_output, right_output);
}
}
/* Disable I2S and put codec into reset */
aic3204_disable();
printf( "\n***Program has Terminated***\n" );
oled_display_message("PROGRAM HAS ", "TERMINATED ");
SW_BREAKPOINT;
}
/* ------------------------------------------------------------------------ *