I'm still in the process of learning the details of the DFT (and FFT) and I've just made a test .wav file in Audacity by joining 3 one-second sine waves together.
.wav file 1 = 440 Hz, sample rate = 44100, samplecount = 44100, 16-bit
.wav file 2 = 495 Hz, sample rate = 44100, samplecount = 44100, 16-bit
.wav file 3 = 495 Hz, sample rate = 44100, samplecount = 44100, 16-bit
VB TEST code:
Private Sub DFT() Dim N As Integer Dim k As Integer Dim i As Integer Dim mReal() As Double Dim mImaginary() As Double Dim mPhase() As Double Dim mMagnitude() As Double N = NumberOfSamples ReDim mSample(N - 1) ReDim mReal(N / 2) As Double ReDim mImaginary(N / 2) As Double ReDim mPhase(N / 2) As Double ReDim mMagnitude(N / 2) As Double 'Call GenerateWaveSamples(hsbAmplitude.Value, cbo_MIDI_127_Frequencies.Text, lstSampleRate.Text, N, vsb_Number_of_Samples_Forward.Value) Call LoadWaveSamples 'Audacity For k = 0 To N / 2 mReal(k) = 0 mImaginary(k) = 0 Next k For k = 0 To N / 2 For i = 0 To N - 1 mReal(k) = mReal(k) + mSample(i) * Cos(2 * Pi * k * i / N) mImaginary(k) = mImaginary(k) - mSample(i) * Sin(2 * Pi * k * i / N) Next i Next k For k = 0 To N / 2 mMagnitude(k) = Sqr((mReal(k) ^ 2) + (mImaginary(k) ^ 2)) mPhase(k) = Atn(mImaginary(k) / mReal(k)) Next k End Sub
I already have a rough idea how to read the samples and calculate the real and imaginary values, frequencies, magnitudes and phases using both DFT and FFT but how would we determine the DURATION of the fundamental frequencies or notes or pitches programatically or mathematically? Any additional info regarding this would be appreciated.