# Sampling analog signal with python; problems with understanding fundamentals

I would like to sample an analog 5kHz signal with a 50MHz sample rate. I want to do this with python so I can see if this sort of sample rate is enough for my needs. But I couldn't wrap my head around the problem.

I am so used to Simulink where I can have a continuous signal which I can move to the workspace and sample easily. Now in python, what I am struggling with is producing an "analog" signal. I need to have the analog signal so that I can sample it at 50 Megs to see the performance of the digitization.

What am I missing?

Edit: I have a capacitor discharge that takes 200 usecs. I will be acquiring this signal with hardware. But before selecting the hardware I wanted to see if 50 Msps is a sufficient sampling rate for my requirements.

• Could be, of course. I am struggling to replicate that analog signal that is available in Simulink. I couldn't find a way to produce an analog signal, or even if it is possible. Do you have any recommendations for me? Aug 22, 2022 at 12:14
• Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
– Community Bot
Aug 22, 2022 at 12:27
• Please edit your question with an example continuous-time signal that you wish to sample -- i.e. if you just want $sin(2 \pi 5\mathrm{kHz} t)$, then there it is. Note that Simulink doesn't generate continuous-time signals -- it just generates a function of time, then calculates that function for the time intervals it's decided it needs to sample. Aug 22, 2022 at 13:30
• Edited the question. sin(2π5kHzt) this is what I tried as well. Aug 22, 2022 at 14:05

and welcome to SE.SP!

You need to learn the difference between analog and digital signals. You can google this of course.
In a nutshell, an analog signal is a continuous signal representing some other quantity, i.e., analogous to another quantity (source: wikipedia). You could coarsely say that analog signals only exist in the physical world. Sound, light, voltage, temperature: these are signals that are continuous in time.

When we want to analyze an analog signal with digital devices such as computers, that can only represent signals as a set of discrete (the opposite of continuous) numbers, we need to sample this signal through the use of an ADC (Analog to Digital Converter), the result being a sequence of samples that the computer can store.

What you're asking is therefore impossible. Once the signal is in computer memory, it's already sampled. It's not continuous anymore, it's digital.

As such, in your case, the 5KHz signal you mention is either already sampled at some sampling frequency defined by whatever ADC was used to convert the analog representation of its physical quantity into a digital representation through sampling, or it has been generated by software (see @Tim Wescott's comment on your OP).

What you might be trying to do is to resample your signal, i.e modifying the sampling rate, but I won't go further into this since you really need to understand the absolute basics first.

Let me know if you need more explanation.

EDIT: Sampling rate requirements You need a sampling rate that's AT LEAST twice your signal's bandwidth of interest (Nyquist-Shannon theorem). So if you're interested in a 5KHz signal, 50MHz is overkill. In fact, the theory would tell you that a sampling rate of 10KHz is enough. Of course that's the theory, in practice you'd want to sample at a rate higher than that. Not sure what sampling rates your ADC supports, but 16KHz is a typical one, and in your case would do the trick.

• Thanks for the answer. I may have used incorrect terms. I have edited the question now. I mainly have a 200 usec discharge I want to capture. I am trying to decide on a sampling rate for hardware. I wanted to do some simulations in this regard Aug 22, 2022 at 14:07
• @Guarneer Edited my answer in this regard
– Jdip
Aug 22, 2022 at 14:41
• Yes I am aware of the Nyquist rule but I have strict requirements so I need to know many data point during the discharge. Aug 22, 2022 at 14:43
• what are your "strict requirements"? The answer to your original question as stated is just a resounding YES, 50MHz sample rate is ENOUGH to capture a 5KHz signal. But I don't think that's what you actually mean to ask. A discharge of $200\mu s$ would only contain one period of a 5KHz signal. Your question needs to be re-written. As it is, there's not much we can help you with.
– Jdip
Aug 22, 2022 at 14:48
• If you know your signal's bandwidth, and you know the nyquist rule, then what else do you need?
– Jdip
Aug 22, 2022 at 14:49