Adding the first left point frequency spectrum to the right side end to make it perfectly symmetrical does not fix the problem?

bhs67

Well-known member
Joined
Oct 11, 2021
Messages
50
Programming Experience
10+
Start with a 2 Hz signal. The signal is sampled at a 4.167 Hz sample rate. See .https://nyquist.foxping.com/ => "DFT Images 2 Hz, 0 zeros.pdf". The intent is to reconstruct a sampled signal (top right side) to be identical to the original signal (top left side).

This code converts a signal to a frequency spectrum (DFT):

C#:
public Complex[] acplxConvertSignalToDft(double[] adSignalYValues)
{
  int iNumOfValues = adSignalYValues.Length;
  Complex[] acplxFrequencies = new Complex[iNumOfValues];
  for (int ii = 0; ii < iNumOfValues; ii++)
  {
    acplxFrequencies[ii] = 0;
    for (int iii = 0; iii < iNumOfValues; iii++)
    {
      acplxFrequencies[ii] += adSignalYValues[iii] *
        Complex.Exp(-Complex.ImaginaryOne *
        2 * Math.PI * (ii * iii) /
        Convert.ToDouble(iNumOfValues));
    }
    acplxFrequencies[ii] = acplxFrequencies[ii] / iNumOfValues;
  }
  return acplxFrequencies;
}//acplxConvertSignalToDft

This code converts a frequency spectrum into a signal (Inverse DFT):

C#:
public double[] adConvertDftToSignal(Complex[] acplxFrequencies)
{
  int iNumOfValues = acplxFrequencies.Length;
  double[] adInverseDftSignalYValues = new double[iNumOfValues];
  for (int ii = 0; ii < iNumOfValues; ii++)
  {
    Complex cplxSum = 0;
    for (int iii = 0; iii < iNumOfValues; iii++)
    {
      cplxSum += acplxFrequencies[iii] *
        Complex.Exp(Complex.ImaginaryOne *
        2 * Math.PI * (iii * ii) /
        Convert.ToDouble(iNumOfValues));
    }
    //Use real values imaginary values should be close to zero
    adInverseDftSignalYValues[ii] = cplxSum.Real;
  }
  return adInverseDftSignalYValues;
}//adConvertDftToSignal

See .https://nyquist.foxping.com/=> "DFT Images 2 Hz, 200 zeros.pdf". Insert 200 zeros between the max frequency in the middle of the frequency spectrum (middle right side image). Then use Inverse DFT to attempt to reconstruct the original signal.

The reconstructed signal (bottom right side) is similar, but not identical to the original signal (top left side).

I noticed that the frequency spectrum was not perfectly symmetrical => one more point on the left half. I decided to add the first left point to the right side end to make it perfectly symmetrical. See .https://nyquist.foxping.com/ => "DFT Images 2 Hz, 200 zeros - added 1st to end.pdf". This distorts the signal.

Adding the first left point frequency spectrum to the right side end to make it perfectly symmetrical does not fix the problem?
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
4,029
Location
Chesapeake, VA
Programming Experience
10+
I managed to skip out on the math course that taught all the theory of how FFTs and DFTs work. You may have better luck asking in StackOverflow's math or engineering forums, rather than this C# focused forum.
 

bhs67

Well-known member
Joined
Oct 11, 2021
Messages
50
Programming Experience
10+
This is one of the greatest discoveries, thanks to Nyquist. It is used in the music recording business ... store a minimum number of values, then reconstruct the original signal.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
4,029
Location
Chesapeake, VA
Programming Experience
10+
I've got no doubt about that. I just felt it unimportant at that time in my school career because I was more interested in writing code and went with the computer science track and didn't require the course, as compared to the computer engineering track which did require it.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
4,029
Location
Chesapeake, VA
Programming Experience
10+
This is just me theorizing, but I don't think you can just copy the leftmost point to the right most point without twiddling the imaginary part of complex number.
 
Top Bottom