Skip to content

Commit

Permalink
FFT has been corrected, works fully now, synthesis matches signal exa…
Browse files Browse the repository at this point in the history
…ctly
  • Loading branch information
Brian Tabone committed Jul 18, 2019
1 parent 6b41d34 commit 4fdda7c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions SampleGenerator/Sample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public List<Double> GetSignalSlice
}
}

// 64 channel DFT done on 50 samples + 14 zeros padded right
// 64 channel sample with padCount zeros padded right
public List<double> GetPaddedChannelSample(int sampleCount, int padCount)
{
int numSamplesToGet = (sampleCount - padCount);
Expand All @@ -108,7 +108,7 @@ public List<double> GetPaddedChannelSample(int sampleCount, int padCount)
List<double> paddedSignal = new List<double>(sampleCount);
paddedSignal.AddRange(_sliceSignal);
// Pad
int padLen = (64 - numSamplesToGet);
int padLen = (sampleCount - numSamplesToGet);
for (int cnt = 0; cnt < padLen; cnt++)
paddedSignal.Add(0.0);

Expand Down
10 changes: 5 additions & 5 deletions SignalProcessor/FastFourierTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ private FrequencyDomain Transform(FrequencyDomain frequencyDomain)
{
if (idx <= j)
{
double tr = frequencyDomain.RealComponent[j-1];
double ti = frequencyDomain.ImaginaryComponent[j-1];
frequencyDomain.RealComponent[j-1] = frequencyDomain.RealComponent[idx];
frequencyDomain.ImaginaryComponent[j-1] = frequencyDomain.ImaginaryComponent[idx];
double tr = frequencyDomain.RealComponent[j];
double ti = frequencyDomain.ImaginaryComponent[j];
frequencyDomain.RealComponent[j] = frequencyDomain.RealComponent[idx];
frequencyDomain.ImaginaryComponent[j] = frequencyDomain.ImaginaryComponent[idx];
frequencyDomain.RealComponent[idx] = tr;
frequencyDomain.ImaginaryComponent[idx] = ti;
}
k = nd2;
while (!(k>=j))
while (!(k>j))
{
j = j - k;

Expand Down
8 changes: 4 additions & 4 deletions Signals And Transforms/Models/SampleData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public static Sample SignalSample
ISignalGenerator square = new SquareIshWave();

Sample sinusoidSamp = new Sample(8000, 1, 2, sinusoid);
//Sample sinusoidSamp2 = new Sample(16000, 1, 7000, sinusoid);
//Sample whiteNoise = new Sample(16000, 1, 1000, random);
Sample sinusoidSamp2 = new Sample(8000, 1, 8, sinusoid);
//Sample whiteNoise = new Sample(8000, 1, 1000, random);
//Sample squareWave = new Sample(8000, 1, 400, square);
_signalSample = sinusoidSamp;//.SumWithSample(whiteNoise);
_signalSample.GetPaddedChannelSample(64,0); // Prime the pump
_signalSample = sinusoidSamp.SumWithSample(sinusoidSamp2);
_signalSample.GetPaddedChannelSample(256,0); // Prime the pump
}

return _signalSample;
Expand Down

0 comments on commit 4fdda7c

Please sign in to comment.