I designed a 1st order Delta Sigma converter in PSpice, except for the decimation filter. I want to implement said decimation filter in Python, rather than in PSpice. Being new to both Python and filters in general, I turned to google, which offered me this "simple" solution.
The explanation is quite clear (I think). In my case, the parameters are the following: - signal going into the DeltaSigma ADC: 1 kHz sin wave - sampling rate of the DeltaSigma ADC: 5 MHz - simulation step size: 100 ns (might be relevant)
When I design my filter (a Windowed Sinc filter, as in the example above) I use the following parameters (I have also used some variations of these parameters): - cutoff frequency fc = 3 kHz - transition bandwidth 1 kHz, which results in N = 200001
NB: the filter might be very ambitious, but as far as I can see this is just a computation-time-related problem.
Now, if I implement the above in Python everything seems to work fine up to the filter application to my signal; this means that the sinc filter "looks" nice in the plot, the input signal is ok, etc...
For reference: this is my implementation of the filter.
# Define the parameters fc = 0.0006 b = 0.0002 N = int(np.ceil((4 / b))) if not N % 2: N += 1 # Make sure that N is odd. n = np.arange(N) # Compute sinc filter. h = np.sinc(2 * fc * (n - (N - 1) / 2.)) # Compute Blackman window. w = np.blackman(N) # Multiply sinc filter with window. h = h * w # Normalize to get unity gain. h_unity = h / np.sum(h)
After this, I simply do a convolution with:
filtered_data = np.convolve(out, h, 'valid')
Image of the output data after the filter:
I would expect the filtered data to be a sin wave, not that "thing".
My guess is that I am missing something fundamental and that somehow I should take care of the fact that the sampled signal is actually sampled with both the 5Mhz clock AND with the 100 ns simulation time.
Any help will be appreciated!
EDIT: clarification on the out signal.
The out signal is generated by a Delta Sigma converter, so supposedly it should be a stream of '1' and '0'.
But since the PSpice simulator has an internal step size (which is variable) the actual values of the out signal have also intermediate values (remember: the output waveform in PSpice is a voltage, so in the transition between 0/1 the voltage is calculated).
So, my out signal looks like this (not actual values, just for clarity):
Time Out 0 0.000 0.1 0.000 0.145 0.123 0.167 0.679 0.2 1.000 0.3 1.000 0.4 1.000 0.45 0.875 0.493 0.439 0.560 0.293 0.6 0.000
This most likely introduces spurious frequencies in my spectrum.
Working on a possible solution, will let you know if it works!