Login / Register  0 items | $0.00 NewWhat is KVR? Submit News Advertise

FFT using vectors

User avatar
Xenobioz
KVRist
 
355 posts since 4 Jul, 2006, from Sweden

Postby Xenobioz; Wed Jun 14, 2017 1:24 am FFT using vectors

Hi, is there any FFT library that can be used with vectors instead of arrays?
I use vectors for my oscillator waveforms, so I don't want to convert them to arrays just for the FFT.
stratum
KVRian
 
1240 posts since 29 May, 2012

Postby stratum; Wed Jun 14, 2017 1:58 am Re: FFT using vectors

You dont need to convert. Use &v[0]
~stratum~
Miles1981
KVRian
 
1251 posts since 26 Apr, 2004, from UK

Postby Miles1981; Wed Jun 14, 2017 6:30 am Re: FFT using vectors

or v.data()
User avatar
Xenobioz
KVRist
 
355 posts since 4 Jul, 2006, from Sweden

Postby Xenobioz; Thu Jun 15, 2017 12:01 am Re: FFT using vectors

Thanks! I also suddenly found a library which uses vectors
https://www.nayuki.io/page/free-small-f ... -languages

Is there anything I should be aware of when using a random FFT algorithm I found? Are they all suitable for bandlimiting waveforms?
MadBrain
KVRian
 
941 posts since 1 Dec, 2004

Postby MadBrain; Thu Jun 15, 2017 7:22 pm Re: FFT using vectors

Most of the difference should be in how fast it runs. Precision is rarely an issue for audio processing FFT.
User avatar
Xenobioz
KVRist
 
355 posts since 4 Jul, 2006, from Sweden

Postby Xenobioz; Fri Jun 16, 2017 12:50 am Re: FFT using vectors

Thanks!
User avatar
Xenobioz
KVRist
 
355 posts since 4 Jul, 2006, from Sweden

Postby Xenobioz; Fri Jun 23, 2017 4:16 am Re: FFT using vectors

I made a sine wave and then ran fft on it and then inverse fft to get the same sine back, but that didn't work. Probably because I don't know how to use the FFT. I tried to put the sine wave in to the real part and have the imaginary part consist of all zeros. So what part should I put in and then read after the inverse fft?The imaginary or real? I only got a line with little noise on or just a few dots when drawing out the waveform.

Also I tried to sum the sines without inverse FFT but got the same kind of line. :cry:
Miles1981
KVRian
 
1251 posts since 26 Apr, 2004, from UK

Postby Miles1981; Fri Jun 23, 2017 6:14 am Re: FFT using vectors

In the inverse FFT, you put all the data from the FFT. And yes, for the FFT, you copy your data in the real part.
This works fine, if you have an issue, you need to show us code.
quikquak
KVRist
 
263 posts since 6 Aug, 2005, from England

Postby quikquak; Fri Jun 23, 2017 7:14 am Re: FFT using vectors

Did you remember to scale the IFFT?
User avatar
Xenobioz
KVRist
 
355 posts since 4 Jul, 2006, from Sweden

Postby Xenobioz; Fri Jun 23, 2017 11:24 am Re: FFT using vectors

quikquak wrote:Did you remember to scale the IFFT?


No, i did not know about that. How do i scale it? :oops:
Miles1981
KVRian
 
1251 posts since 26 Apr, 2004, from UK

Postby Miles1981; Fri Jun 23, 2017 2:06 pm Re: FFT using vectors

The end result must be divided by the number of samples. Unless your FFT does it for you (like IPP can).
User avatar
Xenobioz
KVRist
 
355 posts since 4 Jul, 2006, from Sweden

Postby Xenobioz; Sat Jun 24, 2017 1:06 am Re: FFT using vectors

Miles1981 wrote:The end result must be divided by the number of samples. Unless your FFT does it for you (like IPP can).

Thanks, now it works!
Now I only need to figure out how to bandlimit the waveform.
Miles1981
KVRian
 
1251 posts since 26 Apr, 2004, from UK

Postby Miles1981; Sat Jun 24, 2017 7:28 am Re: FFT using vectors

You can't in the spectral domain. It's mathematically impossible (not with a multiplication).
User avatar
Xenobioz
KVRist
 
355 posts since 4 Jul, 2006, from Sweden

Postby Xenobioz; Sat Jun 24, 2017 11:38 am Re: FFT using vectors

Miles1981 wrote:You can't in the spectral domain. It's mathematically impossible (not with a multiplication).


Does that mean I can't use FFT to remove frequencies that are too high?
Miles1981
KVRian
 
1251 posts since 26 Apr, 2004, from UK

Postby Miles1981; Sat Jun 24, 2017 2:03 pm Re: FFT using vectors

Yes, that's exactly what I'm saying.
This is why you need algorithms like Remez to design in time space a filter that tries to approximate a template given in spectral domain.
This is what I'm trying to explain in the last chapter of my book (if you want to have a look: https://github.com/mbrucher/AudioTK-boo ... /tag/0.0.6)
The main issue is that you have a bijection from time to spectral domain. N samples in time give you N points in spectral domain. Now, the reciprocal is true except if originally you know that some of the N time samples are zeros (which is called zero padding).
The main problem with FFT multiplication is that it gives you circular convolution in time domain. More often than not, people say that it's convolution, but it's false, it's _circular_ convolution. So you alias in the time domain your data.
Now, if your original signal has m non zero samples and you convert that to N spectral samples and multiply this spectrum by something to remove high frequencies, it will still be a circular convolution. The N multiplications, when it's converted to time domain, gives back N samples, so your convolution should give you N + m samples, but it's not possible, as you only have N (so the m are "aliased", and gives you circular convolution).
So the only way to get past this is to have a set of N multiplications that give you N - m + 1 samples, and the only way of doing so is to start with N + m - 1 samples in time domain and figure out a filter from them. Which is more or less what Remez can do.
Next

Moderator: Moderators (Main)

Return to DSP and Plug-in Development