Please consider this piece of code:
clc;clear all; fs=10^3; t=linspace(0,1,fs); f=2; x=sin(2*pi*f*t); W=dftmtx(fs); X=fft(x); X(3) X(end-1) %check : imaginary parts are 180 degrees dephased but right frequency %plot(imag(W(end-1,:)));hold on; plot(imag(W(3,:))) Xrec=(1/length(X))*(X(end-1)*W(3,:)+X(3)*W(end-1,:)); plot(x,'+g');hold on;plot(Xrec,'r','LineWidth',1.25);
The idea is to show (for my personal understanding) that we can reconstruct the pure sine wave x (of frequency 2 cycles) with the only 2 Fourier coefficients (corresponding to the 2 spikes we see in the spectrum) i.e. a negative frequency = -2 and a positive frequency = 2, for this example.
It seems to work well with the line:
Where I want to show that the signal x can be reconstructed by the weighted contribution of W(3,:) and W(end-1,:) (which I found to correspond to +freq and -freq (+2/-2)). This is the point of view of linear algebra where the vector x is a linear combination of the basis vectors W(3,:) and W(end-1,:) with the complex weights X(3) and X(end-1).
Is this explanation correct?
Moreover, there is the perspective of "matched filter", i.e. correlation. From this point of view we should have only contribution of the 2 frequencies aforementioned here 2/-2. But I still get some non-zero correlation when doing e.g. :
W(555,:)*x' = -0.0063 - 0.0011i
... i.e. W(k != 3 or 999) (which are the indexes corresponding to freq=2 or freq=-2)
its small but not zero, so I would then to think that these have some contribution to the signal yet the should not ?