ADC data for Fast Fourier Transform
Why is it common to use ADC data for input sampling to compute Fast Fourier Transform? Why is it a good sampling method for Fast Fourier Transform?
See also questions close to this topic

Conversion from char to int does something weird
Im working with a Particle Photon to make a digital watch + alarm clock. I am using a TFT screen, and i have drawn some digits on it which i can increment and change "digit index" with some buttons that i connected to my Photon  with the purpose of setting the time of a scheduled alarm. The function under is the one i call when a button is clicked, and its parameter is what "digit index" the "cursor" on my screen is at, which i can navigate with my buttons. This works fine however, all the way until 9  where my screen starts displaying ASCII smileys and other letters instead of digits. I tried putting an if statement, that when the variable temp is higher than 9, it is set to 0  which is what i ultimately want to achieve. This did not work, and it keeps displaying ASCII letters when it exceeds 9. Then i decided to try to print temp to console at button click, but then the first letter it prints is 49 and not 0? What??
I am not too seasoned with C/C++, but i do have a hunch that before im incrementing temp, i am doing the conversion from the char array timeSet wrong. What do you guys think?
void replaceDigitFromIndex(int selectorIndex) { tft.setTextSize(4); tft.setTextColor(ST7735_RED); tft.setCursor(4, 20); tft.print(timeSet); int temp = 0; if(selectorIndex == 1) { temp = (int) timeSet[0]; temp++; timeSet[0] = (char) temp; } if(selectorIndex == 2) { temp = (int) timeSet[1]; temp++; timeSet[1] = (char) temp; } if(selectorIndex == 3) { temp = (int) timeSet[3]; temp++; timeSet[3] = (char) temp; } if(selectorIndex == 4) { temp = (int) timeSet[4]; temp++; timeSet[4] = (char) temp; } }

How can i extract constants' addresses,added by compiler optimization, from ELF file?
I'm writing some code size analysis tool for my C program, using the output
ELF
file.I'm using
readelf debugdump=info
to generateDwarf format file
.I've noticed that My compiler is adding as a part of the optimization new consts, that are not in Dwarf file, to the
.rodata
section.So
.rodata
section size includes their sizes but i don't have their sizes inDwarf
.Here is an example fro map file:
*(.rodata) .rodata 0x10010000 0xc0 /<.o file0 path>
0x10010000 const1 0x10010040 const2
.rodata 0x100100c0 0xa /<.o file1 path>
fill 0x100100ca 0x6
.rodata 0x100100d0 0x6c /<.o file2 path>
0x100100d0 const3 0x100100e0 const4 0x10010100 const5 0x10010120 const6 fill 0x1001013c 0x4
In file1 above, although i didn't declare on const variable  the compiler does, this const is taking space in .rodata yet there is no symbol/name for it.
How can i extract theses hidden additions from data sections?
I want to be able to fully characterize my code  How much space is used in each file, etc...

Pseudo database on flash without file system for FreeRTOS
I am quite new to embedded development and seems don't know correct wording to find it on Google.
Can somebody point me to best practices of storing data for preferences/history/some set of repetitive data?
Best would be to save it to flash directly without handling filesystem. And for sure threadsafe is a big plus.
SQLite seems too complicated for my needs and I search for something that can store something like name>object pairs.
Any suggestions are highly appreciated. Thank you.
Update. Question is about external SPI flash.
The data for storing is settings, like key>value map. And also some history, which in fact list of structs.

How to measure waveform distortion analysis (THD, THD+N...) in C++
I'm looking for how to measure distortion for waveform. Waveform data is received from the oscilloscope.
Currently I use FFTW(fftw_plan_dft_1d) to convert waveforms to spectrum. But I don't know how to perform distortion measurements?

How to disable "precharge" while generating a periodical signal using a Keithley2635B sourcemeter?
Good day,
I am trying to source custom waveforms using a Keithley 2635B sourcemeter. Using the trigger attribute
listv
and the timer attributedelaylist
it is easy to do but an unexpected behavior appears.As you can see on the attached picture, I am sourcing a very simple square signal (two points
+A
and–A
with the same delay) and repeat it a number of times usingsmua.trigger.arm.count = <Periods>
. Notice how the signal plateaus when switching polarity? It only happens when crossing 0, if I add an offset so that the signal keeps the same sign there is no issue. This plateau has a very consistent duration of 125 µs regardless of which frequency I try to source. Its impact is not negligible anymore at high frequencies.Below is the portion of the code that matters. Code that is upstream only processes the various parameters given by the user (frequency, amplitude, offset, etc) to create the appropriate
listv
anddelaylist
. Lua commands sent to the Keithley are wrapped with theWRITE()
function so that the rest of the program can be written in Python.# Source V K.WRITE("smua.source.func = smua.OUTPUT_DCVOLTS") # Configure actions to start immediately. K.WRITE("smua.trigger.arm.stimulus = 0") K.WRITE("smua.trigger.source.stimulus = 0") K.WRITE("smua.trigger.endpulse.stimulus = 0") # Configure the source action. K.WRITE("smua.trigger.source.action = smua.ENABLE") K.WRITE("smua.trigger.endpulse.action = smua.SOURCE_HOLD") K.WRITE("smua.trigger.source.listv(%s)" %SourceArray) K.WRITE("smua.trigger.arm.count = %d" %Periods) K.WRITE("smua.trigger.count = %d" %PointsPerPeriod) # Delay between outputs K.WRITE("trigger.timer[1].reset()") K.WRITE("trigger.timer[1].delaylist = {}".format(DelayArray)) K.WRITE("trigger.timer[1].stimulus = smua.trigger.SOURCE_COMPLETE_EVENT_ID") K.WRITE("smua.trigger.measure.stimulus = trigger.timer[1].EVENT_ID") # Start the trigger to generate the AC signal then turn off the output when done. K.WRITE("smua.source.output = 1") K.WRITE("smua.trigger.initiate()") K.WRITE(“waitcomplete()”) K.WRITE("smua.source.output = 0")
Edit: the sourcemeter documentation indicates that
in cases where the first sweep point is a nonzero value, it may be necessary to precharge the circuit so that the sweep will return a stable value for the first measured point without penalizing remaining points in the sweep.
so I assume the plateau I witness is precharge at the beginning of every repetition. Is there a way to disable it? Thanks in advance.

Find equivalent digital filter
I'm trying to find an equivalent digital filter for a simple RC filter. The bode plots don't line up and I don't know why.
====================================================
import numpy as np import scipy.signal as sig import matplotlib.pyplot as plt # Analog filter tau = 0.001 # param lti = sig.lti([1], [tau, 1]) # Equivalent digital filter fs = 20000 # param T = 1 / fs wd = 1 / tau wa = 2 / T * np.tan(wd * T / 2) dtau = 1 / wa dnum, dden = sig.bilinear([1], [dtau, 1], fs) dlti = sig.dlti(dnum, dden) w, mag, phase = sig.bode(lti) dw, dmag, dphase = sig.dbode(dlti) plt.figure() plt.subplot(211) plt.semilogx(w, mag) # Bode magnitude plot plt.semilogx(dw, dmag) plt.subplot(212) plt.semilogx(w, phase) # Bode phase plot plt.semilogx(dw, dphase) plt.show()

Check if The system Date is correct in Vba
Does anyone can help? How to check if a local system has a valid date setting using vba. To protect Code from being run after specified date.
The following code is not enough, it can be break by changing system date.
Private Sub Workbook_Open() If Date > DateSerial(2018, 5, 17) Then ThisWorkbook.Close SaveChanges:=False End If End Sub
Thanks for any reply

How to master system design?
One might be very good at coding (even algorithms and data structures), but he might not be good at system design, or high level design. Looks like system design skills need a special care, as opposed to coding skills.
There are lots of online resources for improving coding skills, such as hackerrank.com (one can practice and evaluate his progress/level). But, is there similar resources that help practice, reflect on, and improve your system design skills?
What's the most foundational book on system design?
What's the roadmap towards becoming very good system designer?

Avg memory access time
With swapping, memory can be viewed as a cache for pages stored on disk. If it takes 100 ns to access memory, 10 ms to access disk, and our cache hit rate is 0.95, then what is the average memory access time, in ms? (provide only two significant digits in your answer)
I've looked around and can't figure it out. My friend is also having the same issue and this is what we got so far: 0.95 * 100ns + 0.05 * 10ms. He says that 0.05 comes from 1  0.95. I just want to know if this is the right setup and if the 0.5 is correct.
Thanks.

fft of soundevice numpy array doesn't have right size
sounddevice works well with a variety of sample rates and devices. The docs for sounddevice.rec say it returns a numpy array.
Normally numpy.rfft will return an array half the size of the original time domain array.
However when I do an rfft on an array obtained from sounddevice.rec, I get an array which is the same size I submitted.
In the example below the rfft result should have a .size of 13, instead we get 25  tha same as what we submitted.
Can anybody suggest what is wrong?
>>> import numpy as np >>> import sounddevice as sd >>> recording = sd.rec(25, device = 'Device',samplerate=48000, channels=1,dtype='int16') >>> recording.size 25 >>> fftrec=np.fft.rfft(recording) >>> fftrec.size 25 >>>
Running Python3.5 under Stretch

1D convolution and deconvolution using FFT
The task: there is some original signal, and there is some response function. I need to convolve them using FFT and then do deconvolution to restore original signal.
The task graphical illustration ( image taken from https://www.originlab.com ):
I wrote the code but getting wrong results. Here are they:
Convolution is obviously wrong. Can you give me a clue where is my mistake?
What I need to do deconvolution, to restore original signal?
I'm using real part of convolution as a convolved signal.
Full working example:
import java.awt.Dimension; import javax.swing.JFrame; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; /** * Description: * Attempt to convolve two 1D functions (original signal with response function ) using FFT, and then restore origin signal. * * * * Dependencies: * FFT.java ( source: https://introcs.cs.princeton.edu/java/97data/FFT.java.html ) * Complex.java ( source: https://introcs.cs.princeton.edu/java/97data/Complex.java.html ) * JFreeChart (for visualizing results) * * * **/ public class FFTConvolutionTest { public static final int nfft = 1024; //FFT length public static void main(String[] args) { //A first function for convolution : original signal is a sine curve double samplingFrequency = 150; //Hz double timeLength = 4; //sec double signalFrequency = 5; //Hz int samples = (int) (timeLength * samplingFrequency + 1); double[] signal = new double[samples]; for (int i = 0; i < signal.length; i++) { signal[i] = Math.sin(2 * Math.PI * ((double) i / samplingFrequency) * signalFrequency); } visualizeArray(signal, 1d/samplingFrequency, "signal"); //A second function for convolution : response function is a gaussian distribution double length = 1; double step = length/samplingFrequency; double[] response = new double[samples]; double center = (int) (samples / 2); double stdDev = 0.3; double factor = 1/(Math.sqrt(2 * Math.PI * Math.pow(stdDev, 2))); double exponent; for (int i = 0; i < response.length; i++) { exponent = (double)  1/2 * ( Math.pow(((double) i  center) * step /stdDev, 2)); response[i] = Math.pow(Math.E, exponent) * factor; } visualizeArray(response, step, "response"); //Making convolution double[] conv = convolution(signal, response); visualizeArray(conv, 1d/samplingFrequency, "convolved"); } public static double[] convolution(double[] xd, double[] yd) { // fft length must be larger than both arrays lengths if ( (xd.length > nfft)  (yd.length > nfft)) { throw new IllegalArgumentException("nnft must be larger: " + xd.length + ", " + yd.length); } // Forming complex versions of arrays Complex[] x = new Complex[nfft]; Complex[] y = new Complex[nfft]; // Extending both x and y arrays to fft length, completing rests with zeros. for (int i=0; i< nfft; i++) { if (i < xd.length) { x[i] = new Complex(xd[i], 0); } else { x[i] = new Complex(0, 0); } if (i < yd.length) { y[i] = new Complex(yd[i], 0); } else { y[i] = new Complex(0, 0); } } // Doing the convolution Complex[] c = FFT.convolve(x, y); //returning real part of convolution double[] cd = new double[nfft]; for (int i=0; i < cd.length; i++) { cd[i] = c[i].re(); } return cd; } public static void visualizeArray(double[] array, double step, String name) { double[][] array2D = new double[array.length][2]; for (int i=0; i<array2D.length; i++){ array2D[i][0] = (double) i * step; array2D[i][1] = array[i]; } final XYSeriesCollection xyCollection = new XYSeriesCollection(); XYDataset xyDataset = xyCollection; XYSeries series = createSeries(array2D, name); xyCollection.addSeries(series); JFreeChart chart = ChartFactory.createXYLineChart(name, "x", "y", xyDataset); ChartPanel chartPanel = new ChartPanel(chart, true, true, true, false, true); JFrame frame = new JFrame(); frame.add(chartPanel); frame.setPreferredSize(new Dimension(700, 500)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); // center the frame frame.setVisible(true); } public static XYSeries createSeries(double[][] array, String name){ XYSeries series = new XYSeries(name); int[][] xyValues = new int[array.length][2]; for (int i = 0; i < xyValues.length; i++) { series.add(array[i][0], array[i][1]); } return series; } }

2D Fourier Transform
I am currently working with
np.fft.fft2()
to simply do a Discrete Fourier Transform but I see the order of the elements of the resulting matrix is not correct. Is there something I'm missing? I've written my own DFT and I expect the following result:Any idea why this occurs for numpy?
Thanks, Harry

Random formula based of 15 seeds
I am working at my university degree and I got stuck at a random function. I am using a microcontroller, which has no configured clock. So, I decided to use the ADC (analog to digital conversion) as seeds for my random function.
So I have 15 two bytes variables with stores some 'random' values ( the conversion is not always the same, and the difference is at the LSB ( the last bit in my case :eg now the value of an adc read is 700, in 5ms it is 701, then back to 700, then 702 etc). So, I was thinking to build a random function with use the last 4 bits lets say from those variables.
My question is: Can you give me an example of a good random formula?
Like
( Variable1 >> 4 ) ^ ( Variable2 << 4 )
and so on ...I want to be able to obtain a pretty random number on 1 byte ( this is the best case ). It will be used in a RSA algorithm, which I have already implemented ( I have a big look up table with prime numbers, and I need 2 random numbers from that table ).

What resistor should be used for OPB80155 optocoupler on transmitter and receiver side?
I am unable to find the values of the resistors that can be used for the optocoupler with the abovenumber.http://www.ttelectronics.com/sites/default/files/downloadfiles/Datasheet_OPB800%20series.pdf is the datasheet of the above mentioned optocoupler.

Build my Own lightning adapter
I have a question about the lightning.
I want to build my own adapter (splitter Jack/Lightning), I want to use the lightning (charger) and the jack 3,5 mm in the same time.
Someone has an idea, how I can make it. (tutorial or information about...)
I Know that product exists but It's a personal project.
Thank's per advance