I am doing the following experiment: http://physlab.lums.edu.pk/images/a/ab/Correlation.pdf
It is basically a white noise generator running through a low pass filter. Sample voltages are taken and normalized, then autocorrelated using a few methods. The autocorrelation using normalized data is supposed to start at a value of 1 at 0 lag (which it does) and then exponentially decay to 0(which it doesnt). However it is decaying below 0.
Also The auto generated coefficient for an exponential fit (a*np.exp(-(t/b)) + c) (b should = RC), does not match the RC constant of the Low pass filter (R=10kohm, C=0.5 microF, RC=5ms).
The methods I am using for the autocorrelation are as follows: f=list of voltage values with mean subtracted from each value, 100,000 samples @ 10000 S/s
Using Built in Correlate function:
def autocorr(f): result = np.correlate(f, f, mode='full') return result[result.size/2:] autocorr=autocorr(f) autocorr /= autocorr[autocorr.argmax()]
N = len(f) fvi = np.fft.fft(f) #n=2*N) acf = np.real( np.fft.ifft( fvi * np.conjugate(fvi) )[:N] )
Plotting using inbuilt python autocor plot:
import matplotlib.pyplot as plt plt.acorr(f)
Which you can see does not drop below 0. I cannot find out the exact code that is executed with the plt.acorr(f) as it does not support outputting of data.
Here is the fitted exponential (clearly showing dip below 0) fitting function =
from scipy.optimize import curve_fit def func(t,a,b,c): return a*np.exp(-(t/b)) + c popt, pcov = curve_fit(func, t, acf)
However the autogenerated constant from the exponential fit, that should equal RC (5ms) actually comes out as 1.043822ms Also when I reduce the RC by 50% the calculated coefficient reduces by 33%. Also if I change the sampling frequency this reduces the coefficient
Is there a way to produce the autocorrelation of the data gathered, that consists of an exponential decay to 0 with the decay constant as the RC of the low pass filter circuit?
I have tried various RC values for the LPF, they all dip below 0, in fact the lower the RC, the lower it dips below 0.
Could this be related to an incorrect offset voltage of the white noise generator? I changed the offset, and it did increase the lowest value that the autocorrelation drops to, but I am not sure if I adjust it again it will fix the problem completely.
So to recap, 2 issues
Autocorrelation does not decay to 0, it drops below 0
Fitted exponential curve decay coefficient, does not equal the RC constant of the circuit.
This thread Autocorrelation of noise - negative correlation Seems to be related to the same experiment and the same issue (unanswered)
Things that have been tried: The White Noise generator has a threshold knob to set the threshold frequency. It did not fix either of the issues: Highest Threshold Setting:
Lowest Threshold Setting:
Autocorrelation was fitted to Python generated White noise filtered through simulated RC low pass filter circuits (different RC values). This produced correct results. This would lead me to believe the code being used to autocorrelate is correct.
I have tested the FFT method and inbuilt python correlate function to autocorrelate data and they give the same results, also confirming the code should be ok.
A physical signal generator, generating square waves was tested through the A2D and plotted v/s time. The result was correct with the correct timings matching the sampling frequency. This confirms the A2D is functioning correctly.
Example of square wave through A2D:
The square waves were also ran through 2 RC low pass filter circuits. The correct RC values were calculated using an exponential fit. This confirms the RC circuits are functioning correctly and also the code used to fit the exponentials is functioning. However decay below 0 occurred
Example of fitted exponential on filtered square wave:
There is a voltage offset in the white noise generator, this was adjusted a few times (above and below 0V), it did not fix the incorrect fitted exponential RC constants. It does effect the decay of the autocorrelated data, but not to the point where it can be determined if this is the cause of the issue.
Plot below. B=before 1st offset change, A = after 1st offset change, A2-x = after 2nd offset change. RC's correspond to eachother e.g. B1, A1, A2-1 have the same RC etc
I have checked the power spectra of 2 samples of non filtered noise from the white noise generator with the following results:
Please ignore the units
It is possible the noise being generated isn't white noise at all. I will need to check with more samples.
The data does fit autocorrelated white noise (decaying exponential), the problem is, it decays beyond 0 and then recovers and the decay constants are roughly a factor of 10 out from the actual RC values of the low pass filters that the white noise is being filtered through. Currently testing the power spectra of the white noise (not filtered or normalized).All plots of data are just samples with a few samples, I have ran more, to many to include. Thanks to User:Floris for suggestions on what to look at.
Well it turns out the problem does lie with the white noise generator. A very strange issue.
I added a voltage follwer circuit before the RC circuit (to increase the current available) and the results improved dramatically. I'm not sure if this is the final fix as there is some weird issues with the voltage follower, adding voltage gain for some reason. I tested with another white noise source before using the voltage follower and I was able to achieve ~ 90% accuracy comparing the exponentially fit RC value to the theoretical RC value and can now match that with the original white noise generator and voltage follower circuit.
Example of a collection of 10 sample sets @ RC=5ms:
Compared to the "working" white noise source:
I will update with a final answer when I know exactly whats happening and why the issue was occuring. If anyone has any suggestions also, much appriciated.