# Tag Info

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

It works fine for me: from scipy.signal import hilbert import numpy as np from matplotlib.pyplot import plot sensor = np.loadtxt('signal.txt') plot(sensor) analytical_signal = hilbert(sensor) plot(analytical_signal.real) plot(analytical_signal.imag) amplitude_envelope = np.abs(analytical_signal) plot(amplitude_envelope) What are you doing differently? ...

5

You need to set the cmap properties of the imshow() function: https://matplotlib.org/devdocs/api/_as_gen/matplotlib.pyplot.imshow.html Use: plt.imshow(img, cmap = "gray")

5

This is simply how Discrete Fourier Transform (i.e. Fourier Transform theory applied on sampled signal) works. You get an output of length N if your input has length N, and after removal of symmetric part, what you get are $\frac{N}{2}$ points that span frequencies 0 (DC component) to Nyquist frequency ($\frac{F_s}{2}$). For this same reason, the more ...

5

You can, but... you'll need to keep symmetry if your original time-domain signal is real-valued. If a signal $x$ is real-valued, then its DFT $X$ will exhibit complex-conjugate symmetry: $$X[k] = X^*[N-k].$$ So you can generate $N$ Gaussian pseudo-random noise samples, $g[n]$, and place them in the frequency domain noise vector, $\epsilon$ as: $$\... 5 Suppose you have initially a real-valued sequence x of length N. The function is basically doing this: To upsample, it transforms to the frequency domain and adds N/2 zeros at the end. Then it transforms back to the time-domain. To downsample, it transforms to the frequency domain and deletes the second and third groups of N/4 elements (which correspond to ... 5 Minimum phase filters will not give you a near constant group delay. You can design a non-linear phase FIR filter with a linear desired passband phase with a specified group delay that is smaller than the group delay of the corresponding linear phase filter. If you use a least-squares criterion, this is equivalent to solving a system of linear equations. As ... 4 The default parameters of signal.spectrogram are: nperseg = 256 noverlap = nperseg/8 = 32 This means that: The length of analysis window is 256 samples (256/250 = 1.024 second) The overlap between consecutive windows is 32 samples (32/250 = 0.128 second) The timestamps returned by signal.spectrogram correspond to the centres of a window. So in ... 4 You need to specify your filter design specifications parameters consistently for either an analog or a digital filter. With your posted code, the butterord computes the required order for a digital filter with cutoff frequencies near 1 (which would make sense as Nyquist-normalized cutoff frequencies, but not so much in Hz), then uses those directly to ... 4 A DCT is equivalent to a DFT of real data that is doubled and mirrored, thus rendering it symmetric. The DFT of any symmetric real signal has a phase of zero (its all cosines, no antisymmetric sine components). 4 Not really, as the transform is real. However, one could interpret the sign as a poor man's phase, being "quantized" or restricted to values 0 or \pi. In other words, 1 = 1.e^{0.\imath} and -1 = 1.e^{\pi.\imath}. [EDIT] There are some instances where people use the sign of DCT or (real) wavelet coefficients, for subpixel image registration or ... 4 Standard Savitzky-Golay filters are linear phase (type I) FIR filters. So they have an odd number of filter coefficients 2N+1, and the delay equals N. For a good overview of Savitzky-Golay filters see this article by Ronald Schafer. For the definition of the four types of linear phase FIR filters see this answer. 4 When calculating the frequency correctly as the inverse of the period, instead of the inverse of the period times 2 pi, the fft does indeed give the expected answer. 4 Is there an invertible low-pass filter No is there something particularly difficult about inverting a low-pass filter? Yes. Digital low pass filters (in the most common sense) have a zero at Nyquist which means that the inverse has infinite gain at Nyquist and is unstable. Seemingly having two identical coefficients in b as the first and only ... 3 By converting to np.int16, you're hitting integer overflow and wrapping the values around. I assume this is not intentional, since the output looks much more sane without it. int16 is limited to values from −32,768 through +32,767, but the output of the convolution goes from −1,255,891,038 to +2,459,046,088: np.int16: np.int64: You can make your test ... 3 Reading the documentation for scipy.signal.spectrogram I noticed that it does not do any kind of periodogram averaging. It simply splits up the signal into (possibly overlapping) segments, computes the magnitude of the DFT and plots it in each column of the STFT matrix. For your application I would recommend looping through non-overlapping segments of the ... 3 maybe you can do it from bottom to top or top to bottom using something like the following. a notation about notation: x[n] is the input sample for the n-th sample. this originally comes from an A/D converter, but may have come from a sound file. x_1[n] and x_2[n] are two separate inputs. y[n] is the output sample at the n-th time. it will ... 3 Do it using the following steps: Look for the optimal frequency for the Low Pass Filter. Usually close as possible to the bandwidth of your desired signal. Design an LPF filter according to the frequency above. If you're after Gaussian based filter you need to optimize the STD ( \sigma ) parameter. Apply the filter either using convolution, Using Numpy's ... 3 Have you tried just median filtering the data ? That's what I'd try as a first step. Winsorizing really doesn't work on a data set that has a changing mean. It looks like python has scipy.signal.medilt to perform this. 3 In general, if you have complex spectrum and need PSD in dB the mathematical equation is$$P_{xx} = 20\cdot\log_{10}|X_{x}|, where $P_{xx}$ is your PSD in dB and $X_{x}$ is your complex STFT spectrum (variable Spectro in your case). In SciPy documentation for scipy.signal.spectrogram is mentioned, that you can compute spectrogram with different modes (...

3

I normally use the Welch method to calculate and plot the PSD of a signal. signal_f, signal_psd = sp.welch(signal, sampling_frequency, return_onesided=False, nperseg=256) signal_f = np.fft.fftshift(signal_f) signal_psd = np.fft.fftshift(signal_psd) plt.semilogy(signal_f, signal_psd, label = 'PSD') Maybe it helps you!

3

With an IIR filter, the higher the ratio is of sampling frequency to bandpass filter frequency, the closer the poles are to the complex unit circle in the Z-transform. Poles close to the unit circle can produce numerical instabilities (ill conditioned computations) when computing the filters response. This is because any numerical quantization or "rounding ...

3

As others said in the comments, this looks like numerical error. 3rd-order filters are not typically prone to this, but the higher your sampling frequency, the closer the poles move to +1: You might benefit from splitting this into second-order sections. The easiest way is to use output='sos' and sosfreqz() and sosfilt(), which handle the splitting ...

3

I am not a good Python coder, but did similar processing in Matlab in the past. The subject has been discussed in SE.DSP in several instances, for instance Librosa stft + istft - Understanding my output. Tools seem to exist: scipy.signal.istft: Perform the inverse Short Time Fourier transform (iSTFT). librosa.core.istft: Inverse short-time Fourier ...

3

Hm well, technically it is some kind of envelope: it oscillates between hilbert(x) and -hilbert(x). Your examples (dashed lines are $\pm$hilbert(x)): I'm assuming you're looking for something smoother. Matlab has a function called envelope where you have various ways of controlling how the envelope is extracted. Not sure if there is a Python equivalent. ...

3

I don't know much about this semantics? of WAV files but their numerical format is the following. (assuming mono) Given a recording with 8-bit per sample precision, then those samples are unsigned integers taking values between $0$ and $255$. Due to being unsigned, to represent negative values, there is a bias of $128$, and the sample values are actually ...

3

I am doing something similar to your application with 1D CNN. I think scipy.resample_poly is the most versatile function since it allows both upsampling, downsampling, or a combination of both. Also your comment about "values beyond the boundary of the signal to be zero" can be solved by using the option "line" in padtype, as shown in the function ...

2

In lfilter the transfer function is described in decreasing powers of z, as shown below copied from the python doc for signal.lfilter: -1 -M b + bz + ... + b[M] z Y(z) = -------------------------------- X(z) -1 -N a + az + ... + a[N] z While the parameters B ...

2

You can do different things: For example, use the (frequency-symmetric) real-tapped bandpass that firwin gives you, and after applying that, apply a complex high pass (a Hilbert filter, essentially) to kill all negative frequencies. That sadly leaves you with the original problem (finding a complex-tapped filter using scipy) Do the same as above, but ...

2

As far as the digital signal is concerned, the signal only exists uniquely in one Nyquist interval (which is $-f_s/2$ to $+f_s/2$ where $f_s$ is the sampling rate. Every other interval, such as in your range of interest that is well above the sampling rate, is a replica of the primary interval. Given that, note that the range from $f_s/2$ to $f_s$ is the ...

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