Hot answers tagged

38

filtfilt is zero-phase filtering, which doesn't shift the signal as it filters. Since the phase is zero at all frequencies, it is also linear-phase. Filtering backwards in time requires you to predict the future, so it can't be used in "online" real-life applications, only for offline processing of recordings of signals. lfilter is causal forward-in-time ...


24

Isn't white noise supposed to have a flat magnitude response? (equal amounts for all frequencies) The expected magnitude response of white noise is flat (this is what JasonR calls the power spectral density). Any particular instance of a white noise sequence will not have precisely flat response (this is what JasonR's comment refers to as the power ...


16

i'm not gonna deal with python nor numpy nor any other parochial computational platform. first, since "silence" is a perceptual property, you need to apply a weighting filter, such as A-weighting to boost the frequency components of the audio that our ears are more sensitive to and attenuate the portions we're less sensitive to. there are other weighting ...


16

You have a bug in ft2. You are incrementing i, and freq together. That's not how you want your summation to work. I messed around with fixing it, but it got messy. I decided to rewrite it from a discrete perspective instead of trying to use the continuous terminology. In the DFT, the sampling rate is irrelevant. What matters is how many samples are ...


12

It's not only about programming language but library you are using. I can think of the following: MATLAB - image processing capabilities are quite ok, but for more advanced and real time processing you would need some low-level stuff. Additionally, it does not offer very good portability. Mathematica - good for prototyping and quick visualization, but ...


11

Personally I find Python one of the best choices out there and did myself some work in area of audio identification. You are welcomed to check for instance my software for automatic identification of birds from noisy audio recordings: Ornithokrites. The program is used by Department of Conservation of New Zealand and they are happy about it. Based on this ...


10

You should not be using the analog filter - use a digital filter instead. You want the filter to be defined in Z-domain, not S-domain. Also, you should define the time vector with known sampling frequency to avoid any confusion. The design of the digital filter requires cut-off frequency to be normalized by fs/2. Here is a working example: import numpy as ...


8

What's not clear to me is what the fundamental difference (if any) is between simulating an analog filter and making a digital filter. Either way, these functions will produce "ba" transfer function outputs, but the b and a are totally different. For a 2nd-order filter, for instance, b = [b0, b1, b2] and a = [a0, a1, a2]. These are the coefficients of the ...


8

Answer by @endolith is complete and correct! Please read his post first, and then this one in addition to it. Due to my low reputation I was unable to respond to comments where @Thomas Arildsen and @endolith argue about effective order of filter obtained by filtfilt: lfilter does apply given filter and in Fourier space this is like applying filter transfer ...


8

Is this meant to happen? Yes, that is absolutely a well known effect of using any window function. Taking a look through the Wikipedia article on window functions, we find that the rectangular window has the sharpest peak. This is quite simply due to the fact that the rectangular window acquires the most data, meaning that it can distinguish between ...


8

The steps for calculation of PSNR value of two images: For details click here import numpy import math import cv2 original = cv2.imread("original.png") contrast = cv2.imread("photoshopped.png",1) def psnr(img1, img2): mse = numpy.mean( (img1 - img2) ** 2 ) if mse == 0: return 100 PIXEL_MAX = 255.0 return 20 * math.log10(PIXEL_MAX / ...


8

I found the answer finally. I found a great article that explains many different libraries that can be utilized for peak detection. I now have the peaks I am really interested in, and can now create the output I am requiring. Finding Peaks in Python


8

Parseval's theorem will hold, but take into account that your signal in the time domain will no longer be $x[n]$. Namely, if you have that $$\sum_{n=0}^{N-1} \Big| x[n] \Big|^2 = \frac{1}{N} \sum_{k=0}^{N-1} \Big| X[k] \Big|^2$$ then, if you window the signal $x[n]$ with a window $w[n]$, your signal will now be $\hat{x}[n]=x[n]w[n]$, and the theorem will ...


8

Since this is a constant spectrogram, you could just as well have just averaged the |FFT|² and plotted that! (The most colorful way of visualizing things isn't always the optimal one; your signal doesn't change over time, so you don't need the time axis of the spectrogram at all.) Quite possibly, in that "easier" representation, you would have ...


7

I would recommend doing some proper reading of books/tutorials etc on the Fourier transform and the Discrete Fourier Transform (DFT). You will also want to look at filters and probably convolution for the bandpass filter. But regardless, here's some info that should help with your current state: Use matplotlib to plot the FT that you've calculated: fs = ...


7

This can be easily done in R or Python. There are well-tested functions available, so you don't have to worry about any boundaries or nuances. Moreover, both are free and popular among scientists. Solution for R There is a special package to handle spectral data, called hyperSpec. The rubberband baseline correction is already implemented there (function ...


7

The recent works I am aware of make use of tools that go beyond mere gradients. Here are a few references that could be starting points: S3: A Spectral and Spatial Measure of Local Perceived Sharpness in Natural Images, 2012, with examples of sharpness maps and Matlab code (that could be converted to Python) This paper presents an algorithm designed to ...


7

You can use cv2.PSNR like this example: import cv2 img1 = cv2.imread('img1.bmp') img2 = cv2.imread('img2.bmp') psnr = cv2.PSNR(img1, img2)


7

Your signal recording clearly shows that you have long streaks of 1.0 – that probably means you're clipping. Your signal is thus broken. Make a new recording with less gain.


7

Change the following line : time1 = np.linspace(0, capture_size1 * timestep1, capture_size1) To the following: time1 = np.linspace(0, capture_size1 * timestep1, capture_size1, endpoint=false) You will see correct results. Your original time instances is not what you intend because Python will create 2048 equally spaced point between 0 and 2048*Ts. ...


7

[EDITED FROM DISCUSSION] On the first order, your data looks like a decay with a positive origin on a small-valued range $[0.7 \; 0.49]\times 10^{-7}$, and very tiny fluctuations with respect to the area under the curve. So from afar, your data is much closer to an almost constant function than to some putative oscillations. So the the zero, or DC-...


7

Yes, Butterworth are IIR. The decay from an impulse technically lasts forever. Yes, all [implementable] IIR are causal. Yes, because of #1 and #2. Don't use signal.filtfilt. Use signal.lfilter. filtfilt does the same thing as lfilter, except twice, in opposite directions, which changes a causal filter into a zero-phase filter. However, as the ...


6

I only need the total group delay, not spectrum of group delay. Group delay is a spectrum, so this doesn't make sense. The group delay is the derivative of the phase response of the filter, so in Python it can be calculated as from scipy import signal from numpy import pi, diff, unwrap, angle w, h = signal.freqs(b, a) group_delay = -diff(unwrap(angle(h))...


6

I'm by no means an expert in this, but I find the subject of compressed sensing very interesting, so I thought it'd be fun to play around with this. I believe your error is in the generation of your sampling matrix, $\Phi$. According to the paper you reference "The convergence of this algorithm was proven in [1] under the condition that $\|\Phi\|_2 < 1$ ....


6

If I understand correctly, you don't need the intrinsics or extrinsics to achieve that, if a top-down view is all you want. You could basically define 4 points on your parallel lines and then warp the entire image into a canonical view (say $\{\{0,0\}, \{480,960\}\}$). To do that in OpenCV, all you need to do is compute the homography using findHomography ...


6

The rfft function returns complex values ordered in specific way. In order to retrieve the amplitude of your DFT you must take the absolute value of it. Easiest way to do that is to call y_a = np.abs(y). I also noticed in your case that you are using fftfreq function to obtain corresponding frequency vector. In case of rfft you must use the rfftfreq. This ...


6

Do I have to filter the whole (or at least a huge bit) of the signal every time a few new samples came in or is there a way (like the sliding DFT) where it is possible to efficiently determine the new part of the filtered signal? Digital filters don't work like that -- basically, classical FIR or IIR can work on every single new sample. You should really ...


6

Well, in continuous time, a sinusoid with a bias can be seen as the output of the linear system \begin{align*} \begin{bmatrix}\dot x_1\\\dot x_2\\\dot x_3\end{bmatrix} &= \begin{bmatrix}0 & 1 & 0\\-\omega^2&0&0\\0 &0 &0\end{bmatrix}\begin{bmatrix}x_1\\x_2\\x_3\end{bmatrix}\\ y &= \begin{bmatrix}1&0&1\end{bmatrix} \...


6

Ideal derivative filter Let $f(x)$ be a signal bandlimited to frequencies $(-\pi,\, \pi)$. Given $f(x)$ as input, the same $f(x)$ is given as output by a system that has as its impulse response the sinc function: $$\operatorname{sinc}(x) = \left\{\begin{array}{ll}1&\text{if }x = 0,\\ \frac{\sin(\pi x)}{\pi x}&\text{otherwise.}\end{array}\right.\tag{...


Only top voted, non community-wiki answers of a minimum length are eligible