Help with FFT

Hello everybody,
I'm new to C++ programming but i have a project for school where you can help me with some tips.

The basic idea of the project is to generate different waveforms (sine, square,...) en make a FFT form that signal. This needs to be plotted. So there will be a GUI where the user can choose amplitude, frequency, harmonics (for square, sawtooth, ...) samples for drawing and fft (if you have a other idea just tell me I'm open for any suggestions)

I use VS2012 C++ Windows Forms and I already made a class for all the waveform. For drawing I want to use the Chart with spline.

So far I can give amplitude, frequency and phi(for start). Default I make 256 samples per periode (I want to draw two periodes) and store them in a vector. I made a 2econd vector for storing the time. I use them to draw the sine wave.

So far so good but now I want to do a FFT and draw it. But i have now idea how to start on this. I want a spectrum from 1 Hz to 44.1 kHz (later I want to use it for audio signals). I also want o give the user a chance to mix different signals and show that spectrum to.

If anybody here has some tips or tricks or have some example code I would be really greatfull.

Thanks all for reading and I wish you a happy 2016.

Sorry for my bad english if you want some details I can give them to you but I didn't want to make this a long story :)

Does it have to be an FFT or do you just need to show the frequency domain? If the latter, then you could implement a DCT-II instead, which is fairly easy.
https://en.wikipedia.org/wiki/Discrete_cosine_transform#DCT-II
In that formula, x is the sequence in the time domain (in your case, a sequence of audio samples) and X is the sequence in the frequency domain, with X_0 being the 0 Hz amplitude (equivalent to the DC offset) and X_{N-1} being the N/2 Hz amplitude. Note:
* If you process 1 second worth of 44100 samples/s audio you'll get a frequency domain between 0 and 22050 Hz. If you pass 2 seconds you'll get up to 44100 Hz.
* If you want higher resolution instead of higher range (i.e. 0.5 Hz steps instead of 1 Hz steps) you need to upsample the block being processed, for example by repease samples, or by applying a cubic interpolation.
* The cosine factor can be precomputed and stored if you're going to process fixed-sized blocks.
Sorry for my late answer but we had some examens:
I worked a little bit on the program. At the momen I have a problem i can't solve. The thing is I need to use a ddl file in assambly. I wrote some code for a dft. My problem is how can I copy my vector with al the sample values to the dll file. At the moment I dit this.
in my exe file
1
2
3
#define DllImport   __declspec( dllimport )
std::vector<double> fft;
fft = DFTValue(xsignal, fftSample); 


DFTValue is the function in the DLL

in my dll header file
1
2
3
4
5
6
7
#ifdef DFT_FFT_DLL_EXPORTS
#define DFT_FFT_DLL_API __declspec(dllexport) 
#else
#define DFT_FFT_DLL_API __declspec(dllimport) 
#endif
//dft function
static DFT_FFT_DLL_API std::vector<double> DFTValue(std::vector<double>, int);


dll file buids fine
i got th following error in the exe file:
MyForm.obj : error LNK2028: unresolved token (0A0004A3) "class std::vector<double,class std::allocator<double> > __cdecl testingGraph::DFTValue(class std::vector<double,class std::allocator<double> >,int)" (?DFTValue@testingGraph@@$$FYA?AV?$vector@NV?$allocator@N@std@@@std@@V23@H@Z) referenced in function "public: void __clrcall testingGraph::MyForm::drawChart(void)" (?drawChart@MyForm@testingGraph@@$$FQ$AAMXXZ)


2>MyForm.obj : error LNK2019: unresolved external symbol "class std::vector<double,class std::allocator<double> > __cdecl testingGraph::DFTValue(class std::vector<double,class std::allocator<double> >,int)" (?DFTValue@testingGraph@@$$FYA?AV?$vector@NV?$allocator@N@std@@@std@@V23@H@Z) referenced in function "public: void __clrcall testingGraph::MyForm::drawChart(void)" (?drawChart@MyForm@testingGraph@@$$FQ$AAMXXZ)


2>C:\Users\Swen\Documents\Visual Studio 2012\Projects\testingGraph\Debug\testingGraph.exe : fatal error LNK1120: 2 unresolved externals

any tips how to put and get a vector to and from a dll woud be really helpfull.

Thank you all

Almost forgot yes it's needt to be a dft or fft
My problem is how can I copy my vector with al the sample values to the dll file.
You can't. Different DLLs may be using different runtime instances (e.g. different malloc() pools). Passing vectors around could involve deallocating a buffer that was allocated in a different DLL, which would corrupt the heap that calls free().
You should only pass POD types around, preferably through a pure C (extern "C") interface.

Why do you need to use a DLL?
Topic archived. No new replies allowed.