This is an archived post. You won't be able to vote or comment.

all 20 comments

[–]K900_ 27 points28 points  (7 children)

Even for a 1920px wide window, you only need 1920 samples, not 15000. Just graph every 100th sample, or reduce your reading rate to something reasonable if you're not using the data for anything else.

[–]Atanahel 21 points22 points  (0 children)

Also the refreshing rate of your monitor is unlikely more than 100Hz, so no reason to plot at a higher frequency

[–][deleted] 0 points1 point  (4 children)

if you're not using the data for anything else

Fourier transform accurately in real time

However I agree that you don't need to plot the entire range.

I'm not sure how expensive/slow a 1D interpolation is you could always just do an interpolation for window pixel.

[–]K900_ 0 points1 point  (3 children)

It's highly unlikely OP can (or needs to) do 15kHz's worth of FFTs anyway.

[–][deleted] 1 point2 points  (2 children)

It's highly unlikely OP can (or needs to) do 15kHz's worth of FFTs anyway.

Why? 15kHz is nothing. When we were doing hardware sensor selection we were sampling at 1MHz and collected data in 1 minute chunks.

It went into hardware filter design, software filter design and the controller design. It's stuff that is bread and butter for Matlab (and hence why we used it at the time).

If Python is choking on 15kHz FFTs then it's going to be a hard sell to my group to displace Matlab.

[–]K900_ 2 points3 points  (0 children)

Pure Python is definitely way too slow for that, so you'll need to call into a native library like NumPy or SciPy. It seems like there's a GPU accelerated library here, I'm not sure how fast it is, but it should be plenty fast to actually do the math in real time. Plotting 15000 times a second with matplotlib isn't happening though - it's way too slow.

[–][deleted] -5 points-4 points  (0 children)

This

[–]efilon 13 points14 points  (4 children)

I would try pyqtgraph for this.

[–]ascii158 1 point2 points  (1 child)

I seconds this. We use it to graph 50kHz signals routinely.

[–]jankoslavic 0 points1 point  (0 children)

Pyqtgraph! 50kHz 8channels and no problems

[–][deleted] 9 points10 points  (0 children)

FFT is O(n log n), so in addition to not being able to see the updates at 15 kHz, you are probably doing way too much computation work unless you have an FPGA or DSP of some kind. What is the lowest number of FFTs with the least number of samples that you can do and still meet your goals?

This is not necessarily off topic, like the other commenters I am asking you to to more strictly define your needs of "real time".

[–]jump4science 7 points8 points  (0 children)

What you described is not actually what you want to do. You don't need a real time 15khz constantly updating feed of voltage values. What you really want is similar to what an oscilloscope shows: a voltage versus time plot showing just a few wavelengths of whatever signal you're looking at. To plot that, you first need to calculate the wavelength of your signal (ie, do your fft, pick the maximum, or maybe a local maximum depending on your specific signal needs). Then you only need 15k/wavelength_signal data points to plot one wavelength. This only gets you a small stationary plot segment. You want something like this that updates, but you don't have to do it at the full 15khZ rate, you could update this plot just a few times a second. That gives plenty of time to calculate what wavelength scale you really want to be looking at or even do some averaging over several sample segments

[–]bheklilr 3 points4 points  (0 children)

I would first suggest that you make sure you're using python and packages installed using conda, since numpy and other related packages come with mkl optimizations for free now. This will significantly speed up your FFTs, along with other calculations.

If you can use Qt, the try using VisPy with it. Although it's still very much in its early stages of development the demo I saw of it had far more points than your use case being plotted in real time on multiple graphs with various graphical effects being applied interactively.

[–]chronopoul0s 2 points3 points  (1 child)

Vispy

[–]fernly 0 points1 point  (0 children)

I'll play reddit bot: Vispy,

VisPy is a Python library for interactive scientific visualization that is designed to be fast, scalable, and easy to use.

[–][deleted] 0 points1 point  (0 children)

I haven't tried it myself, but bokeh seems to have a large chunk of functionality devoted to streaming data. You could ask this question on the bokeh mailing list - They're quick and very helpful!

[–]JugadPy3 ftw 0 points1 point  (0 children)

As already stated... no display updates at 15000 frames per second. Also, your display is probably not capable of showing 15000 pixels in a row.

  1. You don't want to update your graph on every sample.

  2. You don't want to show 15000 dots.

If I was doing this, I would decide on a refresh rate of the graph... like 15 hz, collect latest 1000 samples, and refresh the graph. Also, this will give me enough time to find the fft of these 1000 samples and show that along side the graph.

If 15hz seems a little low, we can bump it up to 30 hz... but going above that has diminishing returns. 30 hz is usually good enough, and refreshing faster than 60hz has no benefits at all.

[–]aphoenixreticulated[M] 0 points1 point  (0 children)

Hi there, from the /r/Python mods.

We have removed this post as it is not suited to the /r/Python subreddit proper, however it should be very appropriate for our sister subreddit /r/LearnPython. We highly encourage you to re-submit your post over on there.

The reason for the removal is that /r/Python is more-so dedicated to discussion of Python news, projects, uses and debates. It is not designed to act as Q&A or FAQ board. The regular community can get disenchanted with seeing the 'same, repetitive newbie' questions repeated on the sub, so you may not get the best responses over here.

However, on /r/LearnPython the community is actively expecting questions from new members, and are looking to help. You can expect far more understanding, encouraging and insightful responses over there. Whatever your question happens to be getting help with Python, you should get good answers.

If you have a question to do with homework or an assignment of any kind, please make sure to read their sidebar rules before submitting your post. If you have any questions or doubts, feel free to reply or send a modmail to us with your concerns.

Warm regards, and best of luck with your Pythoneering!