Skip to main content
10 votes
Accepted

How to get scipy remez to give matlab firpm answer?

The firpm and remez commands return symmetric linear phase filter solutions. In order to create a symmetric linear phase high pass filter, you must have an odd number of taps (Type 1 filter, see chart ...
Dan Boschen's user avatar
8 votes
Accepted

Why is Scipy implementation of Hilbert() function different from Matlab implementation of the function?

It works fine for me: ...
endolith's user avatar
  • 16k
8 votes
Accepted

Are IIR filters (and specifically Butterworth filter) causal?

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 ...
endolith's user avatar
  • 16k
8 votes
Accepted

Scipy filter analog vs. digital

The function butter() doesn't do any signal processing. It is a routine to design a filter, either digital or analog. I.e., it computes the filter coefficients. I ...
Matt L.'s user avatar
  • 92.5k
8 votes
Accepted

Why is implementing a digital LPF with low cutoff frequency but high sampling frequency infeasible?

Also, any advice related to how to implement a 100 Hz cutoff LPF on a signal with a high sampling frequency would be appreciated. Easy: use second order representation (...
Hilmar's user avatar
  • 48.2k
7 votes
Accepted

Scipy resample, "fourier method" explanation

Suppose you have initially a real-valued sequence x of length N. The function is basically doing this: To upsample, it ...
Tendero's user avatar
  • 5,040
7 votes

Amplitude extraction using STFT

Firstly, STFT is fundamentally a time-frequency transform: convolutions with windowed complex sinusoids (i.e. bandpass filtering). You aren't going to "frequency", and "windowed Fourier ...
OverLordGoldDragon's user avatar
7 votes

Why is implementing a digital LPF with low cutoff frequency but high sampling frequency infeasible?

In addition to Hilmar's good comments in his own answer, see this question as well as Rick Lyon's interesting blog post which shows similar pole pattern graphs, demonstrating why very low cut-off ...
Dan Boschen's user avatar
6 votes
Accepted

Designing digital low pass filter with low pass-band group delay

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 ...
Matt L.'s user avatar
  • 92.5k
6 votes
Accepted

Why does scipy introduce its own convention for H(z) coefficients?

I agree with the OP's annoyance in that two conventions are used and believe it comes down to what is commonly used in filter design vs what is commonly used in control systems. However the only ...
Dan Boschen's user avatar
5 votes
Accepted

Calculating values of frequency bins in Python

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 ...
H. Rev.'s user avatar
  • 191
5 votes
Accepted

How to generate random samples of Gaussian distribution directly in the frequency domain?

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^*...
Peter K.'s user avatar
  • 26k
5 votes
Accepted

Write a 440 Hz Sine Wave to .wav-File using Python and SciPy

After some experimenting I came up with the following: ...
Tim Hilt's user avatar
  • 211
5 votes
Accepted

Invertible low-pass (Butterworth) filter in python (scipy)?

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 ...
Hilmar's user avatar
  • 48.2k
5 votes
Accepted

IIR design: SciPy CMSIS-DSP coefficient format

scipy.signal returns a sos matrix when you set output='sos', which is cascaded second-order sections and has a shape of ...
ZR Han's user avatar
  • 3,263
5 votes

How does SciPy's Welch function change the shape of the data?

Assuming that "6041" is a typo and it's actually "6401" that would be expected behavior. The result of welch() is a frequency domain vector the ...
Hilmar's user avatar
  • 48.2k
5 votes

Scipy and Matlab Spectrogram not matching

It’s a scaling problem, for which there are two options: Option 1: Use PSD scaling for both Python and Matlab Use mode='psd' in the ...
Jdip's user avatar
  • 6,814
4 votes

Issue with the time vector returned by $\tt signal.spectrogram$ function

The default parameters of signal.spectrogram are: nperseg = 256 noverlap = nperseg/8 = 32 This means that: The length of ...
jojeck's user avatar
  • 11.2k
4 votes

Do DCT results contain phase spectrum?

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 ...
hotpaw2's user avatar
  • 35.7k
4 votes

Do DCT results contain phase spectrum?

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 =...
Laurent Duval's user avatar
4 votes

Why is Scipy implementation of Hilbert() function different from Matlab implementation of the function?

You have to detrend the signal. If you have a DC component the behauviour changes completely. ...
Fern's user avatar
  • 51
4 votes

Welch spectrogram

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 (...
Atul Ingle's user avatar
  • 4,144
4 votes
Accepted

How to calculate the PSD from the complex calculated STFT?

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 ...
Lukas Krauz's user avatar
4 votes

Delay in Savitzky-Golay filtering

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 ...
Matt L.'s user avatar
  • 92.5k
4 votes

Python Hilbert does not seem to calculate the envelope

Hm well, technically it is some kind of envelope: it oscillates between hilbert(x) and -hilbert(x). Your examples (dashed lines ...
Florian's user avatar
  • 2,463
4 votes

What Are The Semantics Of Wav-File Sample Values?

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 ...
Fat32's user avatar
  • 28.4k
4 votes
Accepted

Apply FFT to positive spiky signal

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.
Idr's user avatar
  • 143
4 votes
Accepted

Are scipy second-order Gaussian derivatives correct?

Ndimage generates a Gaussian kernel by sampling a Gaussian and normalizing it to 1. The derivative of this kernel is generated by modifying that normalized kernel according to the chain rule to ...
Cris Luengo's user avatar
  • 2,770
4 votes

Why does changing the format of an audio file from int16 to float produce jitter?

The reason for this is that wavfile.write supports different number ranges for different data types. The Valid ranges are WAV format Min Max NumPy dtype 32-bit ...
cosinusalpha's user avatar
4 votes
Accepted

Constraints on number of taps in a FIR filter vs. FFT length

I think you got it backwards: the number of taps is determined by your filter requirements (cutoff frequency, steepness, attenuation, etc). The FFT length is then derived from the filter length, not ...
Hilmar's user avatar
  • 48.2k

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