Pages: [1]   Go Down
Author Topic: IFFT - Is anybody use the library to do an IFFT ?  (Read 1821 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello everybody,

I've seen somo code about FFT using the FFT library, but I dodn't see any code using IFFT.

I want to do the following:

- Once I have the FFT array with my Bins, I want to do an IFFT of some Bins, for example I want to generate my analog signal of my bin 19,20 and 21 that could be the 1400-1500 hz (this is an example).

So does anyone could did this before? Does anyone has the code of how to use the library with IFFT ?

Thanks.

Matt.
Logged

Montreal
Offline Offline
Faraday Member
**
Karma: 27
Posts: 2573
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I did  some testing with both direction FFT.
http://coolarduino.wordpress.com/2012/04/09/voice-pitch-shifting-scrambler/
 Code build on Radix-4 FFT,  though Napoleon's plan was make real-time speech compression, but don't have time to continue.
 Other things, it's not a library, to do so and than update it regularly to keep up with new software releases (1.00, 1.01, 1.02, 2.0a ...) till the end of my life  drive my cortex from normal 65 ppm (pulse per minute) to 360 -);
 Other things, library usually put a constrain on data format, size arrays etc via API specification.
What is your application, could you tell more on requirements: data format (8/16/32 bits), frame rate, pass-band?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Magician, thanks for your soon answer.

I am far away to be an expert in electronic , so be pacient with me and my novice questions smiley... I have been reading the code that you wrote for Radix-4 of the PitchShifting project and of course I watched your video on youtube and let me tell you that did a Great Job! that video is awsome with a 8bit Micro, congratulations and thanks for share the code with us.

I will explain what do i want to do and you can tell me if it possible:

I have an audio of 4 khz, this audio signal has different tones (one tone of 1000 hz, another of 1300 hz and another of 1600 hz ) just tones, there is no human voice.
The think I want to do is to filter the tones, I mean I want just the tone of 1000 hz as output to a speaker as you did in the PitchShifting (but I dont want to shift the signal, i want to have the same signal of 1000 hz as output), so do you think that I could do that if I execute de FFT funcions and then I  delete or put in 0 the bin of 1300 hz and the bin of 1600 hz and then execute the iFFT ?

Do you think it will work, I will have just the 1000 hz signal as output?

Thanks!!!

Matias.

 
Logged

Montreal
Offline Offline
Faraday Member
**
Karma: 27
Posts: 2573
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
that video is awsome with a 8bit Micro, congratulations and thanks for share the code with us.
smiley-red You are welcome.
Quote
so do you think that I could do that if I execute de FFT funcions and then I  delete or put in 0 the bin of 1300 hz and the bin of 1600 hz and then execute the iFFT ?

Do you think it will work, I will have just the 1000 hz signal as output?
Technically, yes. You could just "0" - zeroing whatever bins you don't need at the output, ( in both part real, and imaginary), than run reverse and get your "cleaning" process done. (If not zeroing, just multiply with coefficients, it's possible to get nice equilizer).
 So short answer yes.
 But, as always, there are some "but's and if's". In first, for voice running iFFT is computationally efficient way to restore waveform, as all bins has to be processed back to output.  For your application it's not true, simple wave table synthesis (with LUT sinewave) would be much more efficient for single-tone generation.
 Second, manipulation with data "in-between"  (shifting, zeroing, or multiplying as I mention for equalizer) would create distortion at the output, if you try to do it in straight forward approach, w/o overlap-add technics . Frame's boundary discontinuity would be unacceptable "hearable" as modulation by 62.5 Hz.
 Long answer: no, better way via wavetable synthesis.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Magician,

thank you very much for yout support smiley

I think next week I'll try your code with my project ... I will give you the feedback smiley

Thanks, it was very helpfull your support.

Matias.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Magician,

I need help.

I'm trying out your Pitching Code.

I connect my function generator in A0 without any Op Amp, I mean directly.
Then I got a bad signal in the out (I did the circuit that you put in the blog, the one who has to connect pin5 and pin6 with some R and Capacitors)
Do you know what could be ? Do I doing something wrong?
In the out I connected a USB Spekaer which has an Amplifier.

Thanks


Logged

Montreal
Offline Offline
Faraday Member
**
Karma: 27
Posts: 2573
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 You can't connect AC signal source to analog input, AtMega doesn't tolerate negative half-wave voltage. It's not clear what kind of
Quote
my function generator in A0
, but if it lab's 50 Ohm, I'm afraid you fried input.  If you don't want to solder analog front-end with OPA, look here how to hack your USB speakers:
http://coolarduino.wordpress.com/2012/06/22/audio-input-to-arduino/
 Before you connect anything to output, try build-in debug CLI (Command Line Interface) and see what comming out when you send "x". Serial settings 115200.  Than "f" and "y".
Code:
    if (incomingByte == 'x') {
      for (int i = 0; i < FFT_SIZE; i++){
        Serial.print("\t");
        Serial.print( xin[i], DEC );
        if ((i+1)%16 == 0) Serial.print("\n");
      }
      Serial.print("\n");
    }
    if (incomingByte == 's') {             // SWITCHES  -  SCRAMBLING  ON / OFF
       scrmbl_sw = 1 - scrmbl_sw;
        Serial.print("\tSwitch: ");
        Serial.println( scrmbl_sw, DEC );     
    }
    if (incomingByte == 'y') {
       prnt_yotta = 1;
    }
    if (incomingByte == 'f') {
       prnt_spktr = 1;
    }
    if (incomingByte == 'p') {
       prnt_scrmb = 1;
    }
    if ((incomingByte >= '0') && (incomingByte <= '9')) {
       pitch_shf = incomingByte - 48;
       Serial.print("\tPitch: ");
       Serial.println( pitch_shf, DEC );     
    }
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Magician,

I'm again, I told you you have to be pacient with me smiley

I tried the input that you tolde me and I Failed, then I connect an OP before ADC and failed again.
Of course it is my poor electronic knowledge.

So I need to check if my input and Output circuit is ok:

1) So Could you tell me exactly how did you connect the audio to the ADC ? (The schematic or circuit I mean)

2) And tell me if you connect the output in this way : http://coolarduino.files.wordpress.com/2012/04/pwm_10bit1.jpeg

Thank you very much for your help and pacient smiley

Matias
Logged

Montreal
Offline Offline
Faraday Member
**
Karma: 27
Posts: 2573
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I tried the input that you tolde me and I Failed, then I connect an OP before ADC and failed again.
Of course it is my poor electronic knowledge.
What do you mean by "failed"? Have you try to run a serial monitor from arduino IDE and print out input samples array sending "x" command?  By the way, what is the version of IDE? I put this remark in the header of sketch:
Quote
* SOFTWARE COMPILES USING Arduino 0022 IDE (Tested on Linux OS only).
 * !!! IDE 1.0 mixed up TIMER2 settings, some modification would be necessary in
 * the ISR, responsible for sampling / replayiying.
   Actually, I figured it out later, how to fix this incompatibility with 1.0 IDE. All it takes, just run "find and replace" TIMER2 definition for something else, like TMR2 or TSR2 whatever, as original name already in use by some library.

 This is why first step in debugging, have a look on sample-pool. Error related to wrong timer settings easy to spot applying known freq. to input, and counting  zero-cross in sample-pool. Or you can "copy - paste" printed on serial monitor data to Excel, and draw a chart, to see if there is any artifacts, non-linearity, spikes etc.
Quote
1) So Could you tell me exactly how did you connect the audio to the ADC ? (The schematic or circuit I mean)
On a video clip : I put a label "pre-amplifier" over the board, which is a  kit linked on this page: http://fftarduino.blogspot.com/2011/02/color-organ-spectrum-analyzer-on.html
Drawings the pre-amplifier is here: http://coolarduino.files.wordpress.com/2012/06/audio_input.jpeg bottom left side, analog input on Arduino Uno - 0. What is your board?

2) And tell me if you connect the output in this way : http://coolarduino.files.wordpress.com/2012/04/pwm_10bit1.jpeg
Yes, exactly as it shown.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Magician,

it is working!!! smiley

it was just the IDE 1.0 smiley-sad .... I used the 022 and it was plug and play smiley  great!! Thanks for your help!

I have some questions that may be you know, first I will explain What aI want to do then I will ask , I think it is better for you to understand me with my poor electronic knowledge smiley

I want to process a 1 khz signal (could be actually any signal from 0 to 3 khz) ... but just once at time, so suppose that in Analog 0 I have a pure signal of 1 khz ... so I want to check every 32milliseg if the 1 khz singal change their phase 180º ... The protocol works in that way, if it changes their phase 180º (I have always to compare the actuall phase with the last 32millisec phase in order to realize if it changes) so if it changfes I know it is a 0 bit if there in no change is a 1 bit (that the way the protocol works) ....

1) So is there any way to check the phase of a frequency or bin  with some FFT function or something like that?
2) The Voice Pitch Shifting – Scrambler code  samples at 8khz so that means that I will have 4khz from 0 to 64 bin ? each bin will have 62,5 hz of bandwith? I am correct?

Again, Thank you very much for your help!!!

Matt.



Logged

Montreal
Offline Offline
Faraday Member
**
Karma: 27
Posts: 2573
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
2) The Voice Pitch Shifting – Scrambler code  samples at 8khz so that means that I will have 4khz from 0 to 64 bin ? each bin will have 62,5 hz of bandwith? I am correct?
  Correct,  for 1 kHz decoding, you have to "monitor" phase of bin: 1000/ 62.5 = 16.  Here is excellent tutorial how to  calculate phase :
http://www.dspguide.com/ch8/9.htm  For one bin phase calculation, atan2 function should work just fine, I don't think you need LUT for this. 
http://www.cplusplus.com/reference/clibrary/cmath/atan2/
 After you get a phase in variable, all it takes is just subtract new value from the previous one , and check if there is big "jump" in value. Some threshold adjustment would be necessary to make decoding error-free, as small drift in phase will always be present in asynchronous decoding configuration.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good tip with that page!

I tell a friend to try out your library, he has a mega, do you think it will work?

Thanks as always :-)

matt
Logged

Montreal
Offline Offline
Faraday Member
**
Karma: 27
Posts: 2573
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Not sure, probably not. Does Mega has the same ADC and TIMER2 registers configuration?
Logged

Pages: [1]   Go Up
Jump to: