text
stringlengths
81
47k
source
stringlengths
59
147
Question: <p>I am working on analysis of baby cry signal. fundamental frequency(Fo) of signal is already estimated using auto correlation and cepstrum analysis. cry signal is inputted in .wav format. now i want to do short time fourier transform analysis of same signal inorder to find variations in fundamental frequency over the time and plot its "pitch contour". i.e. Fo v/s t. its like finding Fo value for each small interval and plotting over time to see the variability. pls, can anybody help me with the matlab code? </p> Answer: <p>Have a look at <a href="http://labrosa.ee.columbia.edu/projects/SAcC/" rel="nofollow">SAaC</a> from <a href="http://labrosa.ee.columbia.edu/" rel="nofollow">LabROSA</a>. You also might be interested in <a href="https://github.com/dpwe/pitchflow" rel="nofollow">delta pitch without explicit pitch tracking</a>.</p>
https://dsp.stackexchange.com/questions/22558/short-time-fourier-transform-analysis-of-newborn-baby-cry-signal
Question: <p>I'm trying to detect rapid changes in a one-dimensional signal say <span class="math-container">$[0,1]\ni t \mapsto f(t) \in [-1,1]$</span>. By rapid changes, I mean corner points, edges, or sharp transitions at a point for example the signal switches from a value <span class="math-container">$-1$</span> to <span class="math-container">$+1$</span> on a point.</p> <p>For this, I'm using the STFT i.e., the Short-Time Fourier transform using some window functions (see Foundations of Time-Frequency Analysis by Grochenig, Chapter 3).</p> <p>My question is:</p> <p>Is there any justification or estimate indicating for what classes of signals STFT can provide some kind of qualitative answer about the discontinuity detection accuracy? I see that mathematically STFT can be applied for any <span class="math-container">$L^2([0,1];[-1,1])$</span> class of signals which can be very wild. But how does the data derived from an STFT, i.e., the time-frequency plot indicates, <strong>mathematically</strong> which part of the signal is jittery or at which point the signal switches? Is there any formal results/theorems in this line?</p> Answer:
https://dsp.stackexchange.com/questions/86782/a-mathematical-justification-of-discontinuity-detection-using-stft
Question: <p>I am performing time-frequency analysis on electrophysiological data with complex morlet wavelets. Each decomposition in the attached figure shows <em>total power</em> following the onset of a stimulus (top row) or preceding an eye movement (bottom row). There is a broadband, transient increase in power following stimulus onset. </p> <p>I am interested in determining whether there are frequency-specific changes in power (i.e., 'oscillations') during the 0-200 ms epoch as well; therefore, I have parsed the total power into phase-locked and non-phase locked components. Because variability in response latencies may bleed into the estimate of non-phase locked power (<a href="http://www.fil.ion.ucl.ac.uk/~karl/Mechanisms%20of%20evoked%20and%20induced%20responses.pdf" rel="nofollow noreferrer">David et al. 2006</a>), </p> <p>I want to compute adjusted power as recommended by these authors (pg 1589). I am unsure of how to implement this orthogonalization in Matlab-- it is slightly beyond my mathematical savvy. </p> <p>I attached a snapshot of the related paragraph in the paper as well.</p> <p>Is anybody familiar with this computation? </p> <p><a href="https://i.sstatic.net/6880A.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/6880A.png" alt="Total Power"></a></p> <p><a href="https://i.sstatic.net/NwH55.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/NwH55.jpg" alt="Adjusted Power Computation"></a></p> Answer: <p>The notation and terminology in this and the <a href="http://www.fil.ion.ucl.ac.uk/~karl/A%20neural%20mass%20model%20for%20MEG.pdf" rel="nofollow noreferrer">closely related paper</a> could have been more simplified I think.</p> <p>To understand what's going on there, we need to start from page 1583. Specifically:</p> <ul> <li>$y(t)$ is basically your measured signal (the output from each neuronal population). A scaled version of that is what you would sense via some modality (in an ideal world).</li> <li>$s(\omega, t)$ is the frequency-time representation of a $y(t)$. This is <strong>complex</strong>.</li> <li>Given that this is about Event Related Responses (ERR): <ul> <li>$g(\omega, t)_T$ is the average <em>absolute value</em> of $s(\omega,t)$ after a number of trials. This is <strong>real valued</strong>.</li> <li>$g(\omega, t)_e$ is the average of $s$ times the average of the conjugate of $s$ (both of which will be complex, the result of which however will be <strong>real</strong>).</li> <li>These look similar but their magnitude is not.</li> </ul></li> <li>Then the explanation of the breakdown of that "power" follows. What this means is that, based on the <em>assumptions</em> in the paper, we think that the neuronal activity is due to three things: a) Background activity, b) Activity because of connections between neuronal populations and c) Induced activity by the stimulus. Furthermore, these three components are <em>assumed</em> <strong>orthogonal</strong>. This means that if one "happens", the rest do not. This is important for later on.</li> <li><strong>WHERE/WHEN</strong> this holds then we could estimate the background activity by looking at the spectrum BEFORE the stimulus onset, we could estimate the activity due to the stimulus (the part that is phase locked to the stimulus), because we know the "shape" of the stimulus and therefore what is left should be due to structural connections. <ul> <li>These are captured in $g(\omega, t))_i$ and $g(\omega,t)_T$.</li> <li>Notice here that the baseline is only $g(\omega)$</li> </ul></li> <li>So, when you arrive at equation 23, what you see is the explanation of that "adjustment" where: <ul> <li>$g(\omega,t)_T$ is the frequency-time representation of the averaged stimulus response after $T$ trials as before.</li> <li>$g(\omega,t)_e$ is the frequency-time representation "power of average" as before</li> <li>$\hat{\eta}$ now denotes the <strong>proportion</strong> of the frequency-time representation of $g(\omega,t)$ that is due to $g(\omega,t)_e$. The "trick" here is this, you have already <strong>assumed</strong> that the three components are orthogonal. <strong>WHERE/WHEN</strong> this holds, the "pseudoinverse" ($g(\omega, t)^+$) of a given $g(\omega, t)$ multiplied by the "shape" of the stimulus response $g(\omega,t)$ over the trials <a href="https://en.wikipedia.org/wiki/Moore%E2%80%93Penrose_inverse#Orthogonal_projection_matrices" rel="nofollow noreferrer">would be zero</a> and you would be left with the "shape" of the stimulus response. So, that $\hat{\eta}$ business there (and the subtraction) is what allows you to do that "separation".</li> </ul></li> </ul> <p>Perhaps it is now clear how to produce that $g(\omega,t)^+$. Provided that you have a given $g(\omega,t)_e$, invert it with <a href="https://www.mathworks.com/help/matlab/ref/pinv.html" rel="nofollow noreferrer"><code>pinv</code></a> (or anything else equivalent to a <code>pinv</code> in another platform).</p> <p>But, I wonder how effective would that be for what you are trying to do. Irrespectively of this specific technique, a "pulse" or a step or any abrupt change of a signal in the time domain usually has a broad representation in the frequency domain (whether that is Fourier or Wavelet, the point is that you need more components to synthesize the step). You are looking for "oscillations" in a 0-200ms interval. What is the frequency of the oscillations you are looking for?</p> <p>Hope this helps</p>
https://dsp.stackexchange.com/questions/49229/isolating-frequency-specific-oscillation-from-transient
Question: <p>After a lecture on harmonic analysis and time/frequency methods, I reconsidered the Gaussian kernel, defined in continuous time. </p> <p>It is unimodal and symmetric, and its continuous Fourier transform is another Gaussian, thus unimodal and symmetric (from <a href="https://stackoverflow.com/questions/5398304/fourier-transform-of-a-gaussian-is-not-a-gaussian-but-thats-wrong-python">Fourier transform of a Gaussian is not a Gaussian, but that's wrong!</a>):</p> <p><a href="https://i.sstatic.net/0DTr6.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/0DTr6.png" alt="Gaussian/Fourier "></a></p> <p>As a filter or a window, the Gaussian ensure a monotonic weight decay around its center. The interpretation in the frequency domain is similar: frequencies are monotonically attenuated away from a center frequency.</p> <p>Such a property allows a straightforward interpretation in both the time and the frequency domain.</p> <ul> <li>For continuous kernels, are there generic characterizations (necessary or sufficient conditions) under which unimodal and symmetric windows also have a unimodal and symmetric amplitude spectrum?</li> </ul> Answer: <p>This is only also partial answer. I translate unimodular into ripple-free, because ripples are essentially extremal points, and we just want to have a single one.</p> <p>A ripple-free Fourier Transform translates (to my knowledge) to an infinitely often continuously differentiable time-domain function. Furthermore, to let the Fourier Transform be defined easily, the function should either decay very quickly or should have compact support. Hence, candidate functions would be from the Schwartz space of functions. </p> <p>Unimodality further reduces the number of candidates, with the Gaussian being a prominent example. Others are Hermite Polynomials, weighted with the Gaussian. With a clever linear combination of Hermite function, you can create a function that is unimodal, different from a gaussian and still has ripple-free and symmetric Fourier transform.</p> <pre><code>import scipy.special %matplotlib inline Fs = 100 t = np.arange(-10, 10, 1./Fs) H = scipy.special.hermite g = lambda t: (H(4)(t)+H(2)(t)+80*H(0)(t)) * np.exp(-t*t) gauss = lambda t: np.exp(-t*t) plt.subplot(1,2,1) plt.plot(t, g(t)) plt.plot(t, 80*gauss(t)) plt.xlim(-4,4) plt.subplot(1,2,2) plt.plot(20*np.log10(abs(np.fft.fft(g(t), 7*len(t))))) </code></pre> <p><a href="https://i.sstatic.net/xZbDm.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/xZbDm.png" alt="Program output"></a></p> <p>I believe the ripples in the frequency are due to finite windowing and numerics. Might need more analysis with analytic solutions, e.g. from Mathematica.</p> <p>So, the answer might be: The window needs to be unimodular and stem from the Schwartz space of functions?</p>
https://dsp.stackexchange.com/questions/36247/conditions-for-symmetric-and-unimodal-windows-in-both-time-and-frequency-domains
Question: <p>I am reading </p> <p><a href="http://users.rowan.edu/~polikar/WAVELETS/WTpart3.html" rel="nofollow noreferrer">The Wavelet Tutorial</a></p> <p>Part III MULTIRESOLUTION ANALYSIS &amp; THE CONTINUOUS WAVELET TRANSFORM</p> <p>by Robi Polikar </p> <p>The author explains about the following fig and says;</p> <blockquote> <p>Note that boxes have a certain non-zero area, which implies that the value of a particular point in the time-frequency plane cannot be known. All the points in the time-frequency plane that falls into a box is represented by one value of the WT.</p> </blockquote> <p>I am unable to interpret this fig and also that why value of a particular point in the time-frequency plane cannot be known. I can always intersect two lines one passing through a particular value of t and another through f. The intersecting point will give me exact location of frequency at particular time (and V.V). I am not able to understand what thsi diagram is all about and what is its significance? </p> <p><img src="https://i.sstatic.net/Eegv5.gif" alt="enter image description here"></p> Answer: <p>I believe by the WT, you are talking about the discrete wavelet transform, DWT.</p> <p>This can be thought of as a subsampling of the continuous wavelet transform, CWT. In the case of the DWT, we pick frequencies of the form $2^{j-1}$ for ($j=1,2,\dots$) and then pick times seperated by multiples of $2^j$.</p> <p>You can see this in the diagram: As frequency increases, boxes double in height and half in width.</p> <p>I believe what the author means by the statement</p> <pre><code>Note that boxes have a certain non-zero area, which implies that the value of a particular point in the time-frequency plane cannot be known. </code></pre> <p>is that the DWT, is an 'averaging' of the CWT within the boxes i.e. the boxes represent only one value and that is the average of the the values within it from the CWT. Hence as the boxes have non-zero area, it is impossible to know any of the exact values making up this average, so it is impossible to know the exact value of any point in the time-frequency plane.</p>
https://dsp.stackexchange.com/questions/9319/trying-to-understand-wavelet-transform-frequncy-time-diagram
Question: <p>my research focuses on wideband spectrum sensing. I'm currently reading <strong>&quot;A Wavelet Tour of Signal Processing&quot; by Stéphane Mallat</strong>, and I find it very rich and foundational.</p> <p>My current approach is to:</p> <p>Read Mallat’s book carefully to understand wavelet theory, time-frequency analysis, and multiresolution.</p> <p>Then, move on to read research papers that apply these concepts to practical spectrum sensing and cognitive radio systems.</p> <p>My questions are:</p> <ol> <li><p>Is this a reasonable and efficient approach for building strong theoretical foundations?</p> </li> <li><p>Would you recommend focusing on specific chapters only?</p> </li> <li><p>Are there more targeted resources I should consider in parallel to better link wavelet theory with actual</p> </li> </ol> Answer: <p>Considering your very fundamental newer question, <a href="https://dsp.stackexchange.com/questions/96567/what-makes-wavelet-coefficients-large-similarity-with-the-wavelet-shape-or-sig/96575#96575">What makes wavelet coefficients large — similarity with the wavelet shape or signal irregularities?</a> , I'd say it's clear you need more reading on a textbook level, to build intuition and understanding, before you deep-dive into research papers, which all assume you've read a textbook and probably beyond.</p>
https://dsp.stackexchange.com/questions/96565/is-it-a-good-idea-to-start-with-wavelet-theory-before-reading-recent-spectrum-se
Question: <p>I want to do time-frequency analysis of a signal. So i decided to use <a href="https://docs.scipy.org/doc/scipy-0.16.0/reference/generated/scipy.signal.spectrogram.html" rel="nofollow noreferrer">spectrogram</a> function from scipy. This function returns, three parameters f,t,Sxx. I am using below arguements:</p> <ul> <li><p>x : my signal</p></li> <li><p>fs : 1000 Hz</p></li> <li><p>window : hann, with size = 300</p></li> <li><p>nperseg : 300, same as window size</p></li> <li><p>noverlap : 25</p></li> </ul> <p>My question is about returned time segments of this function.</p> <p>As far as I understand the first time segment for which we calculate fft must be 300 samples, then subtract 25 from it calculate fft for next window of 300 samples,and so on. So the signal of length 1s must be divided in 4 time segments. .275,.500,.775,1. , but the function returns :</p> <p><code>f,t,Sxx=spectrogram(sig1,fs=1000,window=get_window('hann',300),noverlap=25,scaling='spectrum',nperseg=300) t Out[172]: array([ 0.15 , 0.425, 0.7 ])</code></p> <p>can someone please suggest if I am thinking wrong or there is a bug in spectrogram function.</p> Answer: <p>As the returned value shows, the first spectrum is computed at time $t=0.15$ s. With a sampling rate of 1000 Hz, that means that the first analysis window is centred at sample $n=150$. So the first analysis frame spans the samples $n \in [0,300[$. </p> <p>Because your overlap is set to 25 samples, the second analysis frame spans the samples $n \in [275,575[$, thus overlapping in its first 25 samples with the first analysis frame. The second analysis frame is then centred at time $t=0.425$ s or in samples $n=425$.</p> <p>The third analysis frame again overlaps 25 samples with the second one. Thus, it spans the samples $n \in [550,850[$ and is centred at time $t=0.7$ s or in samples $n=700$.</p> <p>The next analysis frame would span the samples $n \in [825,1125]$ and is not computed because it would go over the range of samples in the input signal.</p>
https://dsp.stackexchange.com/questions/46516/scipy-signal-spectrogram
Question: <p>I want to do frequency analysis of audio data, basically trying to figure out what the notes are in a song algorithmically. The standard approach is to decode the MP3 into PCM data and run it through an FFT. However, notes below around middle C require too much precision for an FFT to work well. Since the MP3 already has frequency information in small time increments, is it a) precise enough to identify frequencies within about 2 - 5 Hz, and b) is there any code out that there does this conveniently? Most code (unsurprisingly) seems to convert it to the time domain, but I'd like to have just the frequency data.</p> Answer: <p>The MP3 encoder works on batches of 576 time-domain samples and converts them to 576 frequency-domain samples. That means that you get a frequency resolution of <span class="math-container">$\frac{f_\text{sample}}{576}$</span>, whatever your sampling rate is.</p> <p>Notice however how short that is at usual sampling rates, for example 44.1 kHz: that's a bare 13.something milliseconds. That makes a lot of sense – the frequencies produced by an excited string, membrane or air volume change over time after the excitation.</p> <p>So, no, your approach won't work: this resolution won't work to resolve your 2 Hz!</p> <p>Also, not going through the MP3 route and directly FFT'ing your audio signal can't work, either:</p> <p>To get a 2 Hz resolution in a linear frequency transform, you'll need 1/2 seconds of audio, no matter how you do it!</p> <p>Do the math: if you have a sampling rate of 44.1 kHz, and you want to resolve 2 Hz, you'll need to transform 44.1 kHz / 2 Hz = 22050 samples. These take 22050 / 44.1 kHz = 1/2 s to accumulate at that sample rate. It's the same for every other rate, too, because the sampling rate in the equation</p> <p><span class="math-container">$$T_{\text{recording}}=\frac{\frac{f_{\text{sample}} }{f_{\text{resolution}}}}{f_{\text{sample}}}$$</span></p> <p>always cancels.</p> <p>Now, you'll notice that a note lasting half a second in its pure form rarely happens.</p> <p>Furthermore, as I tried to explain in my comments:</p> <p>Your hypothesis that playing a note inserts power at but a single frequency is false.</p> <p>Instruments playing a note don't produce a single tone, but a mixture of multiple harmonics dampened by a changing envelope, also exposed to a drift in frequency over time. It's really not like you can go into a FFT and say, "OK, this was this and that chord played, easy to see". </p> <p>Things get even more complicated since you said you wanted to detect notes played in a chord: Since the individual oscillating elements (e.g. guitar strings) mechanically couple, you typically get further frequency components and a changed temporal behaviour.</p>
https://dsp.stackexchange.com/questions/58403/extract-frequency-data-from-mp3-file
Question: <p>For linear time-frequency representation, the resolution is limited by <a href="https://en.wikipedia.org/wiki/Gabor_limit#Signal_processing" rel="noreferrer">Gabor limit</a>. However, if interference is allowed, the resolution may be higher. What is the possible resolution in such a case? In "Electroencephalography Feature Extraction Using High Time-Frequency Resolution Analysis ", they stated </p> <blockquote> <p>We all know that the Wigner-Ville distribution achieves to the lower bound of the uncertainty principle and have the highest resolution in all time-frequency distributions</p> </blockquote> <p>Why is this statement true?</p> Answer: <p>The statement is true if you restrict it to all TF distributions in the <a href="http://en.wikipedia.org/wiki/Bilinear_time%E2%80%93frequency_distribution" rel="nofollow">Cohen Class</a>. That is rather easy to see, because the Wigner distribution generates all other distribution in that class by convolution with a non-negative time frequency kernel and therefore attains the minimal uncertainty.</p> <p>Beyond the Cohen class things get much more complicated. First of all, the very simple concept of uncertainty in the Cohen class is not necessarily useful for non-bilinear distributions. So it's not obvious how to even generalise the question. So statements that attempt to be more general than the Cohen class first need some clarification about mathematical terminology and possibly even concepts. Outside the Cohen class you will also find distributions without time-frequency translation invariance. If they're bilinear they can have a TF uncertainty that is just as good as the Wigner-Ville distribution. Dropping bilinearity too, you can even beat WV with reassignment distributions of all sorts.</p> <p>So summing up, the statement is true with the (possibly implcit) restriction to the Cohen class, which is the most common theoretical framework for TF distributions. Without that restriction it is not accurate.</p>
https://dsp.stackexchange.com/questions/17058/does-wigner-ville-distribution-provide-the-highest-resolution
Question: <p>Suppose a signal is a superposition of multiple intrinsic-mode-type (IMT) functions, say <span class="math-container">$$f(t) = \sum_{i=1}^n A_i(t)e^{i\varphi_i(t)} $$</span> Why is the separation condition of <span class="math-container">$f(t)$</span> be <span class="math-container">$$\forall i,j \quad|\varphi_i^\prime(t) - \varphi_j^\prime(t)| \geq \Delta$$</span> for some <span class="math-container">$\Delta &gt;0$</span>.</p> <p>There is an explanation in Time Frequency Analysis: Theory and Applications by Leon Cohen.</p> <blockquote> <p><a href="https://i.sstatic.net/I9qyX.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/I9qyX.png" alt="enter image description here" /></a></p> </blockquote> <p>It says that a monocomponent signal will look like a single mountain ridge and at each time the ridge is characterized by the peak. If it is well localized the peak is the instantaneous frequency. Also, the width of the ridge is the conditional standard deviation (actually about twice that), which is the instantaneous bandwidth. So the separation condition is clearly that the instantaneous bandwidth of each parts are much smaller than differences between instantaneous frequency.</p> <p>But I don't know why the peak of the ridge can represent the instantaneous frequency. Also, is there a rigorous proof of the separation condition ?</p> Answer: <blockquote> <p>why the peak of the ridge can represent the instantaneous frequency.</p> </blockquote> <p>The idea is that the peak in the frequency domain is the &quot;frequency&quot; of the signal. So if the frequency changes, the peak should move to be centered at the new frequency.</p> <blockquote> <p>Also, is there a rigorous proof of the separation condition ?</p> </blockquote> <p>Cohen just says:</p> <p><span class="math-container">$$ \left|\frac{A'_1(t)}{A_1(t)}\right| , \left|\frac{A'_2(t)}{A_2(t)}\right| \ll \left| \phi'_2(t) - \phi'_1(t)\right|$$</span></p> <p>in equation 13.21.</p> <p>Below is an attempt to visualize this. The blue plot is the absolute value of the FFT of a sinusoid. The orange plot is the same thing, but with the frequency varying. The green plot is the absolute value of the FFT of the sum of the two. As can be seen, when the frequencies are close, it's hard to see the two peaks in the green FFT.</p> <p>Exactly what the separation needs to be for the peaks to be able to distinguished depends on many factors. We'd need more information about the frequency variations before we can pin that down.</p> <p><a href="https://i.sstatic.net/2jp8H.gif" rel="nofollow noreferrer"><img src="https://i.sstatic.net/2jp8H.gif" alt="Animation of varying frequencies." /></a></p>
https://dsp.stackexchange.com/questions/81169/the-separation-condition-of-a-multi-component-signal
Question: <p>I'm reading the text book "Time-Frequency Analysis" by Leon Cohen and I've made my way through a decent portion. There is however a conceptual issue I keep coming back to. The book states:</p> <blockquote> <p>If we consider $\lvert s(t)\rvert^2$ as a density in time, the average time can be defined in the usual way any average is defined:</p> <p>$$ \langle t \rangle = \int t \lvert s(t)\rvert^2dt$$</p> </blockquote> <p>I don't understand conceptually why multiplying by $t$ in the integration will provide us with an average. I didn't know that was the typical way to define an average either despite the books insistence that this is common knowledge (which it very may well be I'm just not interpreting it correctly). I've always thought about an average as dividing by some base, say by the total period of time $T$ NOT multiplying by $t$ inside the integral. It states earlier that:</p> <blockquote> <p>$\lvert s(t)\rvert^2$ is the energy per unit time.</p> </blockquote> <p>So I was thinking that perhaps mathematically multiplying by $t$ which has units of $s$ would get rid of the per unit time portion, but the units of $\lvert s(t)\rvert^2$ aren't actually $v^2/s$ as that would be the derivative, it's just $v^2$ so that doesn't make much sense (assuming the signal is an electrical signal and the unit time is seconds). Can someone point me in the right direction on how to think about this? I know it's a simple concept but I'm just having trouble making it over this hurdle. Thanks!</p> Answer: <p>Take a signal defined on the real line, defined by the time location <span class="math-container">$t$</span>. Weight them locally at time <span class="math-container">$t$</span> by the energy of the signal, or squared magnitude <span class="math-container">$s|(t)|^2$</span>. A definition of <strong>some average time location of the signal</strong> can then be set as its <a href="https://en.wikipedia.org/wiki/Center_of_mass" rel="nofollow noreferrer">center of mass</a>. You can either look at it as a balance point (the signal's energy would be balanced putting the time line at the tip of your finger), or at a summary: it would be somehow equivalent to concentrate all the signal's energy at this point. </p> <p>Remember the discrete version for the center of mass <span class="math-container">$M$</span>for points <span class="math-container">$T_i$</span> with weights <span class="math-container">$w_i$</span>, <span class="math-container">$\sum_i w_i \neq 0$</span>: <span class="math-container">$$ \sum_i w_i\vec{T_i M} = \vec{0}. $$</span> Now look at a continuous formula like: <span class="math-container">$$ \int \lvert s(t)\rvert^2 \left( m - t \right) dt = 0$$</span> then the analogy is clear: <span class="math-container">$m$</span> would be the center of mass of "times" taken with an infinite summation. Solving for <span class="math-container">$m$</span> gives you: <span class="math-container">$$ m = \langle t \rangle = \frac{\int t\lvert s(t)\rvert^2 dt}{\int \lvert s(t)\rvert^2 dt}= \int t \left(\frac{\lvert s(t)\rvert^2}{\int \lvert s(t)\rvert^2 dt}\right) dt.$$</span></p>
https://dsp.stackexchange.com/questions/24904/defining-an-average-in-time-for-a-density-in-time
Question: <p>I am looking for a good introduction to wavelets and wavelet transforms.</p> <p>that covers the following: Vector Spaces – Properties– Dot Product – Basis – Dimension, Orthogonality and Orthonormality – Relationship Between Vectors and Signals – Signal Spaces – Concept of Convergence – Hilbert Spaces for Energy Signals- Fourier Theory: Fourier series expansion, Fourier transform, Short time Fourier transform, Time-frequency analysis.</p> <pre><code> MULTI RESOLUTION ANALYSIS 9 </code></pre> <p>Definition of Multi Resolution Analysis (MRA) – Haar Basis – Construction of General Orthonormal MRA – Wavelet Basis for MRA – Continuous Time MRA Interpretation for the DTWT – Discrete Time MRA – Basis Functions for the DTWT – PRQMF Filter Banks<br> CONTINUOUS WAVELET TRANSFORMS </p> <p>Wavelet Transform – Definition and Properties – Concept of Scale and its Relation with Frequency – Continuous Wavelet Transform (CWT) – Scaling Function and Wavelet Functions (Daubechies Coiflet, Mexican Hat, Sinc, Gaussian, Bi Orthogonal)– Tiling of Time – Scale Plane for CWT.</p> <pre><code> DISCRETE WAVELET TRANSFORM </code></pre> <p>Filter Bank and Sub Band Coding Principles – Wavelet Filters – Inverse DWT Computation by Filter Banks – Basic Properties of Filter Coefficients – Choice of Wavelet Function Coefficients – Derivations of Daubechies Wavelets – Mallat's Algorithm for DWT – Multi Band Wavelet Transforms Lifting Scheme- Wavelet Transform Using Polyphase Matrix Factorization – Geometrical Foundations of Lifting Scheme – Lifting Scheme in Z –Domain.</p> <pre><code> APPLICATIONS </code></pre> <p>Wavelet methods for signal processing- Image Compression Techniques: EZW–SPHIT Coding – Image Denoising Techniques: Noise Estimation – Shrinkage Rules – Shrinkage Functions – Edge Detection and Object Isolation, Image Fusion, and Object Detection.</p> <p>Please suggest the steps,resources and materials to do the same.</p> <p>Thanks. DeeRam</p> Answer: <p>For wavelet I would recommend this book: <a href="http://www.conceptualwavelets.com/book.html" rel="nofollow">http://www.conceptualwavelets.com/book.html</a></p> <p>It is not too much mathematics included, yet in depth.</p>
https://dsp.stackexchange.com/questions/14109/need-to-learn-wavelet-suggest-steps-and-resources
Question: <p>Imagine transfer function obtained by Laplace transform, for example:</p> <p>$G(s) = \dfrac{1}{s+1}$</p> <p>Now, I would like to do some frequency analysis, so I replace the $s$ with $\omega i$ (let's consider this operation valid for this example).</p> <p>What is the unit of the $\omega$? So far what I have seen, the $\omega$ is noted as frequency or angular velocity. I asked my colleagues and I got various answers:</p> <ul> <li>rad/sec</li> <li>Hz</li> <li>no unit</li> </ul> <p>What is correct and why? Does it depend on real variable passed to transform (if somebody uses different variable than time)?</p> Answer: <p>If you are dealing with the Laplace transform $G(s)$ of a <strong>time</strong> domain signal $g(t)$ and its evaluation on the imaginary axis to get the Fourier transform $G(j\omega)$ (assuming it exists) then the unit of your frequency $\omega$ is <strong>radians per second</strong> assuming the unit of the time was seconds. </p> <p>It's relation to cyclic frequency is : $$\omega = 2 \pi f$$ where $f$ is the frequency in Hz (<strong>cycles per second</strong>).</p> <p>On the other hand if the initial function was like $g(x)$ where $x$ was a spatial variable with unit of meters, then the transform domain frequency unit will be in <strong>radians per meter</strong> where its relation to space-frequency is still the same with $\omega = 2 \pi f$ where $f$ will have the unit of <strong>cycles per meter</strong> </p>
https://dsp.stackexchange.com/questions/43733/meaning-and-unit-of-frequency-in-laplace-fourier-transform
Question: <p>I am sending a 20Khz signal from my phone and capturing all the signals while doing exercise above it. Here I have a signal of a person doing "<a href="http://www.top10homeremedies.com/wp-content/uploads/2016/02/scissors-exercise.gif" rel="nofollow noreferrer">hand scissors exercise</a>"</p> <p>I am doing analysis on how many times has the person done the exercise. I am able to figure that out in the frequency domain. But, the time-domain signal is very noisy, is there any way to extract any information in the time-domain from the existing signal that I have ?</p> <p><strong>The FFT analysis of the signal is attached below</strong> : <a href="https://i.sstatic.net/PXK4p.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/PXK4p.png" alt="frequency domain of the signal"></a></p> <p>The raw signal in the time-domain is given below, is there anything that can be done on this : </p> <p>(Y -axis is the energy of the signal) (X-axis is the number of frames in the wave signal)</p> <p><a href="https://i.sstatic.net/Blxzm.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Blxzm.png" alt="Time domain of the raw signal"></a></p> Answer:
https://dsp.stackexchange.com/questions/35297/any-examples-of-analysis-in-time-domain-to-extact-information
Question: <p>I've been looking to merge two datasets I have, that capture instances of the same phenomenon using two different recording tools. Both are multichannel electrical signals, but the recording tools have very different properties. I want to standardize those measures to make them hardware independent, but sadly I can't find much litterature on this topic even though it seems to be quite important to me.</p> <p>I currently look at two different paths : caracterising the signals using time-frequency analysis, and figuring out the properties of my devices in a controlled environment to extrapolate a transformation to standardize the signals.</p> <p>I am of course not expecting a definite answer on such a vague problem, but I would be very thankful if any of you can provide guidance or useful papers for me to read.</p> Answer: <p>I don't think there is a &quot;one size fits all&quot; answer for this. Here is one possible process assuming that your goal is &quot;if I measure a system with both tools I should get the same result&quot;.</p> <ol> <li>Start with the requirements. What information/data exactly do you need and how good does it need to be. Could be transfer function, spectra, THD, noise analysis, Volterra series, etc.</li> <li>Build a few test cases that a) have known answers and b) are reasonably representative for your desired application space.</li> <li>Apply both recording tools to the test cases</li> <li>Check to which extent the recording tools can provide the results and the accuracy you are looking for.</li> <li>Check whether there is enough overlap between the outcomes to standardize on one output format that both tools can produce with reasonable agreement and accuracy. Depending on how the tools and differ and what you need this may requires significant compromise or may not even be possible</li> <li>If that did converge, test verify the outlier use cases.</li> </ol>
https://dsp.stackexchange.com/questions/82892/standardizing-signals-from-the-same-experiment-setup-with-different-recording-to
Question: <p>The spectrogram of a signal throws away the phase information, but it is said to be possible to reconstruct the signal only from the spectrogram [1] via $$s(t) = \frac{1}{2\pi s^*(0)}\int_{-\infty}^{\infty}\frac{M_{SP}(\theta,t)}{A_h(-\theta,t)}e^{-j\theta t/2}d\theta$$ where $M_{SP}$ is the chariteristic function of spectrogram and ${A_h(\theta,t)}$ is the ambiguity function of the window.</p> <p>The formula seems to work in theory. Could anybody explain why it works? Some phase information is thrown away after all. Also, is it a good reconstruction tool used in practice? It seems to me that nobody uses this as the reconstruction tool.</p> <p><a href="http://www.worldcat.org/title/time-frequency-analysis/oclc/801304211?loc=" rel="nofollow noreferrer">[1] L. Cohen, Time-frequency analysis. Englewood Cliffs, N.J: Prentice Hall PTR, 1995.</a></p> Answer:
https://dsp.stackexchange.com/questions/47820/reconstruct-signal-from-its-spectrogram-only
Question: <p>What is the best &quot;Signals and systems&quot; Module Online course/resource/Youtube playlist?</p> <p>FYI, this request is for a Final Year undergrad following Bachelor's degree in EEE.</p> <p>I have checked Neso academy, but its too long and can be frustating to complete it, also it doesnt cover most of the advanced topics like:</p> <ul> <li>Multirate signal processing (interpolation and decimation)</li> <li>Time-frequency analysis (e.g., wavelets, filter banks)</li> <li>2D signal processing (image representation and compression</li> </ul> <p>I have also checked the MIT courses like MIT 6.003 and MIT RES.6.007, but they are tool old and the video quality isnt the best.</p> <p>I just want to know if there is any quality resource to learn visually from basics to advance, in one single playlist. I haven't found such resource on the Internet yet.</p> Answer:
https://dsp.stackexchange.com/questions/97832/what-is-the-best-signals-and-systems-module-online-course-resource-youtube-playl
Question: <p>I have a vibration signal coming from a motor measured from accelerometer (<strong>Irregular Time series</strong>) and I need to use these signals for analysis purpose. </p> <p><img src="https://i.sstatic.net/yNYDe.jpg" alt="pic2"></p> <p>I am in need to transform this signal to some form for analysis purpose. I read few blogs and websites containing <em>vibration signal processing technique</em>. The basic thing is to transform the signal from time domain to frequency domain.</p> <p>So I used the <code>fft</code> function to transform using R </p> <pre><code>X.k &lt;- fft(signal) </code></pre> <p><code>plot.frequency.spectrum()</code> plot a frequency spectrum of a given fft [Link: <a href="http://www.di.fc.ul.pt/~jpn/r/fourier/fourier.html" rel="nofollow noreferrer">here</a>]</p> <pre><code>plot.frequency.spectrum &lt;- function(X.k, xlimits=c(0,length(X.k))) { plot.data &lt;- cbind(0:(length(X.k)-1), Mod(X.k)) plot.data[2:length(X.k),2] &lt;- 2*plot.data[2:length(X.k),2] plot(plot.data, t="h", lwd=2, main="", xlab="Frequency (Hz)", ylab="Strength", xlim=xlimits, ylim=c(0,max(Mod(plot.data[,2])))) } </code></pre> <p>The frequency spectrum of this fft looks like this <a href="https://i.sstatic.net/g4kMu.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/g4kMu.jpg" alt="her"></a></p> <p>The first peak is extremely high. I don't know why this happens as am new to signal processing techniques. I cannot use this for analysis purpose and do prediction as it will end in bad results. Any other ways to do this method? Or do I need to use other techniques? </p> Answer: <p>The first peak is the DC component of your spectrum which is large compared to the AC components (your signal doesn't have negative value and its always above zero which lead to large DC bias)</p> <p>Find average of your signal over time and subtract it from your signal to remove the DC component.</p> <p>Good luck.</p>
https://dsp.stackexchange.com/questions/43157/analysis-of-vibration-signals
Question: <p>How to show the time history of a signal down-sampled under the rates of 25Hz &amp; 40Hz and find its DFT analysis using Matlab ? The sample signal is in a data file (<a href="http://www.filedropper.com/sensordata" rel="nofollow">sensor_data.mat</a>) its sampling rate is 1000Hz.</p> <p>I can get the time history and the DFT analysis of the signal.</p> <pre><code>Fs = 1000; % sampling rate T=1/Fs; % sample time L= 20000; % lenght of signal t=(0:L-1)*T; % time vector figure(1) plot(t,u) grid; title('Time History of the Signal') % dft analysis yf=fft(u); w=[0:2*pi/L:(L-1)*2*pi/L]; figure(2) plot(w/(2*pi*T),abs(yf)) grid title('DFT analysis of the signal sampled at 1000Hz') </code></pre> <p>But how do I down-sample it ? I know Matlab has a function for it (downsample), but I'm not getting any correct answers. </p> <p>Also how do I find the signals frequency range and amplitude over its frequency range from the DFT analysis ?</p> <p>Thanks in advance, Please help !! </p> Answer:
https://dsp.stackexchange.com/questions/23492/how-to-show-the-time-history-of-a-signal-down-sampled-under-the-rate-of-25hz
Question: <p>I have a device (Large as typical PC casing) with a motor. There can be a condition that the device motor load is unbalanced and the device starts to move around the table and I need to detect this. For this, I have an accelerometer.</p> <p>But the problem is that I can't come up with a reliable algorithm to detect these vibrations.</p> <p>Here are sensor data. The solid line is 5 point moving average. The dotted line is raw data. Time is in ms.</p> <p><a href="https://i.sstatic.net/0LYCy.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/0LYCy.png" alt="enter image description here" /></a></p> <p>I tried to do some averaging, max and min detection and some other simple algorithms but it didn't work, but there is difference between plots, &quot;Vibration&quot; plot looks more periodic and consist of one frequency.</p> <p>Can you please suggest some algorithms or ways to deal with such a problem in the time domain? Maybe there is some neat way to differentiate these two plots?</p> <p>I am using 8bit MCU to read data and detect vibrations so I can't do real-time frequency domain analysis.</p> <p>Thank you</p> <p>PS. I will add plots I made in the frequency domain, maybe this will help. I took 5 points moving average. Then used a cosine hamming window and took DFT of 64 samples. Here are plots</p> <p>Vibrations <a href="https://i.sstatic.net/VpTYR.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/VpTYR.jpg" alt="enter image description here" /></a></p> <p>No vibrations</p> <p><a href="https://i.sstatic.net/Kp2mg.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Kp2mg.jpg" alt="enter image description here" /></a></p> Answer:
https://dsp.stackexchange.com/questions/70179/accelerometer-data-analysis-without-fft
Question: <p>I have been studying the Hilbert-Huang transform, which I understand is a frequency analysis technique that uses the adaptive IMFs basis components to decompose a signal using EMD.</p> <p>I understand that frequency analysis techniques such as the STFT (short-time Fourier transform) and Wavelet transform involve the convolution of a signal with a predefined basis in order to extract frequency information.</p> <p>Several articles from Huang and others state "<em>convolution processes involve integration, which makes the results suffering the limitation imposed by the uncertainty principle</em>". </p> <p><a href="http://web-static-aws.seas.harvard.edu/climate/pdf/Zhaohua.pdf" rel="nofollow noreferrer">http://web-static-aws.seas.harvard.edu/climate/pdf/Zhaohua.pdf</a> <a href="https://pyhht.readthedocs.io/en/latest/tutorials/hilbert_view_nonlinearity.html" rel="nofollow noreferrer">https://pyhht.readthedocs.io/en/latest/tutorials/hilbert_view_nonlinearity.html</a></p> <p>I also understand that the frequency of each IMF is extracted by finding the time rate of change of phase of the analytic signal for each IMF (which would involve differentiation of the phase with respect to time).</p> <p><strong>Why does this differentiation mean that the uncertainty principle is avoided?</strong></p> <p>I have a vague idea that it's due to operators associated with time and frequency that don't commute, but I have struggled to find any sources that approach this from a signal processing/mathematical perceptive rather than in a quantum mechanical sense.</p> <p>Furthermore, if this kind of signal processing circumvents the uncertainty principle, does that mean time and frequency events can be resolved with <em>arbitrary</em> precision? </p> <p>(In my head, this, in turn, would have implications in quantum mechanics, but I imagine this would be outside the topic of this site.) </p> <p>Any insights and/or articles are gratefully received. </p> Answer: <p>I'm not that familiar with the Hilbert-Huang transform, so I won't comment on that.</p> <p>You seem to be under the impression that the DFT "suffers from the uncertainty principle". This is not true. Don't feel bad about thinking that as it is a widespread misunderstanding. This is a quote from an email to me from a well known expert in the field after I tried to get them to look at my exact frequency formula for a single (non-integer) pure real tone in a DFT:</p> <blockquote> <p>An "exact" computation of frequency based on FTs is not possible for some very simple reasons: The Fourier Transform is itself an estimator, and the time-frequency uncertainty principle means frequency can't be determined exactly without an infinitely long observation window. So essentially all frequency computations of time series or signals are estimates, it's just that some are more accurate or more efficient than others.</p> <p>So claiming that you have an exact solution just isn't going to get the attention of everyone interested in the field.</p> </blockquote> <p>The first paragraph is entirely hogwash. The last sentence was prophetic, hence I started my blog so no one could dispute the math. You will find my original exact solution here:</p> <ul> <li><a href="https://www.dsprelated.com/showarticle/773.php" rel="nofollow noreferrer">Exact Frequency Formula for a Pure Real Tone in a DFT</a></li> </ul> <p>I have discovered, and written about, several more. You will find them among my articles. There are also a few in the pipeline, including a correction to Macleod's three bin formula which makes it exact also.</p> <p>The FT does apply to the uncertainty principle in physics, but in a different manner. There they are talking about the transform of a Gaussian curve which happens to be an eigenfunction of the FT (but not the DFT, close though) and how it is the "narrowest function" in the transform.</p> <p>I'm not an expert in Physics either, but I dabble. I consider this to be my greatest mathematical discovery ever (exclipses the simple math of the frequency formulas by a mile):</p> <ul> <li><a href="https://www.dsprelated.com/showarticle/1190.php" rel="nofollow noreferrer">Off Topic: Refraction in a Varying Medium</a></li> </ul> <p>This is the vector form of Snell's law in a continuously varying index of refraction medium. It is a theoretical particle model so its applicability to light is still a subject of study for me. I believe it has the potential to illuminate subatomic behavior (i.e. the quantum world) but I haven't gotten there yet.</p>
https://dsp.stackexchange.com/questions/64336/why-does-the-hilbert-huang-transform-not-suffer-from-the-uncertainty-principle
Question: <p>What is Spectral entropy and spectral moments? I know what the normal entropy of a signal is! And also what are some good time-frequency features for the analysis of non-stationary signals?</p> Answer:
https://dsp.stackexchange.com/questions/49809/spectral-entropy-and-moments-and-non-stationary-signal-processing
Question: <p>I am currently working on a project which requires evaluating slow changes over time in the magnitude of a signal's high frequency (over 10 kHz) components.</p> <p>This signal was acquired in tests with a 25.6 kHz sampling rate and in &quot;batches&quot;: every minute, one second of data was acquired. This was done in order to save storage space, since 1 Hz resolution was enough for the FFT analysis and since short spaced fluctuations in the components would be irrelevant for our goal. The tests were quite expensive, and I am not able to perform more of them.</p> <p>This acquisition method was enough for a STFT analysis of the signal, but we are now looking to other time-frequency analysis methods, such as Hilbert-Hwang and continuous wavelet transform, and these require data acquired at a fixed sample rate.</p> <p>I see 2 options to perform these analyses with the data that I currently have:</p> <ol> <li>Reconstruct the missing 59s of each minute assuming that the 1s of data that I have is representative of whole minute.</li> <li>Simply join all data that I have, perform all the analyses as if the data was acquired at a 60 times slower rate, and in the end just scale the frequencies back to the original.</li> </ol> <p>I tried to do both solutions with the <a href="https://www.mathworks.com/help/signal/ref/istft.html" rel="nofollow noreferrer">istft matlab function</a>, tweaking with the function parameters and trying to interpolate phase and magnitude information in order to smoothen the transition from one batch to another, but I always end up with discontinuities that make it unable to perform the desired analyses.</p> <p>Is there any way to reconstruct/synthesize data that would have a similar frequency behavior of the original, but correct for the discontinuities?</p> Answer:
https://dsp.stackexchange.com/questions/87036/reconstruction-of-batch-acquired-signal
Question: <p>I was studying the introduction to wavelets and its benefit over the frequency domain. I said that:</p> <blockquote> <p>Fourier analysis can't localize signals both in time and frequency domain. Fourier analysis can localize signal in frequency domain very well, but not so much in time domain. While wavelet has the advantage of localizing signals both in time and frequency domain.</p> </blockquote> <p>What does this mean? Could you give me any example or link that explains this scenario better?</p> Answer: <p>In the Fourier transform, the basis functions are complex exponentials. These functions are perfectly localized in the frequency domain, i.e., they exist at one frequency, but they have no time localization because of their infinite duration. The localization of a function depends on its spread in time and frequency. A complex exponential has zero spread in frequency, but it has infinite spread in the time domain. Consequently, any signal analyzed by the Fourier transform is only localized in frequency (e.g., frequencies of sinusoidal components can be identified), but not at all in time (e.g., temporal changes of signal properties cannot be localized).</p>
https://dsp.stackexchange.com/questions/33474/fourier-transform-can-localize-signals-in-frequency-domain-but-not-in-time-dom
Question: <p>Can anyone describe in a bit more detail or provide references to the techniques for simultaneous enhancements to time and frequency resolution described in a high level in <a href="https://youtu.be/BQRNPXkN6Ww" rel="nofollow noreferrer">HEAD acoustics International - Advanced FFT Analysis HSA - frequency and time resolution as you want</a> video? Can anyone think of any downsides?</p> <p>The time &quot;overlap&quot; is mostly straightforward, but I don't quite follow how different window sizes for the same time step would be aggregated together.</p> Answer: <p>As Jazzmaniac said in his comments: this is a marketing video which is heavy on hype and light on technical details.</p> <p>There is no way around the basic limitation of frequency and time resolution. The techniques used in HSA appear to be standard interpolation methods: you can adjust hop size and window length independently. This is all fine and well: You just need to be aware that this interpolation of the original data and NOT new data. You don't learn anything new, you just display it differently.</p> <p>There is certainly nothing wrong in optimizing the display of your data to the properties of your signal or the requirements of your application. It's just not a &quot;one size fits all&quot; approach that is fundamentally better (or worse) than any other approach.</p> <p>Specially this works really well in the video, because the frequencies of the signal only change very slowly with time. If you would use the same analysis parameters for a signal with rapid pitch changes (such as someone singing or speech), you would see that the time transitions are very smeared out and it would be quite difficult to see when the pitch change actually happens.</p> <p>So it all boils down to: use the right tool and parameters for the task at hand. In some cases that may be the HSA as advertised but in many cases it will not.</p>
https://dsp.stackexchange.com/questions/82743/fft-with-high-time-and-frequency-resolution
Question: <p>Defined as &quot;negative DFT bins zero&quot;, when are such filters suboptimal for AM/FM extraction or related filtering? <a href="https://dsp.stackexchange.com/a/83991/50076">This answer</a> reads,</p> <blockquote> <p>[nulling] also has the worst performance compared to other methods such as windowing or using the optimized algorithms known as &quot;least-squares&quot; and &quot;equiripple&quot; (Parks-McLellan) that are used in the 'firls' and 'firpm' or 'remez' commands;</p> </blockquote> <p>with an explanation I don't quite follow,</p> <blockquote> <p>this is because the Frequency Sampling method will result in a response that is exact at the bin frequencies used, but have more error compared to the other methods at all other frequencies that are in between the FFT bins, and more error in the time domain responses as well</p> </blockquote> <p>Firstly, I strongly disagree with &quot;worst performance&quot;, as such nulling is considered <em>optimal</em> in time-frequency analysis: the <a href="https://overlordgolddragon.github.io/generalized-morse-wavelets/" rel="nofollow noreferrer">Generalized Morse Wavelets</a> are built with such nulling being explicit. Obvious case: if any negative bin is non-zero, it can always be exploited to make a pure sine appear as AM. Example is STFT, which is pseudo-analytic near Nyquist:</p> <img src="https://i.sstatic.net/pSBX4.png" width="700"> <img src="https://i.sstatic.net/Z9Ja6.png" width="450"> <p>This remains the case with higher sampling rates and observation intervals. What do the alt methods (<code>remez</code> etc) have to say about this?</p> Answer:
https://dsp.stackexchange.com/questions/84638/when-is-perfect-analytic-filtering-discrete-suboptimal
Question: <p>The big disadvantage of a DFT is that it has only frequency resolution and no time resolution. This means that although we might be able to determine all the frequencies present in a signal, we do not know when they are present. So we go for Wavelets.</p> <p>My question is, What are the applications (other than music &amp; speech processing ) that require both the time and frequency information at same time ?</p> <p>How do you relate that we require both spatial (time) and frequency information in an image at a same time ? </p> <p>Give me some good examples and suggest a book (PDF links) to learn Wavelet Multiresolution Analysis (For Dummies)</p> Answer: <pre><code>For the source, go to end of the answer </code></pre> <p>Suppose one day you got one note which has some thing written to it, say <strong>"Major frequency components are 10 Hz, 25Hz, 50 Hz and 100 Hz"</strong>. Somehow, you understood that its time-series representation is a very important thing (may be master-piece work of a great musician, or some national security matter, anything). So you decided to find it. </p> <p>You start by plotting the spectrum which looks like below:</p> <p><img src="https://i.sstatic.net/p9rbN.gif" alt="enter image description here"></p> <p>(There can be some noises/disturbances in between these frequencies, but most people neglect it)</p> <p>Now you want to find its time-series representation. Since we have worked it a lot in our signal processing class in college, most probably, we get below signal:</p> <p>$$ x(t)=cos(2 \pi 10 t)+cos(2\pi 25 t)+cos(2 \pi 50 t)+cos(2 \pi 100 t) $$</p> <p>Great !!! </p> <hr> <p><strong>But is this the only time series representation for those frequencies?</strong></p> <p>Consider another time series signal which plays a sine wave of frequency 100 Hz for 300 ms, then 50 Hz sine wave for next 300 ms, then 25 Hz sine wave for 200 ms, then 10 Hz sine wave for 200 ms. A total of 1000 ms long signal. If you plot it, it will look like below:</p> <p><img src="https://i.sstatic.net/fEmtm.gif" alt="enter image description here"> </p> <p>Actually above signal also have similar frequency spectrum (shown below):</p> <p><img src="https://i.sstatic.net/MXrCE.gif" alt="enter image description here"></p> <p><em>Those ripples are because of sudden changes in frequency. Amplitude changes are because of change in how long each frequency was played. They are not of importance to us right now.</em></p> <hr> <p><strong>So what to do now? How will you pick one? Even if we change the order they were played, still we get the same frequency spectrum. So how many such combinations you have?</strong></p> <hr> <blockquote> <p><strong>In short words, without knowing when those frequencies were played, it is very difficult to find its time series representation, and that is where, wavelets come into picture. It provides not only the frequencies present in the signal, but also, the time it was present in the signal.</strong></p> </blockquote> <hr> <h1>UPDATE (17-Feb-14)</h1> <p><strong>Question</strong> : How do you relate that we require both spatial (time) and frequency information in an image at a same time ? </p> <p><strong>Answer</strong> : <em>Me too, had the same question before, so after seeing your comment, I thought I should find one example (I haven't studied wavelets in the context of images before wavelets). And below explanation is the <a href="http://www.quora.com/In-laymans-terms-what-is-a-wavelet-transform" rel="nofollow noreferrer"><code>summary of an answer in Quora.com</code></a> (all credits to that author, Ron Reiter) which I felt as a good example.</em></p> <p>You might be knowing that we use the DCT for jpeg compression of images. It preserves the low frequency data while throws away some of the high frequency data in the images, based on the image quality we need.Or in other words, this method is good with low frequency data, but not that accurate with high frequency data. </p> <p>For example, in an image with sky and a tree, the areas of sky will be preserved accurately while some details of tree will be thrown off.</p> <p>In DCT, we take 8x8 blocks of images and encode it for all frequency of data. For very low frequencies, we could have used higher block size while for very high frequencies, we may have to use lower block size than this.</p> <p>Now apply our wavelet method as explained in 1D case above. What if we can find both frequency and their location in the image? We can encode the low frequency areas in big chunks while high frequency areas in low chunks. So it produces better results.</p> <p><em>Please check the link for more details</em></p> <h1>SOURCE:</h1> <ol> <li><a href="https://ccrma.stanford.edu/~unjung/mylec/WTpart1.html" rel="nofollow noreferrer">THE WAVELET TUTORIAL by ROBI POLIKAR</a> <ul> <li>All the images, explanation, everything, are extracted from this link. It is a must-read introduction of wavelets to beginners</li> </ul></li> <li><a href="http://www-2.nersc.no/~even/matlab/toolbox/wavelets/amara/wavelet.html#wwwintro" rel="nofollow noreferrer">Amara's Wavelet Page</a></li> <li><a href="http://www.quora.com/In-laymans-terms-what-is-a-wavelet-transform" rel="nofollow noreferrer">Wavelet in image compression - Ron Reiter at Quora.com</a></li> </ol>
https://dsp.stackexchange.com/questions/14404/why-we-need-frequency-and-time-information-at-the-same-time
Question: <p>At a glance, the constant-Q fourier transform and the complex <a href="https://dsp.stackexchange.com/q/2114/29">Gabor-Morlet wavelet</a> transform seem the same. Both are time-frequency representations, based on constant-Q filters, windowed sinusoids, etc. But maybe there's a difference that I'm missing?</p> <p><a href="http://www.elec.qmul.ac.uk/people/anssik/cqt/" rel="nofollow noreferrer">Constant-Q Transform Toolbox for Music Processing</a> says:</p> <blockquote> <p>CQT refers to a time-frequency representation where the frequency bins are geometrically spaced and the Q-factors (ratios of the center frequencies to bandwidths) of all bins are equal.</p> </blockquote> <p><a href="https://web.archive.org/web/20050411111713im_/http://www.engmath.dal.ca/courses/engm6610/notes1.pdf#page=19" rel="nofollow noreferrer">Time-scale analysis</a> says:</p> <blockquote> <p>That is, computing the CWT of a signal using the Morlet wavelet is the same as passing the signal through a series of bandpass filters centered at <span class="math-container">$f = \frac{5/2\pi}{a}$</span> with constant Q of <span class="math-container">$5/2\pi$</span>.</p> </blockquote> Answer: <p>Simply speaking both the const-Q-transform and the Gabor-Morlet wavelet-transform are just continuous wavelet transforms. Or, more precisely, approximations thereof, as there will always be discretization issues in real applications.</p> <p>A property of wavelet transforms is that they have build in the constant Q-factor property, or in other words logarithmic scaling. Gabor and Morlet are just two names of a particular wavelet function (complex exponentials with a gaussian window) which is used most commonly. The CQ-transform just uses another basis function/wavelet and has a special name attached to it, probably to some historical reason. </p>
https://dsp.stackexchange.com/questions/6266/whats-the-difference-between-the-gabor-morlet-wavelet-transform-and-the-constan
Question: <p>I have been reading about non-linear non-stationary signal analysis methods and it seems to do this type of analysis the go-to method is the Empirical Mode Decomposition (EMD), then Hilbert Transform (HT) to get instantaneous phase and frequency.</p> <p>However I have been doing some analysis on a non-linear, non-stationary signal by splitting the time signal into intervals with a Hanning window and Fourier transforming each interval which I think might also be the idea behind the Short Time Fourier Transform (STFT), although I am not sure.</p> <p>Can anyone tell me what is wrong with this method, and why the EMD / HT method is more advantageous? I have also seen wavelet analysis used in similar cases, is this something I should look into?</p> Answer: <p>Non-linearity and non-stationarity are <strong>non-properties</strong>. Without more details, they do not say much about the methods that may perform well, and moreover the choice depends a lot on what you really do: analysis, feature extraction, enhancement, filtering, component separation, restoration? What follows are typical sets of tools you could use:</p> <ul> <li>Your moving-window-Fourier definitely has some STFT flavors, and there are many non-linear extensions: <a href="https://en.wikipedia.org/wiki/Bilinear_time%E2%80%93frequency_distribution" rel="nofollow noreferrer">bilinear or quadratic time–frequency distributions</a> (Wigner-Ville, Choi–Williams, Rihaczek)</li> <li>Non-linearity may come from changing the classical energy preservation into other norms, like robust DFTs (under an <span class="math-container">$\ell_1$</span> norm minimization), see for instance <a href="https://doi.org/10.1109/tsp.2003.812739" rel="nofollow noreferrer">Robust <span class="math-container">$L$</span>-estimation based forms of signal transforms and time-frequency representations</a>, see also <a href="https://dsp.stackexchange.com/q/59022/15892">Using different algorithms/formulas to create spectrograms</a></li> <li>Some methods also alleviate the hypothesis that signal formation is linear: variance-stabilizing transforms, cepstral analysis or <a href="https://en.wikipedia.org/wiki/Homomorphic_filtering" rel="nofollow noreferrer">homomorphic signal processing</a> (linear transforms applied in a <span class="math-container">$\log$</span> domain)</li> <li>Generalizations of linear approaches in polynomial or rational fraction modeling, with a recent interest in <a href="https://doi.org/10.1109/tsp.2018.2890065" rel="nofollow noreferrer">Rational Optimization for Nonlinear Reconstruction with Approximate <span class="math-container">$\ell_0$</span> Penalization</a>.</li> </ul> <p>All of the above can be combined somehow, like EMD at different scales in <a href="https://dx.doi.org/10.1098%2Frspa.2014.0709" rel="nofollow noreferrer">Intrinsic multi-scale analysis: a multi-variate empirical mode decomposition framework</a>. EMD has many uses and <a href="https://en.wikipedia.org/wiki/Hilbert%E2%80%93Huang_transform#Limitations" rel="nofollow noreferrer">some known limitations at the same time</a>.</p>
https://dsp.stackexchange.com/questions/59797/non-linear-non-stationary-spectral-analysis-methods-when-and-where
Question: <p>The signal I'm studying has fundamental frequencies of 20 and 60 cycles per minute (shown in the Periodogram graph). It is straight forward to extract the peaks in the time domain belonging to the 20 cycles/minute frequency (both are circled), however the peaks associated with the 60 cycles per minute frequency can be noisy.</p> <p><a href="https://i.sstatic.net/Bvuk6.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Bvuk6.png" alt="Time Domain"></a></p> <p>6 seconds of the time domain signal</p> <p><a href="https://i.sstatic.net/LdWEy.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/LdWEy.png" alt="Frequency Domain (per minute not per sec)"></a></p> <p>Both signals in the time domain will ALWAYS overlap so low pass filtering isn't completely necessary but I'm just curious to know if there's a better way of extracting the 60 cycles per minute peaks (aside from peak-to-trough analysis) using frequency domain information?</p> <p>Thanks!</p> Answer: <p>You can figure where the peaks would be if the other tone wasn't there by an accurate estimate of the phase. This location will be a rougher estimate in the presence of the other tone. When you add a slanted signal (say a line) to a mode (a peak), it will shift the location of the peak somewhat. Since you are interested in the higher frequency tone, the lower frequency one is going to look like a broad hill in comparison which is going to be less interfering than if you were doing it the other way around. (I'm using the word "tone" broadly, meaning a pure sinusoidal signal.)</p>
https://dsp.stackexchange.com/questions/59118/is-it-possible-to-extract-peak-locations-in-the-time-domain-using-help-from-four
Question: <p>I want to write an algorithm in C++ which is capable of identifying specific features within a single song, e. g. the sound of a drum which is played 100 times during 5 min. </p> <p><strong>State of the project</strong></p> <p>So the first thing I did was to import my *.wav-file, perfrom a step-wise FFT of the signal in order to create a time-frequency-pattern as shown in the figure below (x-axis: frequency, y-axis: time [ms], color: magnitude [dB]).</p> <p><a href="https://i.sstatic.net/lVTgz.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/lVTgz.jpg" alt="Time-frequency-pattern of a *.wav-file"></a></p> <p>Here you can see the magnitude of a single frequency over time:</p> <p><a href="https://i.sstatic.net/4UwSf.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/4UwSf.jpg" alt="Time-amplitude for a single frequency"></a></p> <p>In the second picture one can easily see, that the pattern of the drum stays the same and is only shifted in time (peaks).</p> <p>If I would only have this single song, it would be straightforward: I could search for points reaching a specific dB value and read out the corresponding time. However, I want to apply this algorithm to many different song files and don't want to manually adapt the values each time.</p> <p><strong>Problem</strong></p> <p>Which method could I use to identify such features? I thought about pattern recognition by neural networks, but I am not sure if this is the most appropriate solution. </p> <p>I already read wikipedias article about pattern recognition (I am not allowed to make more than two links, sorry for that) basically saying that there are many different algorithm, but I think I need some help selecting the most appropriate one for my problem.</p> <p><strong>Edit 1:</strong></p> <p>My current approach is to use blob detection in order to read out different areas like the bass features and feed the blobs and their properties to a Neural Network in order to categorize them.</p> <p>Thank you in advance!</p> <p>Cheers, Urs</p> <p><strong>Links</strong> Sorry for the missing http://, i am not allowed to post more than two links</p> <p>t-f-relationsip of music in general: ecee.colorado.edu/~mathys/ecen1200/sound/sounds2006_6pp.pdf</p> <p>time frequency analysis of music: en.wikipedia.org/wiki/Time–frequency_analysis_for_music_signals</p> <p>perhaps helpful: en.wikipedia.org/wiki/Harmonic_pitch_class_profiles</p> <p>might be helpful, but I don't understand it: resources.mpi-inf.mpg.de/departments/d4/teaching/ss2009/mp_mm/2009_MuellerMeinard_Lecture_MusicProcessing_AudioStructure_handouts.pdf</p> Answer:
https://dsp.stackexchange.com/questions/36963/feature-recognition-within-a-single-song
Question: <p>I'm new to python and I'm using it to analyse accelerations from an accelerometer ie. vibration analysis. For that I need to plot 2 types of diagrams: 1) Frequency map; frequency and time on the axis with the amplitudes, 2) Order map; order and time (or RPM) on the axis with respective amplitudes.</p> <p>The data from the sensor is sampled at 1 kHz and include the accelerations in X,Y and Z, pulses for every shaft rotation and the timestamps (in microseconds).</p> <p>I wrote a small code for the frequency map and plot them using scatter() and it gives me this plot. <a href="https://i.sstatic.net/o39vk.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/o39vk.png" alt="Frequency map (my code)"></a> The green "lines" correspond to the RPMs and the order; accelerating and decelerating the shaft.</p> <p>I then found that scipy has a builtin spectrogram() and pcolormesh() function, which should give me something similar. I used it on my data and got this: <a href="https://i.sstatic.net/GHdjP.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/GHdjP.png" alt="scipy spectrogram"></a> Note: axis are flipped</p> <p>The "RPM lines" are barely visible. So I used log to scale the colours and got this:<a href="https://i.sstatic.net/xkln5.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/xkln5.png" alt="scipy spectrogram with log"></a> </p> <p>And this is still weird looking.</p> <p>The problem is with my code and using scatter, the points overlap. And if I used smaller points, then they look strange when opening the diagram in full screen. Is there any way to get the plots to look better? Whether using the spectrogram() function or using something like scatter() ?</p> <p>Also, how can I plot the order map? I don't know how to change the data from time/frequency domain to order domain. </p> <p>Here is a link to understand what I'm trying to implement: <a href="https://de.mathworks.com/help/signal/examples/order-analysis-of-a-vibration-signal.html" rel="nofollow noreferrer">https://de.mathworks.com/help/signal/examples/order-analysis-of-a-vibration-signal.html</a></p> <p>Much thanks in advance!</p> Answer:
https://dsp.stackexchange.com/questions/64228/frequency-and-order-maps
Question: <p>I am a total newbie in signal processing. I have been trying to plot on simulink a time/frequency domain noise in PLC (Powerline Communication) that matches a real-world research <a href="https://ieeexplore.ieee.org/abstract/document/5478758/" rel="nofollow noreferrer">"<code>Time Frequency Analysis of Noise Generated by Electrical Loads in PLC</code>"</a>, however, I failed to plot such noise. </p> <p>Generally speaking about my aim, I am trying to collect appliances’ noise that causes bit errors in PLC by comparing the original bit sequence with the received bit sequence. So, I need to simulate each appliance noise individually like the article mentioned above. Unfortunately, I couldn’t find any data source where I could download appliances’ noise, so I am creating my own simulation to collect my appliances’ bit-errors data. I have been able to simulate PLC using FSK modulation/demodulation with 1000 bits per second as a binary sample rate for my bit-sequence. For the FSK modulation, I have 7500 Hz as a carrier frequency for the bit-sequence to the AC channel that has 50 Hz/220 V as the typical AC source voltage, but now I am stuck on the phase of creating Appliances’ noise which has to matches real-world noise. <a href="https://i.sstatic.net/rq58f.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/rq58f.png" alt="enter image description here"></a></p> <p>If anyone knows how to plot on Simulink as I don't know how to plot such signals:</p> <ul> <li>In frequency domain: background noise as high as 55dB for the measurement frequency range with the power contained up to 4MHz</li> <li>In time domain: Raise up to 45dB above the background noise floor for most of the AC cycle duration</li> </ul> <p>As far as the article shows, it should look like this. <a href="https://i.sstatic.net/MErtV.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/MErtV.png" alt="enter image description here"></a></p> <p>I need to plot a huge dataset, so if anyone could help me understand how to plot such noise, I will be able to plot the rest.</p> Answer:
https://dsp.stackexchange.com/questions/49778/plot-background-noise
Question: <p>I have a problem with a FFT analysis in MATLAB, which is probably related to my limited understanding of the fundamentals of Fourier analysis. </p> <ul> <li>I use MATLAB’s built-in fft analysis function. </li> <li>The sampling frequency is 48000Hz The samples signal is a fairly clean sinus at 3000Hz (se below)</li> <li>I use a flat top windowing. </li> <li>I sample two voltage signals and use them to calculate the impedance of a device under test. An example of time data fed into the fft function, after windowing, is presented below <img src="https://i.sstatic.net/mliF2.gif" alt="enter image description here"></li> </ul> <p>When I increases the sampling time from shorter to a longer times, e.g. 0.5sec to 1sec, I get incorrect impedance results (e.g. negative resistance). Intuitively I would assume that longer sampling times would increase the accuracy. I have tracked the difference between the two different sample times to a change of the sign of the imaginary part of the discrete Fourier transform output for the 3000Hz-frequency bin. I do not know if this can be related to the incorrect results. For the shorter sampling time the imaginary part of the DFT is negative, se left figure below. And for the longer sampling time the imaginary part of the DFT is positive, se right figure below.</p> <p><img src="https://i.sstatic.net/kyuqa.gif" alt="http://i.imgur.com/VOSPNgw.gif"></p> <p>I am grateful for any ideas of what might be causing this issue? I’m also happy to provide additional information if needed. </p> <p>Kind regards, Johan</p> <p>edit: My code is quite long, but below I have attached a code extract which I think is most relevant to the problem. I have not written all this code myself, but the author is unfortunately not available to me for questions. Generally this code have worked very well for a long time, the issue described in my original post is the only time that I have ever seen a problem.</p> <pre><code>% stSet.freq is the excitation frequency % TH is the time data matrix [Gij, freq, spec] = specDens(TH(inx,2:end), measData.Fs, blockSize, windowFcn, nOverlap, nFFT); inxHD = ([1:nHarmonics].*stSet.freq)./spec.x(2)+1; %% Defining indicies for HD components inxHD = inxHD(inxHD&lt;nFFT/2-1);%% Taking only HD components &lt; Fs/2 % I = U2/R % U = (U1-U2) % Hiu = U/I = (U1-U2)/U2*R (electrical impedance) % Gij - cross- and autopower spectral density functions % Channels ch_U1 = 1; % Ch.#1 - U1 ch_U2 = 2; % Ch.#2 - U2 R = 1.; % Resistance of measurement resistor H.iu = (Gij(inxHD,ch_U1,ch_U1) - Gij(inxHD,ch_U2,ch_U1)) ./ Gij(inxHD,ch_U2,ch_U1)*R; % Electrical impedance </code></pre> <p>Subfunction: specDens</p> <pre><code>function [Gij, freq, spec] = specDens(TH, Fs, blockSize, windowFcn, nOverlap, nFFT) % % Syntax: % [Gij, freq, spec] = specDensRE2(TH, Fs, blockSize, windowFcn, nOverlap, nFFT) % % MATLAB function for computing cross- and autopower spectral density functions from continous signal measurements % % __Outputs__ % Gij - cross- and autopower spectral density functions % freq - frequency vector % spec - Single sided linear spectrum % % __Inputs__ % TH - measured signal, [m, n] = size(TH), m = No of samples, n = No of channels % Fs - sampling frequency % blockSize - Block size % windowFcn - user defined window, no input =&gt; Hanning % nOverlap - user defined overlap, no input =&gt; nOverlap &lt;=&gt; 75% % nFFT - Number of fft points if(nargin&lt;6); nFFT = blockSize; end; if(nargin&lt;5); nOverlap = round(blockSize*.75); end; if(nargin&lt;4); [windowFcn, windowLSS] = window_re(blockSize,'Hanning'); end; if(ischar(windowFcn)); %% assuming windowFcn is defining window type [windowFcn, windowLSS] = window_re(blockSize,windowFcn); end; [nSamples, nCh] = size(TH); %% nSamples=No of samples, nCh=No of channels if(nSamples&lt;nCh); disp('Assuming input data transposed.'); TH = TH.'; [nSamples, nCh] = size(TH); %% nSamples=No of samples, nCh=No of channels end nAvg = fix((nSamples-nOverlap)/(blockSize-nOverlap)); nLost = mod((nSamples-nOverlap),(blockSize-nOverlap)); windowFcn = windowFcn(:); %% making sure windowFcn is a column vector Gij = zeros(nFFT,nCh,nCh); %% cross- and autopower spectral density functions scaleFactor = (nFFT/blockSize)*nAvg*sum(windowFcn)^2; %% quad. normalising scale factor freq = [0:(nFFT-1)]'*Fs/nFFT; %% frequency vector tmp = zeros(nFFT,nCh); % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % CROSS- AND POWER SPECTRA % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % inxSelect = [1:blockSize]; %disp(['Calculating spectral density functions, nAvg = ' int2str(nAvg) ', nLost = ' int2str(nLost)]); for loop=1:nAvg tmp = TH(inxSelect,:)-repmat(mean(TH(inxSelect,:)),blockSize,1); %% Removing BIAS %tmp = detrend(TH(inxSelect,:)); %% select a block and de-trend tmp = tmp.*repmat(windowFcn,1,nCh); %% apply window to signal(s) tmp = fft(tmp,nFFT); %% FFT for ii = 1:nCh for jj = ii:nCh Gij(:,ii,jj) = Gij(:,ii,jj) + tmp(:,ii).*conj(tmp(:,jj)); end end inxSelect = inxSelect + round(blockSize-nOverlap); end for ii = 1:nCh for jj = (ii+1):nCh Gij(:,jj,ii) = conj(Gij(:,ii,jj)); end end Gij = Gij/scaleFactor; % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % IF NUMBER OF OUTPUT ARGUMENTS &gt; 2 % % % =&gt; OUTPUT SINGLE SIDED AMPLITUDE SPECTRUM % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % if(nargout&gt;2); % % Selecting single sided spectrum (assuming real signal) if(rem(nFFT,2)==1); % nFFT odd inx = [1:(nFFT+1)/2]'; else inx = [1:nFFT/2+1]'; end spec.x = freq(inx); %% frequency vector spec.y = zeros(length(inx),nCh); for ii=1 : nCh spec.y(:,ii)=sqrt(Gij(inx,ii,ii)*2); end %% PSD % PSD = (Gij(inx,ii,ii)*2)/df/windowLSS; %% needs window LSS to calc from AP % PSD = spec.y .^2/df/windowLSS; % RMS_PSD = sqrt(df*sum(PSD)); spec.Fs = Fs; spec.nFFT = nFFT; spec.RMSinfo = char('RMS(time) = sqrt(mean(abs(x).^2))','RMS(spec) = sqrt(sum(spec.y.^2)/windowLSS)','NOK for signals with BIAS ~= 0'); end </code></pre> Answer: <p>actually decreasing sampling frequency may create the aliasing effect (sampled signal will be distorted and nothing similar to the original one) </p> <p><a href="http://en.wikipedia.org/wiki/Aliasing" rel="nofollow">http://en.wikipedia.org/wiki/Aliasing</a></p> <p>if You want to properly sample Your signal use Nyquist - Shannon theory, which states that sampling frequency should be at least twice the signal frequency (it was proven that twice is enough and further increasing sampling rate does not gives better results)</p> <p><a href="http://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem" rel="nofollow">http://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem</a></p> <p>thus Your sampling rate should be at least 6000Hz (sampling frequency of the sinus signal) </p> <p>could You also provide the matlab code You used in this?</p>
https://dsp.stackexchange.com/questions/15151/fft-analysis-of-longer-data-sets
Question: <p>I'm new to frequency domain analysis. Let's say I have a frequency domain representation from a time domain signal. What I want to do is taking frequencies with a low amplitude out of this frequency domain representation and then convert this frequency domain representation back to the time domain such that the result is almost the original time domain representation. </p> <p>In Matlab what I want to do is something like this:</p> <p>timeDomain(1:50) -> apply fft(timeDomain) -> inspect frequency domain and filter out low amplitude frequencies yielding a frequency domain vector x with length(x) probably (way) smaller than 50. (so x should contain only the frequencies with the highest amplitudes of the signal) -> apply ifft on this filtered complex vector -> Get an approximation of the original time domain signal (timeDomain(1:50) that has also length 50.</p> <p>So my aim is to represent the time domain signal timeDomain(1:50) with less dimensions in the frequency domain without too much information about the signal getting lost, thus being able to reconstruct the time domain signal, so basically compression.</p> <p>Thanks for your time.</p> Answer: <p>Everything depends on what you call compressing. What you are proposing is Fourier or spectrum thresholding. You will generate a $50$-length vector with some zeroes, hopefully. Let us ignore "complexness" that requires two floats for now, you can deal with it using Hermitian symmetry. </p> <p>Your main problem is actual compression. Forget about quantization first. The main issue is index location. Assume I have a transformed domain vector $T=[5, 1, 3 ,4, 0.5]$. Suppose I use a threshold on $2$. Now I give you the compressed version $T_c=[5, 3 ,4]$, a ratio of $3/5$. </p> <p>Can you retrieve $T_d=[5, 0, 3 ,4, 0]$? Probably not, you do not know where the zeroes were. This problem somehow prevented matching pursuit to be used for image compression, because coding the index penalized the final compressed file too much.</p>
https://dsp.stackexchange.com/questions/30602/compressing-a-time-domain-signal-in-the-frequency-domain-matlab
Question: <p>What are the Pros and Cons of using Wigner-Ville Distribution for spectral analysis of a signal vs taking the STFT. When is it appropriate to use one over the other and is WVD used in real-time implementations?</p> <p><strong>Update:</strong> Since no answers were received for the first few days of this post, I tried posting the same question on ChatGPT and below is the response I got from it:</p> <p><em>The WVD is a time-frequency representation that provides a high degree of resolution in both time and frequency. It is useful for analyzing signals that have non-stationary properties, such as chirps and transient signals. The WVD can also distinguish between closely spaced frequency components, and can also show the instantaneous frequency of a signal.</em></p> <p><em>On the other hand, the STFT is a widely used method in signal processing, and is useful for analyzing signals that are stationary or have slow time-varying properties. It provides a high degree of frequency resolution, but its time resolution is limited. Unlike WVD, it is not able to distinguish between closely spaced frequency components, and it does not show the instantaneous frequency of a signal to the degree in which WVD can.</em></p> <p><em>The major disadvantage of the WVD is the computational cost. It has a computational complexity of O(N^2) which makes it impractical for large data sizes.</em></p> <p>Is the above response true or false?</p> <p>I had originally added this as a possible answer, removed it due to objection from a member (Jdip) due to inaccuracy and adding it back as part of question as asked by a member (OverLordGoldDragon) in the comments. Hope posting ChatGPT responses is not against the rules or anything.</p> <p>Peter K. also mentioned a <a href="https://ieeexplore.ieee.org/document/149998" rel="nofollow noreferrer">link</a> to his publication in the comments of the deleted answer which I am adding here as well.</p> <p>Peter K. also mentioned in OverlordGoldDragon's answer that the WVD is not very much useful in the presence of noise, a separate question has been added <a href="https://dsp.stackexchange.com/questions/86297/comparison-of-wvd-and-stft-spectral-analysis-in-the-presence-of-noise">here </a> for discussion on that in case anyone is interested.</p> Answer: <p>I preface this answer with that I know little about WVD and never worked with it, but do know time-frequency, and synchrosqueezing, which shares similarities. Part of my answer will be for SSQ.</p> <h3>Re: ChatGPT</h3> <blockquote> <p>The WVD is a time-frequency representation that provides a high degree of resolution in both time and frequency.</p> </blockquote> <p>No, oversimplified</p> <blockquote> <p>It is useful for analyzing signals that have non-stationary properties, such as chirps and transient signals. The WVD can also distinguish between closely spaced frequency components, and can also show the instantaneous frequency of a signal.</p> </blockquote> <p>Yes</p> <blockquote> <p>On the other hand, the STFT is a widely used method in signal processing, and is useful for analyzing signals that are stationary or have slow time-varying properties.</p> </blockquote> <p>So is DFT, misses the point</p> <blockquote> <p>It provides a high degree of frequency resolution, but its time resolution is limited.</p> </blockquote> <p>Nonsense, the whole point is we can tune it</p> <blockquote> <p>Unlike WVD, it is not able to distinguish between closely spaced frequency components,</p> </blockquote> <p>No</p> <blockquote> <p>and it does not show the instantaneous frequency of a signal to the degree in which WVD can.</p> </blockquote> <p>Yes</p> <blockquote> <p>The major disadvantage of the WVD is the computational cost. It has a computational complexity of O(N^2) which makes it impractical for large data sizes.</p> </blockquote> <p>No</p> <h3>Re: dorian111</h3> <blockquote> <p>When increasing the sampling length to improve the frequency domain resolution, the time domain resolution will deteriorate.</p> </blockquote> <p>I can't tell if this refers to WVD or STFT. For STFT or any localized time-frequency method, it's wrong - the sampling <em>rate</em>, not <em>duration</em>, affects time resolution. WVD appears to have a global temporal operator, so it may be true there.</p> <blockquote> <p>For WVD, it is generally believed that it is not limited to the uncertainty principle and can achieve the maximum mathematical accuracy of frequency domain resolution.</p> </blockquote> <p>No method completely escapes Heisenberg, but it's true we can achieve practically perfect localization for certain classes of signals.</p> <blockquote> <p>The general conclusion is that the accuracy of WVD is much higher than that of STFT.</p> </blockquote> <p>No. This isn't even true for synchrosqueezing, which significantly improves upon WVD. The worst case in SSQ vs STFT is close, I can't say SSQ is better, and certainly not &quot;much better&quot;. But it is true that the <em>best</em> case for SSQ is far superior.</p> <blockquote> <p>The disadvantage is that the frequency spectrum will appear pseudo-frequency when there are multiple frequency signals in the data.</p> </blockquote> <p>Unsure what this means, WVD is time-frequency, there's no &quot;frequency spectrum&quot; in standard sense. It's true that introducing additional intrinsic modes worsens WVD, esp. with &quot;quadratic interference&quot; (that SSQ lacks).</p> <blockquote> <p>Compared with STFT, the calculation cost is much higher, and the performance is the difference between O(N2log(N)) and O(kNlog(N)). When the STFT sliding length is taken as the minimum limit of 1, k=N, and the performance of WVD is the same.</p> </blockquote> <p>Not necessarily. The compute burden depends on what we need WVD for, and whether we window. Of chief consideration is information, and how much we lose, which <a href="https://dsp.stackexchange.com/a/80920/50076">can be measured</a> - and conversely, how much we gain by computing the full WVD as opposed to a part of it. The original MATLAB synchrosqueezing toolbox used <code>n_fft=N</code>, with logic that DFT is length N, and which most will agree is completely unnecessary.</p> <p>Without windowing, I imagine WVD is like a fancified Hilbert transform and struggles with <a href="https://dsp.stackexchange.com/a/83257/50076">more than one component</a> - see <a href="https://www.di.ens.fr/%7Emallat/papiers/WaveletTourChap1-2-3.pdf" rel="nofollow noreferrer">Figure 4.18</a> and below. Windowing, particularly with kernels which make WVD complex, enable tremendous optimization, similar to CWT. These optimizations are unrealized in most code... <a href="https://dsp.stackexchange.com/a/83495/50076">for now</a>.</p> <blockquote> <p><span class="math-container">$$X(\tau,f)=\int_{-\infty}^\infty x(t)w(t-\tau)e^{-j2\pi f t}dt $$</span></p> </blockquote> <p>This is a correct STFT formulation which is what most libraries implement, but I'd like to note that <a href="https://github.com/librosa/librosa/issues/1279" rel="nofollow noreferrer">it's bad</a>.</p> <blockquote> <p><span class="math-container">$$W_x(t,f)=\int_{-\infty}^{\infty}x(t+\frac\tau{2})x^{*}(t-\frac\tau{2})e^{-j2\pi f\tau}d\tau $$</span></p> </blockquote> <p>From this formula, something sticks out: <span class="math-container">$x(... \pm \tau)$</span>. This screams boundary effects - a major disadvantage compared to STFT.</p> <hr> <h3>Re: original question</h3> <p>Two major advantages of the <em>spectrogram</em> (<code>abs(STFT)</code>) over WVD, or at least SSQ, is <em>stability</em>, and <em>sparsity</em>. SSQ, as a feature, is quite brittle to noise (in some ways, yet also more robust in other ways, see <a href="https://dsp.stackexchange.com/a/71399/50076">related</a>). Sparsity may come as a surprise, as SSQ claims that's <em>its</em> advantage over STFT - and it is - but the form of sparsity that matters a lot is <em>subsampleability</em>.</p> <p>Note, <code>hop_size</code> is just the subsampling factor for STFT. We can hop in the spectrogram because there's high redundancy along time, and doing so loses little information. Not the case with SSQ, which generates rough and spiky time-frequency geometries - subsampling it a lot means losing a lot, and <em>not</em> subsampling likewise means keeping too many data points to be useful for machine learning, not because of data size, but correlated features prone to overfitting.</p> <p>As I understand, WVD is more a measurement tool - it can be used to describe time-frequency characteristics of time-frequency kernels, e.g. wavelets. Though really I don't know where its applicability ends.</p> <p>Lastly, third major advantage, STFT doesn't straight up invent signals:</p> <img src="https://i.sstatic.net/VgN8X.png" width="800"> <p><a href="https://www.di.ens.fr/%7Emallat/papiers/WaveletTourChap1-2-3.pdf" rel="nofollow noreferrer">Figures 4.18 &amp; 4.20, Wavelet Tour</a>. Left is plain WVD, such interference is a dealbreaker for most applications. Right is windowed WVD, which attenuates interferences, but &quot;reduces the time-frequency resolution&quot; (under Eq 4.156).</p>
https://dsp.stackexchange.com/questions/86211/wigner-ville-distribution-wvd-vs-stft-for-spectral-analysis
Question: <p>I am analyzing some time series of sea surface water temperature and am using wavelet analysis to do so. I am computing the continuous wavelet transform and then removing some specific frequencies and then converting the series back from the frequency to the time domain. I am following the methods of torrence and compo 1998 (Practical guide to wavelet analysis) to perform this operation but am a bit confused as to why my results are not as expected. As an example, I will fist decompose the time series into the frequency domain and then reconstruct the signal without altering any of the coefficients:</p> <p><img src="https://i.sstatic.net/q4KIA.png" alt="enter image description here"></p> <p>In the attached figure we have the original series in red and the reconstructed series in blue, straight away we can see that the the reconstructed signal is much lower than the original series. The main reason I think this occurs is that the wavelet transform normalizes the series to have unit energy (in order to compare the coefficients across scales). Therefore, I was wondering if it was possible to convert the reconstructed signal back to have the same magnitude (?) as the original series i.e. reverse the normalizing to have unit energy stage?</p> Answer: <p>Take the mean of the original signal and add it to the reconstructed signal. IIRC wavelets have no DC response, and so the reconstructed signal will have 0 mean.</p>
https://dsp.stackexchange.com/questions/7822/wavelet-analysis-normalized-to-have-unit-energy
Question: <p>I have been working with some seismic data and recently submitted a paper to a journal.</p> <p>My seismic data has 493 traces: each trace are 8300 seconds long with sampling frequency of 2000 Hz.</p> <p>One of the reviewers is asking me to generate a frequency spectrogram at the time= 2000s for all signals. My knowledge about the spectrogram is that you can only do it for one signal and there should be a time window to run the frequency analysis on. How can I do it? </p> <p>Here are more detail about my problem: These 493 traces recorded vibration around a cable in a oil producing horizontal well. The traces are 16ft away from each other along the well. The idea of the publication was to assess the spectrogram for traces on a specific location that was the target for hydraulic fracturing. The figure below is the spectrogram of one of the traces (signals) close to the target zone. Note that there are 492 other traces and all of them have the same number of samples, frequency, and length. All these traces recorded vibration for the entire 8300secon. The question is how I could generate spectrogram of all 493 traces for example at 2000 second. Here is the wording of the reviewer: "I welcome the addition of a spectrogram showing many channels at one particular time interval." The paper is accepted, But I think it's better to address the reviewer's comment. I will appreciate your name in my acknowledgment.</p> <p><a href="https://i.sstatic.net/4TVfX.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/4TVfX.png" alt="enter image description here"></a></p> Answer: <blockquote> <p>"I welcome the addition of a spectrogram showing many channels at one particular time interval."</p> </blockquote> <p>If you don't want to include it, or don't have enough space, it is always worthwhile to put them in a supplementary file, attached to the journal, or separately on the Internet. I suggest the reviewer is looking for an onset phenomenon, and it would be easy to generate a few crops in time interval <span class="math-container">$[1500-2500]$</span> side-by-side, potentially for only a tenth of your data (about 50 signals).</p>
https://dsp.stackexchange.com/questions/53014/spectrogram-of-493-signals-at-a-time
Question: <p>My inquiry is regarding the so called <a href="https://en.wikipedia.org/wiki/Cepstrum" rel="nofollow noreferrer">cepstrum</a> analysis.</p> <p>By conducting some experiments, i have real time data at my disposal. The acquisition rate is 1600Hz.</p> <p>I wanted to try cepstrum analysis just out of curiosity to see how it performs in comparison with trivial spectral analysis.</p> <p>So what i do with the acquired data:</p> <ol> <li>Use a lowpass filter with a cut-off frequency of 340 Hz for noise attenutation.</li> <li>Fourier transform the filtered data, removing the DC component by subtracting the mean value from the filtered data.</li> <li>Take the log of the magnitude of the FFT.</li> <li>Apply IFFT on the resulting vector to acquire the real cepstrum.</li> </ol> <p>I notice that, despite the filtering that has taken place at step 1, the cepstrum plot displays activity beyond the cut-off frequencies. So my question is this: Is this supposed to happen? To me it seems that this is not normal. Does anyone have any experience with that?</p> <p>Edit: Plot image added for clarification. Frequencies of interest lie on the right of the red line displayed</p> <p><a href="https://i.sstatic.net/UlEUd.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/UlEUd.jpg" alt="Cepstrum vs Quefrency plot"></a></p> Answer: <p>Presence of frequencies above cutoff in Cepstrum could be because of - </p> <ul> <li>Is lowpass filter used a perfect lowpass filter(does it removes all the frequencies above cutoff or just attenuates them) ?</li> <li>If lowpass filter is not perfect, what are the relative magnitudes of high frequencies(above cutoff) with respect to low frequencies. if high frequencies are relatively dominant then they will be visible in cepstrum.</li> </ul> <p>also "Fourier transform the filtered data, removing the DC component by subtracting the mean value from the filtered data."</p> <p>After fourier transform subtracting mean should not be the way to remove DC.</p>
https://dsp.stackexchange.com/questions/38837/cepstrum-analysis-cut-off-frequencies-displayed
Question: <p>A continuous time domain system is well described by the Laplace transform. It allows to express any continuous signal x(t) as the integral sum of weighted complex and exponentially growing/decaying sine waves <span class="math-container">$e^{st} = e^{\sigma t} \cdot e^{j\omega t}$</span>:</p> <p><a href="https://i.sstatic.net/eH2aH.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/eH2aH.png" alt="enter image description here" /></a></p> <p>Where X(s) is the Laplace Transform and may be evaluated as:</p> <p><a href="https://i.sstatic.net/z0JHz.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/z0JHz.png" alt="enter image description here" /></a></p> <p>The variable of interest (on which the Laplace Transform depends) is the complex angular frequency <span class="math-container">$s = \sigma + j\omega$</span>. If <span class="math-container">$\sigma= 0$</span>, the Laplace Analysis coincides with the Fourier analysis since <span class="math-container">$s = j\omega$</span></p> <p>In a discrete time Frequency, the Z transform is usually used:</p> <p><a href="https://i.sstatic.net/sa5LJ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/sa5LJ.png" alt="enter image description here" /></a><a href="https://i.sstatic.net/kOJ3h.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/kOJ3h.png" alt="enter image description here" /></a></p> <p><a href="https://i.sstatic.net/phUIt.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/phUIt.png" alt="enter image description here" /></a><a href="https://i.sstatic.net/GRnPE.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/GRnPE.png" alt="enter image description here" /></a></p> <p><strong>Questions</strong></p> <ol> <li><p>What does the synthesis equation of Z Transform mean? Does it mean that the discrete time domain sequence is expressed as the sum of weighted complex power functions <span class="math-container">$z^{n-1}$</span>?</p> </li> <li><p>Is <span class="math-container">$z$</span> the variable of interest? Often I read that if we replace z with <span class="math-container">$e^{j\omega t}$</span>, we get the DFT. Correct, but the DFT is an exponential function of <span class="math-container">$\omega$</span>, and not a power function of <span class="math-container">$z$</span>. Which is (between <span class="math-container">$z$</span> and <span class="math-container">$\omega$</span>) the variable of interest for a discrete time sequence and why?</p> </li> <li><p>I think understanding which is the significant variable (between <span class="math-container">$z$</span> and <span class="math-container">$\omega$</span>) is crucial to understand <a href="https://en.wikipedia.org/wiki/Bilinear_transform#Frequency_warping" rel="nofollow noreferrer">Frequency warping</a>, that is the frequency distorsion due to the fact that the real angular frequency axis <span class="math-container">$[-\infty;+\infty]$</span> becames the unit circumference <span class="math-container">$z = e^{j\omega t}$</span> . Well, but this is due only to the fact that <strong>we decide that the variable of interest for a discrete-time sequence is z instead of <span class="math-container">$\omega$</span></strong>. Also Fourier (and Laplace) Transform of continuous signals contains <span class="math-container">$e^{j\omega t}$</span>, but we don't say &quot;We put <span class="math-container">$z = e^{j\omega t}$</span> hence there is distorsion&quot;, and the variable of interest is assumed to be <span class="math-container">$\omega$</span>. I've never seen people complaining about this for continuous signals.</p> </li> </ol> <p>It seems that: &quot;Until it's continuous, <span class="math-container">$\omega$</span> is important. When your signal becomes discrete, <span class="math-container">$z$</span> is important&quot;. But I do not understand why.</p> Answer: <p>The z-transform is the discrete version of the Laplace transform and in both cases z and s are the set of all complex numbers, and as such we map with the transform the time domain function into the domain of complex frequencies; signals that change in rotation only which is the Fourier Transform and in addition to that such signals that can grow and decay in time. This leads to great mathematical simplifications, for example doing this will translate integral-differential equations into simple algebra.</p> <p>The question is better phrased &quot;why use z instead of s&quot;, as what we would refer to as the frequency “axis” is a one dimensional subset of the complex surface for both cases: In the s plane, the frequency axis is the <span class="math-container">$j\omega$</span> axis (the imaginary axis of the s-plane) and in the z-plane, the frequency axis is the unit circle.</p> <p>The significant convenience of the z-plane is clear when you compare the equations for the Laplace Transform, to the Laplace Transform for a discrete time sequence, and finally with a simple substitution of <span class="math-container">$z= e^{sT}$</span> in the Laplace Transform for the discrete time sequence we arrive at the z-transform. Notably, this translates a transcendental equation to a simple polynomial that we can resolve to finite poles and zeros and takes advantage of the repetition in discrete time resulting in a much simpler equation for further manipulation. One can continue to process everything using Laplace, both continuous time and discrete time waveforms, but why take that punishment when the z-transform can be used instead for the discrete time cases?</p> <p>Consider the Laplace Transform for a causal continuous time sequence:</p> <p><span class="math-container">$$X(s) = \int_{t=0}^{\infty} x(t) e^{-st }dt$$</span></p> <p>The Laplace Transform when applied to a discrete time sequence becomes:</p> <p><span class="math-container">$$X(s) = \sum_{n=0}^{\infty} x(nT) e^{-snT}$$</span></p> <p>Note this simple case of applying this formula to solve for the Laplace Transform of a discrete-time two sample moving average, and then solving for the poles and zeros:</p> <p><a href="https://i.sstatic.net/zfumm.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/zfumm.png" alt="example" /></a></p> <p>If we substitute <span class="math-container">$z = e^{sT}$</span> the transform then becomes the &quot;z Transform&quot; as:</p> <p><span class="math-container">$$X(z) = \sum_{n=0}^{\infty} x(nT) z^{-n}$$</span></p> <p>And the example above becomes the much simpler polynomial ratio as:</p> <p><span class="math-container">$$H(z) = \frac{1}{2}+\frac{1}{2}z^{-1} = \frac{z+1}{2z}$$</span></p> <p>This simplification is not limited to discrete-time systems as we can have similar complexities in continuous time of transfer functions involving fixed delays (with the same challenge of having a transcendental equation versus simpler polynomials of fixed order), in which case we could make the same substitution to proceed with further processing and mathematical manipulation. The point is that in discrete time this always occurs that we are working with systems of consistent unit delays, and the z-transform abstracts that exponential that is always there and avoids us from carrying it through every computation unnecessarily. It is much simpler. This is no different from other mathematical mappings and change of basis with the main objective that in the new space it is much easier to manipulate the equations and find solutions, and if the original space was important, we can transform back to that after all the heavy lifting is done.</p> <p>Frequency warping only occurs if we choose to map transfer functions from continuous time to discrete time using the Bilinear Transform method and this is only because this method will provide a one to one mapping from the unique continuous frequency domain which extends to <span class="math-container">$\pm \infty$</span> to the unique frequency domain for sampled systems which extends from <span class="math-container">$-f_s/2$</span> to <span class="math-container">$+f_s/2$</span>. Other mappings exist with no warping but will instead have aliasing.</p>
https://dsp.stackexchange.com/questions/75831/why-is-z-and-not-%cf%89-the-variable-of-interest-for-discrete-time-systems
Question: <p>I'm looking for a Fourier analysis method that will help me with a servo position tracking problem. I'll give some background:</p> <p>Imagine I have a control system that attempts to control a linear actuator to a submicron position. I have a following error signal in units of nanometers that I monitor. In an ideal world, this following error signal would be zero because my control system is perfect. Unfortunately, my system is not perfect and this signal dithers. In order to better understand the following error signal, I want to perform some Fourier analysis on the signal to see how the position error amplitudes map to the frequency domain. Ideally, I would be able to look at the analysis and make a statement: &quot;For my 1000nm peak following error in the time domain, 800nm correspond to frequency range X, 100 nm frequency range Y, and the remaining 100nm correspond to the remaining range&quot;.</p> <p>However, I'm not sure what spectral analysis would actually be able to answer this. Here are are my current thoughts / questions:</p> <ul> <li>If I were to perform a basic DFT over over a range of data, I could apply amplitude normalization. However, because the signal is random the number of frequency bins will influence the amplitude calculation (i.e. longer signal will decrease FFT amplitudes). Now this might be okay since I could integrate the bins over a specific frequency range.</li> <li>Ideally integrating over the entire frequency spectrum would yield the peak error value of the time domain signal. However, the phases of each frequency component would influence how &quot;additive&quot; two frequencies are.</li> <li>I've been studying the usage of the PSD which seems like it could be useful since this is a random signal, however, I don't care about the power of the signal. I truly just care about the amplitude of the signal since it corresponds to position error.</li> </ul> <p>Ultimately I think this is a scaling problem. Of course it would be trivial to see what frequency components are influencing my systems performance, but more importantly, I want to account for every nanometer of that peak follow error in the frequency spectrum.</p> <p>Edit for further clarification on what I'm ultimately interested in: When taking the FFT of my error signal and amplitude scaling it (i.e. dividing the magnitude by the number of sample points), I notice that most of the error is centered around 60hz but is distributed among a 10hz bandwidth window. So in other word, most of the error frequency content is found between 55hz and 65hz. My natural next question would be: &quot;If I could clean up at that 60hz random noise that might clear up most of that 10hz noise window, how much would that improve my following error?&quot;. I can't simply integrate over that 10hz bandwith per @TimWestcotts answer below, so what method would allow me to quantify the error attributed to that 10hz range?</p> Answer: <p>Possibly the reason this question has lain fallow is because it contains a factual error, and cannot be answered as stated.</p> <blockquote> <p>&quot;For my 1000nm peak following error in the time domain, 800nm correspond to frequency range X, 100 nm frequency range Y, and the remaining 100nm correspond to the remaining range&quot;</p> </blockquote> <p>In general, you can't do that, because except under very specific conditions, the <em>amplitudes</em> of signals of different frequencies do not add, or integrate. Rather, the power (or at least the signal amplitude squared) will add or integrate.</p> <p>So you could say that out of a total <span class="math-container">$1 \cdot 10^{-12} \mathrm{m^2}$</span> of mean-squared error, <span class="math-container">$8 \cdot 10^{-11} \mathrm{m^2}$</span> is in frequency range X, <span class="math-container">$1 \cdot 10^{-11} \mathrm{m^2}$</span>, <span class="math-container">$1 \cdot 10^{-11} \mathrm{m^2}$</span> is in frequency range Y, and the remaining <span class="math-container">$1 \cdot 10^{-11} \mathrm{m^2}$</span> is elsewhere.</p> <blockquote> <p>however, I don't care about the power of the signal. I truly just care about the amplitude of the signal since it corresponds to position error.</p> </blockquote> <p>Unfortunately, signal power is what you have to work with, just like all the rest of us.</p> <p>You <em>can</em> talk about the RMS value of the signal in your frequency ranges: just take the square roots of the power values. The RMS values won't add up to the total signal RMS value, but you'll at least be speaking in a sensible way that people can understand.</p>
https://dsp.stackexchange.com/questions/96070/what-fourier-analysis-would-be-appropriate-for-analyzing-servo-position-error-as
Question: <p>I have performed a cross-correlation analysis using <em>scipy.signal.correlate</em> to determine the phaseshift (time delay) between two sine waves that I have recorded with a 180MHz digitizer. To increase the resolution of the time delay, I performed upsampling with different factors. I found a oscillating, but converging behaviour of the determined time delay with increasing upsampling factor.</p> <p>For verification, I determined the time delay with a second method, FFT, where the frequency binning hits exactly the true frequency.</p> <p>I'm observing that for high upsampling factors, the time-delay determined via cross-correlation converges towards the FFT method, but shows an oscillating behaviour around the value determined using FFT. Does anybody have know where this oscillating behaviour comes from?</p> <p><a href="https://i.sstatic.net/eDE0COvI.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/eDE0COvI.jpg" alt="time delay vs upsampling" /></a></p> Answer: <p>thank you!</p> <p>Yes, sure. I am using scipy.signal.resample for the upsampling. Here is some of the code I used to produce this:</p> <pre><code>def cross_corr(signal1, signal2, sampling_rate, upsampling,T_ns, method): corr = signal.correlate(signal.resample(signal1,len(signal1)*upsampling), signal.resample(signal2,len(signal2)*upsampling), mode='full', method = method) lags = signal.correlation_lags(signal1.size*upsampling,signal2.size*upsampling, mode = &quot;full&quot;) max_lag = lags[np.argmax(corr)] dt = max_lag * (1/sampling_rate) / upsampling * 1e9 if dt &lt; 0 and dt &gt; -T_ns: return dt + T_ns elif dt &gt; T_ns: return dt - T_ns else: return dt </code></pre> <p>My data consists of two 2400 sample long traces of a digitizer. I did the following to determine the time delay depending on the upsampling:</p> <pre><code>up_max = 500 upsampling = np.linspace(1,up_max,up_max) trace = all_traces['2k4'][1] dt_upsampling_2k4 = [] for i in upsampling: dt_upsampling_2k4.append(cross_corr(trace.CH2,trace.CH1, sampling_rate =180*1e6,upsampling = int(i), T_ns = (1/(60*1e6))*1e9 )) </code></pre> <p>In the end, I have plotted delta t against the upsampling factor.</p>
https://dsp.stackexchange.com/questions/96192/converging-behaviour-with-upsampling-in-cross-correlation-analysis
Question: <p>I am working on balancing an air-spindle. For the unbalance analysis I use an accelerometer (NI device). I have the voltage signal from the accelerometer corresponding to the vibration of spindle at a particular frequency (rpm) saved in an excel file. To analyze the unbalance from this vibration signal I use the <code>fft</code> function in MATLAB. My data is sampled at a sampling frequency of $100,000\textrm{ Hz}$. I am using the same example code given in the <code>fft</code> documentation. The result of fft is as shown. </p> <p><a href="https://i.sstatic.net/rIXxW.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/rIXxW.jpg" alt="FFT Plot"></a>.</p> <p>The present signal consists of signals of various frequency. How can I filter this result in order to get only the signal of frequency equal to my rotational frequency ($40\textrm{ Hz}$). I would need this signal to calculate the vibration phase and magnitude by comparing it with the tachometer signal. My MATLAB code looks like this: </p> <pre><code>%For vibration analysis of signal without any trial mass. filename = '2400RPM.xlsx'; sheet = 1; xlRange = 'C40:C516039'; x = xlsread(filename,sheet,xlRange); T=1/100000; L=length(x); Fs=1/T; t=(0:L-1)*T; Y = fft(x); mag1 = abs(Y/L); mag = mag1(1:L/2+1); mag(2:end-1) = 2*mag(2:end-1); ph1 = rad2deg(Y/L); ph = ph1(1:L/2+1); ph(2:end-1) = 2*ph(2:end-1); f=Fs*(0:(L/2))/L; %PLOTTING RESULTS %-------------------------------------- subplot(2,2,[1,2]) plot(t,x); title('Vibration Signal: 2400RPM'); xlabel('Time (seconds)'); ylabel('Amplitude (voltage)'); subplot(2,2,3) plot(f,mag); title('Magnituge Plot'); xlabel('Frequency (Hz)'); ylabel('Amplitude'); subplot(2,2,4) plot(f,ph); title('Phase Plot'); xlabel('Frequency (Hz)'); ylabel('Phase (degree)'); </code></pre> <p>Any help is much appreciated.</p> Answer: <p><strong>NOTE:</strong> (Updated noting the sampling rate and desired frequency) Your post describes extracting a 40 Hz signal at a 100,000 Hz sampling rate. Your filtering implementation will be significantly easier (and more effective) if you apply course low pass filtering and decimation to a lower rate before applying the 2nd order tuned resonator derived from an exponential averager as shown in detail below. Please review this post <a href="https://dsp.stackexchange.com/questions/31548/fast-integer-8-hz-2nd-order-lp-for-microcontroller/31553#31553">Fast Integer 8 Hz 2nd Order LP for Microcontroller</a>. I suggest decimating to a 200 Hz sampling rate which is a decimate by 500 (in stages such as 5-10-10). </p> <p>Once decimated, consider using an exponential averager implementation, following this post for converting the lowpass filter to a bandpass, tunable to any frequency including your desired 40Hz:</p> <p><a href="https://dsp.stackexchange.com/questions/31028/transfer-function-of-second-order-notch-filter/31030#31030">Transfer function of second order notch filter</a></p> <p>The difference between the notch filter in the post above and an exponential averager, is that the exponential averager has the following transfer function:</p> <p>$$H(z) = \frac{\alpha z}{z+\alpha-1}$$</p> <p>I think you will see the similarity and be able to follow the process in the linked post above. A diagram of the implementation as an "Exponential Averager" or low pass filter is shown below. This would create a maximum at DC and would need to be converted to a bandpass implementation similar to what was done in the linked post.</p> <p><a href="https://i.sstatic.net/zUWGt.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/zUWGt.png" alt="exponential averager"></a></p> <p><strong>UPDATE:</strong> In pursuing the transformation myself I came up with the following result:</p> <p>$$ H(z) = K\frac{z^2}{z^2-2\beta \cos\omega_n z+\beta^2} $$</p> <p>Where: </p> <p><strong>(update, adding the closed-form equation for K)</strong></p> <p>K is a normalizing constant that is dependent on $\omega_n$ and $\alpha$ given as:</p> <p>$$K= \alpha \sqrt{\beta^2-2\beta cos(2 \omega_n)+1}$$</p> <p>$\omega_n$: center normalized radian frequency, between 0 and $2\pi$</p> <p>$\alpha$: bandwidth constant, bandwidth gets tighter as $\alpha$ approaches 0.</p> <p>$\beta = 1- \alpha$</p> <p>The resulting implementation as a tuned 2nd order resonator is shown below.</p> <p><a href="https://i.sstatic.net/GVtL1.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/GVtL1.png" alt="Tuned 2nd order resonator"></a></p> <p>Below are two examples with different bandwidths at center frequency $\omega_n=\pi/3$. The first plot is with $\alpha =0.1$ and the second plot is with $\alpha = 0.001$. </p> <p><a href="https://i.sstatic.net/uTaTO.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/uTaTO.png" alt="First Frequency Response Example"></a></p> <p><a href="https://i.sstatic.net/a2UMo.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/a2UMo.png" alt="Second Frequency Response Example"></a></p> <p>Note that the very long delay this second filter would have as evidenced by the very steep phase slope through the passband (group delay = $d\phi/d\omega$), as required for any tight bandwidth filter. This would also mean a relatively long convergence time. Given the ability to tune bandwidth and center frequency independently, you can envision how this can enable an optimized implementation for certain applications that is initially wide band for fast convergence while the bandwidth tightens over time to maximize SNR for the signal of interest. This structure can also be used as a bandpass loop filter or in a bandpass Sigma Delta implementation for bandpass sampling.</p> <p>Below is an equivalent form of the exponential averager that only requires one multiplier as Rick Lyons has shown at the site linked below. Here I have chosen $\alpha$ to be similar to what Rick had done, in that $\alpha$ is a small number approaching 0 to make the bandwidth tighter (this is in contrast to my other post linked above for the notch filter implementation where I used $\alpha$ approaching 1 to be a tighter bandwidth, so swapping $\alpha$ with $1-\alpha$ between these two posts. I think the formula is cleaner if you actually use $\alpha$ as the number approaching 1, in that it eliminates my need to use $\beta$ as I have done above without the formulas appearing too cumbersome.</p> <p><a href="https://www.dsprelated.com/showarticle/182.php" rel="nofollow noreferrer">https://www.dsprelated.com/showarticle/182.php</a></p> <p><a href="https://i.sstatic.net/QcJrK.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/QcJrK.png" alt="enter image description here"></a></p>
https://dsp.stackexchange.com/questions/40482/fft-analysis-for-vibration-signal
Question: <p>I'm in the process of building features for an EEG machine learning problem and have been doing some reading about what features may be useful. Turns out, that alpha band (8-12Hz) power can make a good distinction between my categories. The nuance is that for 1 category, alpha power rises and then falls over the time series, but for the other category alpha power begins low and then rises</p> <p>I have a butterworth filtered signal which gives me a fairly clean alpha wave, but is it possible to determine power of this band at every time point over the series?</p> <p>If I can get away with doing the calculations on just the filtered signal then that'd be ideal, without having to resort to running an FFT (the eventual goal is to do this online and my concern is speed)</p> <p>Could it simply be the squared amplitude at every time point? Or do I need to run a specific FFT/time-frequency type analysis for this?</p> <p>I've been trying to find some Python code for this but haven't had much luck because I mostly am not sure the best way forward</p> Answer: <p>The Goertzel algorithm allows you to compute individual terms of the Discrete Fourier Transform, and is more efficient than the FFT. However, if you wish to later compute the spectrum of other bands besides alpha, Goertzel will turn out to be more computationally expensive than the FFT.</p> <p>Unless you are seriously limited by computational power, in principle, you can compute the Fast Fourier Transform in quasi-real-time, using a sliding window (also known as the Short Time Fourier Transform, or STFT). The Discrete Wavelet Transform is also sometimes used for real-time EEG power estimation. To find the power in the alpha band, you can look at the corresponding frequency bins of the STFT for either the original or the filtered signal.</p> <p>The output of the STFT will be delayed by the length of your window (as you need all the samples inside the window to arrive before computing the power in that time bin). However, with a window length of 512 samples under 8kHz sampling rate, for example, this amounts to 0.064 seconds delay, which is fairly close to 0.0 seconds!</p> <p>The STFT (Short-Time Fourier Transform) is effectively a computation of the FFT one 'chunk' or 'time-frame' of the signal at a time. Often these chunks are overlapped by some amount, such as 50%, meaning that if the window length is 512 samples, then halfway through the first frame (at the 256th sample), you already begin to process samples that contribute to the second time-frame.</p> <p>The purpose of using overlapping frames is to avoid artefacts caused by taking square slices of the signal. (Computing the power of one sample at a time, like you suggest, amounts to convolving your signal with a square window, which is equivalent to convolving the frequency representation of your signal with a sinc function. This causes spectral leakage, or 'ringing' artfeacts. Thus, it is common to use a sliding window with smooth edges, such as a Hamming window, to reduce these artefacts.)</p> <p>Note that the choice of window length will affect your spectro-temporal resolution. A longer window will have better frequency resolution, but worse temporal resolution, and vice-versa. This phenomenon is known as the Gabor limit, or Heisenberg-Gabor limit.</p>
https://dsp.stackexchange.com/questions/25163/eeg-power-at-specific-time-points
Question: <p>Hello friends am studying the topic of signal processing and the Fourier transform and the s-transform and in most books as for example "Time-Frequency Signal Analysis and Processing. 2nd" of Boashash in section 5.11.2.3 says that these transforms retain the absolute phase information of the signal and I do not understand that it mean with this concept about retain the absolute phase information of the signal and why this is important?.</p> Answer: <p>It simply means that for a signal: $$ x(t) = a(t) e^{j\phi(t)} $$ that the phase information $\phi(t)$ is completely preserved in the transform domain.</p> <p>Time-frequency representations that use a <a href="https://en.wikipedia.org/wiki/Time%E2%80%93frequency_representation#Quadratic_forms" rel="nofollow">quadratic form</a> do not necessarily have this property: $$ x(t+\tau)x^*(t-\tau) = a(t+\tau)a(t-\tau)e^{j(\phi(t+\tau) - \phi(t-\tau))} $$ so if $\phi$ is of the form: $$ \phi(t) = f(t) + C $$ where $C$ is a constant, then $C$ is not preserved in $x(t+\tau)x^*(t-\tau)$.</p> <p>This is important because sometimes you are interested in the absolute phase of a signal, not just its relative phase.</p>
https://dsp.stackexchange.com/questions/29819/why-fourier-transform-and-stockwell-transform-retain-the-absolute-phase-informat
Question: <p>I learned that the time constant can be computed as $\frac{1}{2 \pi f_0}$, where $f_0$ is the half-power cutoff frequency of a high-pass filter.</p> <p>However, I was wondering how the time constant and the half-power cutoff frequency can be related. For example, if the half-power cutoff frequency is 2 Hz, why must the time constant be $\frac{1}{2 \pi (2 \text{ Hz})}$ seconds? Why can't it be some arbitrary number, as long as at that time the output reaches $\frac{1}{e}$ of the starting value?</p> <p>My knowledge of signal processing is limited to a very basic understanding of Fourier analysis and filtering, so a bit more illustration would be appreciated.</p> Answer: <p>If you have a first order high-pass filter with transfer function</p> <p>$$H(s)=\frac{s}{s+\omega_0}\tag{1}$$</p> <p>then the squared magnitude of its frequency response is given by</p> <p>$$|H(j\omega)|^2=\frac{\omega^2}{\omega^2+\omega_0^2}\tag{2}$$</p> <p>Consequently, for $\omega=\omega_0$ we have</p> <p>$$|H(j\omega_0)|^2=\frac12\tag{3}$$</p> <p>and $\omega_0$ clearly is the $3$-dB (half-power) cut-off frequency.</p> <p>In the time domain, we could look at the step response of that system. The step response corresponding to the transfer function $(1)$ is</p> <p>$$s(t)=e^{-t/T}u(t),\quad T=\frac{1}{\omega_0}\tag{4}$$</p> <p>where $u(t)$ is the unit step function. So the time constant $T$ and the $3$-dB cut-off frequency are inverses of each other. This is what you get from the math (Fourier transform).</p> <p>I'll try to give you some intuition and insight into this result. In general a high-pass does not pass DC (i.e., a constant value), so after the step has been applied at the input, the output must decay to zero because the value of the step function is constant after the step has occurred. The higher the cut-off frequency $\omega_0$, the faster the output must decay to zero, because the filter suppresses low frequencies better than a filter with a lower cut-off frequency. So a high value for $\omega_0$ implies a smaller time constant $T$. You can also look at it from the other side. Assume an extremely low cut-off frequency $\omega_0\approx 0$. This means that the filter hardly suppresses anything, i.e., it leaves the input almost unchanged. So at the output you will observe almost the same as at the input, i.e., a step. Only after a very long time will the output decay to zero (because DC is suppressed, after all). So a small value for $\omega_0$ corresponds to a large value of $T$.</p>
https://dsp.stackexchange.com/questions/51042/how-to-understand-the-relationship-between-the-filter-time-constant-and-the-half
Question: <p>I am simulating a linear system described by the following equation</p> <p>$m \ddot{x} + c \dot{x} + k x = A \sin(\omega t)$</p> <pre><code>Fs = 1000; % sampling frequency tspan = 0:1/Fs:10; m = 25; c = 15; k = 330000; A = 100; % forcing amplitude omega = 114.89; % forcing frequency % State space function odefun = @(t,u)[u(2); 1/m*(-k*u(1)-c*u(2)+A*sin(omega*t))]; [time,u] = ode45(odefun,tspan,[0 0]); spost = u(:,1); % displacement vel = u(:,2); % velocity </code></pre> <p>Then I compute the FFT of the displacement:</p> <pre><code>L = length(spost); NFFT = 2^nextpow2(L); SPOST = fft(spost,NFFT)/L; f = Fs/2*linspace(0,1,NFFT/2+1); </code></pre> <p>And this is what I get:</p> <p><img src="https://i64.photobucket.com/albums/h182/Olgola/displacement2.jpg" alt=""></p> <p><img src="https://i64.photobucket.com/albums/h182/Olgola/fft_displ2.jpg" alt=""></p> <p>As you can see the maximum value of the displacement is different in the 2 cases, but this does not look right to me. In fact, if I run a structural analysis in the time or in the frequency domain I would expect to obtain the same maximum displacement (since the excitation frequency is equal to the resonance frequency).</p> <p>How can this be explained?</p> <p><strong>EDIT</strong></p> <p>I forgot to say I tried also increasing the simulation time, but still the 2 values do not match</p> Answer: <p>What you are trying to do is to compare the amplitude of your signal with an amplitude of FFT peak, expecting it is the same. The thing is that amplitude of your signal is varying and FFT is taking the "average" over whole duration.</p> <p>In such case you should use time-frequency representation of your signal, such us spectrogram. It will allow you to observe how amplitude of particular frequency is changing over time. Since you work in MATLAB you can try following code:</p> <pre><code>win = hamming(256) noverlap = 0 nfft = 512 X = abs(spectrogram(spost, win, noverlap, nfft)) % Scale by window and multiply by 2 to restore energy from negative freqs X = 2*X/sum(win) surf(X) </code></pre> <p>It will produce something like: <img src="https://i.sstatic.net/cRJF7.png" alt="enter image description here"></p> <p>The maximum value of displacement is around $0.053$. Results can be tweaked even further by tweaking even more and using other methods.</p>
https://dsp.stackexchange.com/questions/19779/system-response-time-vs-frequency-why-do-i-get-different-magnitudes
Question: <p><a href="https://i.sstatic.net/OrSV8.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/OrSV8.png" alt="Sinc(10.t) Function and Amplitude Spectrum in the Frequency Domain" /></a>First of all, hello.</p> <p>This question is about a problem that I’ve faced during an attempt to obtain both time and frequency responses of a sinc function in MATLAB. The problem is an inconsistency between my calculations that I’ve done on the paper and simulation results that I’ve observed in MATLAB.</p> <p>I’ve picked up <span class="math-container">$sinc(10 \cdot t)$</span> function and at first, I’ve taken its Fourier transform on paper. Afterwards, in order to have an experience in coding, I implemented this operation into MATLAB and plotted the functions both in the time and frequency domains.</p> <p>However, in the amplitude spectrum in the frequency domain, the amplitude of the resultant rectangular pulse didn’t match with my results on the paper. According to my analysis results, the amplitude of the rectangular pulse is <strong>0.1</strong> but in MATLAB, I’ve got <strong>10</strong> instead of it.</p> <p>My MATLAB code for simulation is given below:</p> <pre><code>t = -10: 0.01: 10; Ts = 0.01; % Sampling period in seconds fs = 100; % Sampling frequency in Hertz function_1 = sinc(10 * t); number_of_samples_1 = length(function_1); number_of_samples_2 = power(2, nextpow2(number_of_samples_1)); f = linspace(-fs / 2, fs / 2, number_of_samples_2); function_2 = fft(function_1, number_of_samples_2); function_3 = fftshift(function_2); function_4 = abs(function_3); subplot(2, 1, 1); plot(t, function_1, &quot;r&quot;); xlabel(&quot;Time (s)&quot;); ylabel(&quot;Function-1 (t)&quot;); title(&quot;Sinc(10.t) Function in the Time Domain&quot;); subplot(2, 1, 2); plot(f, function_4, &quot;r&quot;); xlabel(&quot;Frequency (Hz)&quot;); ylabel(&quot;|Function-4 (f)|&quot;); title(&quot;Amplitude Spectrum of Sinc(10.t) Function in the Frequency Domain&quot;); </code></pre> <p>My question is this: Why has this result occurred in contrast to my expectations and analysis?</p> <p>I will be happy if you give feedback to my problem and question.</p> <p>Thank you.</p> Answer: <p>I have recently answered a <a href="https://dsp.stackexchange.com/a/73640/55891">related question</a>.</p> <p>What happens is that MATLAB <code>fft</code> is calculating a sum in the sampled points, the integral would be approximated with a (Riemann) sum.</p> <p><span class="math-container">$$ \int_{0}^{T} f(x)dx \approx \sum_{k=0}^{N-1} x(k \Delta t) \Delta t$$</span></p> <p>The <span class="math-container">$\Delta t=0.01$</span> factor matches the two results.</p>
https://dsp.stackexchange.com/questions/73838/inconsistency-between-analysis-and-simulation-results-of-fourier-transform-of-a
Question: <p>I have multiple trials of physiological data. I am doing a frequency based analysis to analyze power (amplitude) in certain frequencies of interest. Is averaging multiple trials of equal length and then taking a single FFT of the averaged signal vs computing FFT for each trial and then averaging the frequency bins the same? In practice im finding this not to be the case. </p> <p>Specifically, the signal naturally has a strong 1/f component and this gets emphasized if I compute the FFT of each individual trial and then average the amplitudes (real part) of each frequency bin. Are the two equivalent? is there a right way to do things? or under what principled conditions should the choice between time domain averaging vs frequency bin averaging be made? </p> Answer: <p>Let me clarify.</p> <ul> <li>Fourier transform does <strong>not</strong> represent the histogram of the signal. Fourier transform is a linear transform that takes signal from time domain (complex function) to frequency domain (another complex function). It takes a complex function to another complex function.</li> <li>Fourier transform <strong>is</strong> linear as the poster above pointed out.</li> <li>Phase in your samples matters as pointed out above. If trial-by-trial data varies in phase, then you do not want to average before doing a Fourier transform, but you also do not want to average after Fourier transform. You want to average after Fourier transform and norm. I will elaborate below as far as exactly what needs to be done.</li> </ul> <p>The main issue here is that the question is posed wrong. It is not &quot;should I take the Fourier transform before averaging or after averaging&quot;. Because it makes no difference due to linearity of Fourier transform.</p> <p>The correct question to ask is &quot;should I take the amplitude of the Fourier transform before averaging or after averaging&quot;. For this question, the answer is before.</p> <p>Here are the details.</p> <p>Suppose your sampled data is represented by the sequences:</p> <p><span class="math-container">$d_1=d_1[n_1],d_1[n_2],...d_1[n_N]$</span></p> <p><span class="math-container">$d_2=d_2[n_1],d_2[n_2],...d_2[n_N]$</span></p> <p><span class="math-container">$d_3=d_3[n_1],d_3[n_2],...d_3[n_N]$</span></p> <p>...</p> <p><span class="math-container">$d_M=d_M[n_1],d_M[n_2],...d_M[n_N]$</span></p> <p>where <span class="math-container">$d_1,...d_M$</span> are data from M trials and <span class="math-container">$n_1,...n_N$</span> are sampled time points, then:</p> <p><span class="math-container">$F_1 = \sum_{j=1}^M{|\mathcal{F}\{d_j\}|} \neq |\mathcal{F}\{\sum_{j=1}^M{d_j}\}| = F_2$</span></p> <p>So while the transform <span class="math-container">$\mathcal{F}$</span> is linear, <span class="math-container">$|\mathcal{F}|$</span> is not.</p> <p>Furthermore, while <span class="math-container">$d_j[n_i]$</span> is real for all <span class="math-container">$i,j$</span>, <span class="math-container">$\mathcal{F}\{d_j\}$</span> is not, but <span class="math-container">$|\mathcal{F}\{d_j\}|$</span> is.</p> <p>As for what you should do, you should take the Fourier transform of individual trials (via FFT), get the amplitude of individual trials, and a average them together.</p> <p>Finally, what is <span class="math-container">$1/f$</span>. <span class="math-container">$1/f$</span> is a short term for the frequency spectrum of &quot;natural&quot; signals (usually people think of images).</p> <p>When people say there is a large <span class="math-container">$1/f$</span> component, it means that the amplitude as a function of frequency looks like <span class="math-container">$1/f$</span>. It's totally hand-wavy... probably coming from a biologist :p</p> <p>The inverse Fourier transform of <span class="math-container">$1/f$</span> is some sign function, but that is useless. It is an imaginary sign function! Real functions generate symmetric Fourier transform.</p> <p>In fact saying that the spectrum is <span class="math-container">$1/f$</span>, tells you something about the signal, but it doesn't let you recover the signal. All that you know is that <span class="math-container">$|\mathcal{F}\{x(t)\}| = |1/f|$</span>. This doesn't let you uniquely determine <span class="math-container">$x(t)$</span> because all the phase information is gone, and we know that the structure of a signal <a href="https://ieeexplore.ieee.org/document/1456290" rel="nofollow noreferrer" title="The importance of phase in signals">relies heavily on its phase</a>.</p> <p>What does <span class="math-container">$1/f$</span> tell you? Simply that it contains a lot of low frequency and a little high frequency.</p> <p>Just as important a question, what does averaging buy you? and more important is how to interpret the result? Tune in tomorrow for a more in depth discussion :p</p>
https://dsp.stackexchange.com/questions/7527/fft-time-domain-average-vs-frequency-bin-average
Question: <p>David I.Shuman in "<a href="https://arxiv.org/abs/1307.5708" rel="nofollow noreferrer">vertex-frequency analysis on graph</a>" claims that,"we generalize one of the most important signal processing tools – windowed Fourier analysis – to the graph setting and When we apply this transform to a signal with frequency components that vary along a path graph, the resulting spectrogram matches our intuition from classical discrete-time signal processing. Yet, our construction is fully generalized and can be applied to analyze signals on any undirected, connected, weighted graph."</p> <p>In this paper generalized translation operator that allows us to shift a window around the vertex domain so that it is localized around any given vertex, just as we shift a window along the real line to any center point in the classical windowed Fourier transform for signals on the real line.</p> <p><strong>generalized translation operator:</strong></p> <p>$$(T_{i}f)(n) := \sqrt{N}(f*\delta_{i})(n) = \sqrt{N}\sum_{\ell=0}^{N-1}\hat{f}(\lambda_{\ell}) \chi^{*}_{\ell}(i)\chi_{\ell}(n) .$$</p> <p><strong>See the picture</strong> <a href="https://i.sstatic.net/M7sgQ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/M7sgQ.png" alt="enter image description here"></a></p> <p><strong>Question</strong></p> <ol> <li>How do I understand translation on the graph?</li> <li>How to label irregular graphs with high dimensional data?</li> </ol> <p>Thanks.</p> Answer: <p>To understand either of these, you first have to understand the basic premise behind Graph Signal Processing (GSP) which is to map a signal to a graph and then work with it on the "Graph space". This is possible due to certain similarities of classic DSP concepts and <a href="https://en.wikipedia.org/wiki/Algebraic_graph_theory" rel="nofollow noreferrer">Algebraic Graph Theory</a>.</p> <p>So, it is easier to start from the second question because, before we start applying GSP, we first need a graph.</p> <blockquote> <p>How to label irregular graphs with high dimensional data?</p> </blockquote> <p>The short answer is that this is still an open problem and currently, there are "signals" that are naturally mapping on graphs and others where the mapping is either arbitrary or in some way constructed.</p> <p>Signals that <em>naturally map on graphs</em> are usually expressed as weights of the graph's edges through a Weight Matrix that is similar to an <a href="https://en.wikipedia.org/wiki/Adjacency_matrix" rel="nofollow noreferrer">Adjacency Matrix</a>.</p> <p>Typical examples are usually items and some form of similarity between them. For example, suppose that you have a set of $N$ time series $X$ and you evaluate their cross correlation. This will result in a Weight Matrix (let's call it $W$) whose $i^{th}, j^{th}$ element ($W_{i,j}$) is the cross correlation between time series $X_{:,i}$ and $X_{:,j}$. (So, $X$ is an $m \times n$ matrix of $n$ time series signals each being $m$ samples long.)</p> <p>What does this graph look like? It looks like a <a href="https://en.wikipedia.org/wiki/Clique_(graph_theory)" rel="nofollow noreferrer">Clique</a>. In other words, because we have examined <strong>all-to-all</strong> cross correlatons, all nodes are considered connected with each other. <strong>But</strong>, the strength of the connection is expressed by some weight. </p> <p>So, yes, they are all connected, but some are much more closer than others.</p> <p>For signals that <em>do not naturally map on graphs</em>, you first have to solve the corresponding <a href="https://en.wikipedia.org/wiki/Graph_labeling" rel="nofollow noreferrer">graph labeling</a> problem. This is generally done in two ways, either by coming up with a function that maps a signal to some graph or arbitrarily.</p> <p>In the arbitrary case, you select some graph whose <a href="https://en.wikipedia.org/wiki/Glossary_of_graph_theory_terms#O" rel="nofollow noreferrer">order</a> (the number of nodes) is equal to the number of samples in your signal. That graph's nodes can be arbitrarily connected, it could for example be an entirely random graph where there is equal chance for any two nodes to be connected.</p> <p>This is what the author of the paper that you link is actually doing. They take an arbitrary graph (a road network) and they map on to it an exponential decay signal. How? Arbitrarily. Does it make sense? No, but it illustrates the point they are trying to make about showing the effect of the operators.</p> <p>(See page 4:<em>"Note that the definitions of the graph Fourier transform and its inverse [...] depend on the choice of graph Laplacian eigenvectors, which is not necessarily unique. Throughout this paper, we do not specify how to choose these eigenvectors, but assume they are fixed. The ideal choice of the eigenvectors in order to optimize the theoretical analysis conducted here and elsewhere remains an interesting open question; however, in most applications with extremely large graphs, the explicit computation of a full eigendecomposition is not practical anyhow, and methods that only utilize the graph Laplacian through sparse matrix-vector multiplication are preferred."</em>) </p> <p>The other way that you can do the mapping is with an intuitive or model fitting (in the sense of optimisation) way.</p> <p>So, an intuitive way to map a signal to a graph is to put the samples of some $x[n]$ time series on the nodes of a graph that are simply connected as a "line" (so, something looking like $x[0] \rightarrow x[1] \rightarrow x[2] \rightarrow x[3] \ldots \rightarrow x[n]$ ).</p> <p>And a constructed way is to use optimisation in order to construct a graph whose connectivity represents SOME aspect of your original signal $x[n]$.</p> <p>Which brings us to the first question:</p> <blockquote> <p>How do I understand translation on the graph?</p> </blockquote> <p>The short answer is that translation on a graph is equivalent to a re-ordering of the edges that effects a new connectivity pattern on the nodes of the graph. In this way, the nodes appear to have "moved" or translated to a different "position".</p> <p>So now the question is how do you define "position" and to an extent this question is a bit related to the first one because "position" and how you represent the signal are related.</p> <p>But, here is a very simple example, just to demonstrate a trivial translation.</p> <p>Say we have this signal: $x = \left\{ 0,1,2,3,2,1,0,1,2,3,2,1,0 \right\}$ and we map it to the "line" graph $G(V,E)$ we saw earlier that looks like $x[0] \rightarrow x[1] \rightarrow x[2] \rightarrow x[3] \ldots $. In other words, we assign $x[0]$ to $v_0$, $x[1]$ to $v[1]$ and so on and we <strong>assume</strong> that nodes are connected "sequentially" (and cyclically).</p> <p>The adjacency matrix (or the weight matrix) of this graph is:</p> <p>$$A = \begin{vmatrix} 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\ 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\ 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\ 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\ 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\ 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\ 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\ 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\ 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 &amp; 0 \\ 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 &amp; 0 \\ 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 &amp; 0 \\ 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 1 \\ 1 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\ \end{vmatrix}$$</p> <p>Notice here that I have connected $x[|V|]$ back to $x[0]$ with that last line.</p> <p>So, how do you "move" nodes around?</p> <p>In classic DSP, if you wanted to shift things in time, you did something like: $y[n] = x[n+2], n \in \left\{0 .. |x| \right\}$ and the shift is cyclic here. After this, our shifted sequence $y$ looks like: $y = \left\{ 2,3,2,1,0,1,2,3,2,1,0,0,1 \right\}$</p> <p>Right, so how could we achieve the same, solely utilising the $A$ to effect the same shifting on our graph signal? </p> <p>Well, that's easy here because instead of having our initial time series $x$ connected as $x[n] \rightarrow x[n+1]$ it is as if we now connect $x[0] \rightarrow x[2], x[1] \rightarrow x[3], x[2] \rightarrow x[4], \ldots$. So basically, the same $A$ as above, only that now the $1$s appear two places to <strong>the right</strong> of their current position.</p> <p>Did you notice how we expressed something that happened in <strong>the time domain</strong> to something that happens in the <strong>graph</strong> domain?</p> <p>The key idea here is that <strong>we translated the signal by changing the way the nodes are connected</strong>. Translation is basically an operator on the connectivity of the graph.</p> <p><strong>BUT!</strong></p> <p>Notice here that we said earlier that we <strong>assume</strong> a "line" graph as the underlying graph for our signal. We made an arbitrary decision. We could have mapped our signal on the road network of some city (as the authors of the paper that you link have done). Then, <em>how do you define translation on that thing?!?"</em>.</p> <p>This is where the Graph Laplacian and Algebraic Graph Theory come into play.</p> <p>To cut a long story short, the <a href="https://en.wikipedia.org/wiki/Laplacian_matrix" rel="nofollow noreferrer">Graph Laplacian</a> is like the <a href="https://en.wikipedia.org/wiki/Discrete_Fourier_transform" rel="nofollow noreferrer">Discrete Fourier Transform</a> for signals in the time domain. </p> <p>It has been the topic of a lot of research in pure mathematics and its eigenvectors and eigenvalues are supposed to return a lot of information about the graph's connectivity structure (for example, whether it contains cycles or not, what sort of lengths of cycles, whether it is completely connected or not, etc).</p> <p>So, basically, what the authors are working on in the paper that you linked are a translation operator and a "DFT" equivalent operator on the graph laplacian so that you can "translate" nodes around an arbitrary connected graph (not only one looking like a line, it could have <strong>any</strong> shape) <strong>and</strong> decompose and recompose the graph connectivity matrix to elementary components <strong>no matter how complex the graph is</strong>.</p> <p>You can see now how the representation of the graph and "translation" are connected. The Laplacian of the graph depends on the values of its adjacency (or weight) matrix (i.e. its <strong>structure</strong>). You map your signal $x[n]$ on the node set of the graph $V$ and you <strong>assume</strong> (or <em>construct</em>) the edge set $E$. Therefore, any notions of "translation" or "frequency" now depend on the structure of the adjacency matrix.</p> <p>Therefore, don't try to understand why Fig.7 in the paper that you link looks the way it looks. First of all, the mapping of the signal on the road network is arbitrary and second, the "translation" depends <strong>both</strong> on the mapping <strong>and</strong> the connectivity matrix of the road network. Conceptually, this particular example does not have an immediate connection with reality. But at the same time, <strong>conceptually</strong> it shows you what <em>translation</em> means over a graph signal and a graph that can have arbitrary connectivity.</p> <p>Perhaps it is easier to think about GSP in terms of linear algebra because at the end of the day, this is what it is all based on.</p> <p>If we forget about graphs, adjacencies, nodes, edges, mappings, etc for a minute and focus on the Laplacian: The whole point of GSP is to come up with a new representation for $x[n]$ in the form of a matrix. A new "decomposition" if you like, similar to the way the DFT matrix decomposes a signal or similar to the way Wavelets decompose a signal.</p> <p>In fact, wavelets are part of the family of "constructed" graphs I am talking about earlier. They are basically a matrix. This matrix <em>could</em> also be expressed as a graph. When it <strong>is</strong> expressed as a graph, it opens the door to "new" ways of working with signals <strong>or</strong> "new" ways of working with graphs. For more information on this line of thinking please see <a href="https://doi.org/10.1016/j.acha.2010.04.005" rel="nofollow noreferrer">this paper</a> or <a href="https://papers.nips.cc/paper/5046-wavelets-on-graphs-via-deep-learning" rel="nofollow noreferrer">this paper</a> and <a href="https://arxiv.org/abs/1806.00848" rel="nofollow noreferrer">this paper</a> (for methods of discovering graph representations).</p> <p>Hope this helps.</p>
https://dsp.stackexchange.com/questions/52000/generalized-translation-on-graph
Question: <p>I wanted to do formant analysis using MATLAB and did everything according to the following tutorial:</p> <p><a href="https://de.mathworks.com/help/signal/ug/formant-estimation-with-lpc-coefficients.html" rel="nofollow noreferrer">https://de.mathworks.com/help/signal/ug/formant-estimation-with-lpc-coefficients.html</a></p> <p>I have speech signals with a sampling frequency of 44.1kHz, therefore I changed the order of the LPC estimation to 46.</p> <p>But I have the following problem: the algorithm sometimes works well, but most of the time the formants are completely off. Especially for female voice. I tried to play around with the required bandwidth and lower limit for the formant frequency, but nothing yielded sufficiently good results for various voices.</p> <p>I hope, that someone might have some tips for me to improve the code, such that it works more generally.</p> Answer: <p>According to the documentation and my past experience with the ETSI GSM 06.10 &quot;GSM Full Rate Speech Transcoding&quot; standard, you should be careful in the requirements of each block of the system and the length of the segments after the pre-emphasis or segmentation blocks.</p> <p>Probably you made it, but check the length of the signal before running the LPC function. And remember that we can obtain p/2 formants of the voice. GSM uses p=8 in the standard.</p> <p><a href="https://i.sstatic.net/7bb2e.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/7bb2e.png" alt="enter image description here" /></a></p> <p>Cheers.</p>
https://dsp.stackexchange.com/questions/71709/formant-analysis-lpc-matlab
Question: <p>I am a student learning dsp. I like the subject. I could understand the discrete time signals. When I move into z transform. I could not understand it. </p> <p>Z transform is the mapping from discrete signal to zplane to make frequency analysis easy. It would be great if users give some tips that could help me to clarify various views on z-tranform on discrete signals. </p> <p>Text is here to explain about broad answers on z-tranform. I am just looking forward in some tips that can help me understand and approach z-transform in text. Just some lines about what you think about z-tranform will surely help. Thank you mate. </p> Answer: <p>Discrete-time signals are generally written in the time domain as $x[n]$ where $n$ is an integer.</p> <p>We want to be able to see how discrete-time systems can be used to modify these signals: $$ y[n] = \sum_{m=1}^M a_k y[n-m] + \sum_{p=0}^P b_p x[n-p] $$</p> <p>The above equation is a linear, constant coefficient difference equation.</p> <p>Such equations can be hard to manipulate for a specific $x$ to figure out what $y$ is.</p> <p>The $z$ operator is used to attempt to simplify the analysis of such systems. $z$ is the forward-shift operator: it shifts a signal forward by one time instant. $z^{-1}$ is the backward-shift operator: it shifts a signal backward in time by one time instant.</p> <p>Using this operator, we can rewrite the equation as: $$ Y(z) = Y(z) \sum_{m=1}^M a_k z^{-m} + X(z) \sum_{p=0}^P b_p z^{-p} $$ which, upon rearrangement, we can get:</p> <p>$$ Y(z)/X(z) = \frac{\displaystyle\sum_{p=0}^P b_p z^{-p}}{\displaystyle1 - \sum_{m=1}^M a_k z^{-m}} $$</p> <p>which is now a <strong>discrete-time system</strong> that we can analyze in the $z$ domain, rather than the time domain.</p> <p>One thing this buys us is the ability to figure out what happens when many discrete-time systems are put together: we just multiply the discrete-time system descriptions (transfer functions). Doing the same thing in the time domain is doable, but very tedious.</p>
https://dsp.stackexchange.com/questions/26774/the-right-way-to-approach-z-transform
Question: <p>I'm trying to compute the highest frequency (as can be sampled) in some pretty manky looking discrete time-dependent signals. My current method - a discrete fourier analysis - fails for some pretty awful looking but clearly oscillating signals (with discernable highest frequencies).</p> <p>My current method is to compute the discrete fourier transform, locate the local maxima, and perform weighted averages around these peaks (to undo the 'smearing' of the dft across the discrete sample frequency bins). Here it is in MATLAB.</p> <pre><code>% compute spectrum dft = abs(fft(weight)); % real response dft = dft(1:floor(end/2) + 1); % keep only pos freqs dft = dft/sum(dft); % normalise % find present modes modes mode = zeros(0, 2); [pks, locs, widths, ~] = findpeaks(dft); for k=1:length(locs) % only consider significant peaks if pks(k) &gt; 0.1 av_width = min([floor(peak_width_factor*widths(k)), locs(k)-1, length(dft)-locs(k)]); inds = (locs(k)-av_width):(locs(k)+av_width); av_ind = (inds * dft(inds)) / sum(dft(inds)); av_freq = (av_ind - 1)/T; mode = [mode; av_freq, pks(k)]; end end </code></pre> <p>This produces a matrix of present modes (of a spectral significance above 0.1/1) where each row is the frequency and significance of the mode.</p> <p>This works great for signals like this (time signal left, dft right with the frequencies of detected modes labeled):</p> <p><a href="https://i.sstatic.net/lE0uG.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/lE0uG.png" alt="enter image description here"></a></p> <p>but fails for signals like these (where we see and expect frequencies close to 2; not an order of magnitude smaller!)</p> <p><a href="https://i.sstatic.net/jmIdD.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/jmIdD.png" alt="enter image description here"></a></p> <p>Often I expect a certain frequency (e.g f=2.6 in the above signals) and can judge myself the mode is present by the average period between the local maxima. I tried codifying this - computing the average time between local maxima - in MATLAB, but it was pretty unreliable:</p> <pre><code>[~, peak_inds] = findpeaks(weight); cycle_periods = diff(peak_inds) * dt; av_cycle_period = sum(cycle_periods)/length(cycle_periods); av_freq = 1/av_cycle_period; </code></pre> <p>My signals are well enough sampled (around 15 to 20 values per observable manky period) to resolve these manky modes visually. I've studied time series and random processes at an undergraduate level, but we never really went too deep into spectral analysis. So:</p> <ul> <li><p>How can I reliably compute these highest-frequency modes in my very 'unfourier' signals?</p></li> <li><p>Why does my current DFT analysis incorrectly deduce very low frequency modes in these manky signals?</p></li> <li><p>Why would, if multiple present modes have dissimilar frequencies, my naive distance-between-local-maxima-average method fail at extracting the highest frequency?</p></li> </ul> Answer: <p>I think most of your questions can be solved by subtracting then mean from the signal. Namely the all sinusoidal waves, with a nonzero frequency, have a mean of zero. So when the mean of a signal is not close to zero, then it will show up at 0 Hz (you can look at this as $\cos(0\,t)=1$).</p> <p>After a closer look and some testing by myself it does seem that only removing the mean would not fix your problem. Your signal seems to be contaminated by white noise, which has been integrated probably twice (so low frequencies are much more present than high frequencies). You could try to subtract a higher order polynomial fit, so linear or even quadratic. These fits can easily be obtained using some <a href="http://global.oup.com/booksites/content/0199268010/samplesec3" rel="nofollow">linear algebra</a>, for example for a quadratic fit:</p> <pre><code>X = [ones(N, 1), t', t'.^2]; b = (X' * X) \ X' * y'; z = y - (X * b)'; </code></pre> <p>Or you could also look at the biggest peaks above $f^{-2}$, with $f$ the frequency vector. However if you have a signal with normal white noise you should probably just stick with removing the mean, since my proposed methods try to make use of the fact that the present noise is white noise which has been integrated twice.</p>
https://dsp.stackexchange.com/questions/35028/find-highest-frequency-of-a-very-manky-signal
Question: <p>I've read an article about &quot;mains hum&quot; forensics in <a href="http://hummingbirdclock.info/about" rel="nofollow noreferrer">http://hummingbirdclock.info/about</a> and about <a href="https://en.wikipedia.org/wiki/Electrical_network_frequency_analysis" rel="nofollow noreferrer">Electrical network frequency analysis</a>. The idea is to be able to measure the small variations of the 50 Hz power line hum.</p> <p>Is it said that the power line frequency is changing every second.</p> <p><strong>Given a 96 kHz audio recording signal (with a mains hum) of a few seconds, how do I measure if the mains hum frequency is 49.90 or 49.95 Hz, or 50.04 Hz?</strong></p> <p>To do this with a spectrogram FFT, we would need frequency bins of width 0.01 Hz, so this means we would need at least 5 million samples, nearly <em>1 minute</em> of audio recording.</p> <p>Then the variation of the frequency second after second is lost... if it is averaged on a 1 minute interval.</p> <p><strong>How to perform such a frequency measurement on a short time frame of a few seconds?</strong></p> <p>Of course we can look at the harmonics, but I'm not sure it will be enough here.</p> Answer: <p>A few routes that come to mind:</p> <ol> <li>Use phase information to refine your frequency estimates.</li> <li>If you have good processing power, maybe a <a href="https://en.wikipedia.org/wiki/Constant-Q_transform" rel="nofollow noreferrer">constant Q transform</a> can help.</li> <li>Track the hum frequency using an adaptive algorithm such as an <a href="https://hal-amu.archives-ouvertes.fr/hal-01956284/document" rel="nofollow noreferrer">adaptive notch filter</a> (the stronger the hum, the better it will perform of course, a pre-filter could help).</li> </ol>
https://dsp.stackexchange.com/questions/84852/how-do-i-distinguish-a-49-90-hz-sine-wave-from-a-49-95-hz-one-in-a-short-audio-r
Question: <p>I have two questions regarding signal processing:</p> <p>1) In my analysis I generate a signal in the time domain with a frequency of 0.1 Hz. I apply the FFT and then determine the peak frequency of the signal, which should be 0.1 Hz. But I notice that when I simulate my signal for 200s, the peak frequency is always close to the 0.1Hz, but when I simulate my signal for 20s, then the peak frequency is not always 0.1Hz. Is there a certain rule of thumb for the duration of the signal to have the peak frequency occur in the frequency domain?</p> <p>2) Currently I am just determining the peak frequency of my signal, as the highest peak in the frequency domain. But sometimes I have a lot of peaks near each other and at times they might overlap. What are some other recommended techniques to determine the peak frequency? I am using Matlab</p> <p>Thanks!</p> Answer: <p>What window function are you using when you apply your FFT?</p> <p>If the signal being analyzed is simply truncated on both ends, the window is rectangular. </p> <p>Lets call the length of time that you generate your signal the analysis window and call the signal you create the "windowed signal". In this case I'm assuming the window to be rectangular.</p> <p>One interpretation of the math behind the FFT is that the signal being analyzed is periodic and the complete version of the signal is formed by taking the unaltered input from the analysis window and placing it end to end so it repeats indefinitely as illustrated below</p> <p>....| Windowed Signal (-1) | Windowed Signal (0) | Windowed Signal (+1) |...</p> <p>Depending on where you stop your signal generation, you may introduce discontinuities in the periodic signal that the FFT assumes when you do your analysis. For example if your signal generation stops at the peak of a sine wave but starts at a 0 crossing, the signal at the point where one windowed signal segment meets the nest will abruptly go from Vpeak to 0. This discontinuity introduces spurious frequency content in the FFT. Also if you don't make your analysis window an integer multiple of the period of signal being analyzed, the FFT will assume the signal is periodic in a different period than the signal being analyzed (actually the period assumed by the FFT is always the window length). this will create frequency lobes that are not harmonically related to the signal you are testing.</p> <p>As you increase the length of your window, the contribution of the discontinuity and window period diminish, so the longer duration signal will give more accurate results.</p> <p>The way to improve accuracy of the FFT frequency and/or amplitude resolution is with the use of non-rectangular window functions. There are a bunch of window functions that are designed for this purpose. The window function is multiplied by your time domain data (signal). The effect of the window function is to taper off the amplitude of at the ends of your analysis window (the start and end of the signal you generate) so the edge effects are reduced in the FFT computations. Different windows have different advantages in frequency or amplitude resolution, so there are trade offs in choosing a window function.</p> <p>In general, if you want decent resolution in your FFT, you should provide a data length that is least 2x the period of the lowest frequency to be represented and apply a window function to soften the effects of signal truncation. Note that the longer you make your time window, the greater the frequency resolution of your FFT. The bins are spaced at 1/T and its multiples where T is the duration of your signal.</p> <p>There is plenty of information on the internet that discusses the different window functions used in FFT analysis. Just Google "FFT window functions".</p>
https://dsp.stackexchange.com/questions/15474/time-duration-of-a-signal-to-determine-the-peak-frequency
Question: <h2>Background</h2> <p>Here's the thing: using software for Finite Element Acoustic Simulation I got the dataset of frequency response from a room; software works by solving the wave equation in the interval $`[f_i,f_f]`$ so results come directly in the frequency domain and we save them into a .csv file: <a href="https://i.sstatic.net/WmdX4.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/WmdX4.jpg" alt="enter image description here"></a></p> <p>For decay time analysis, we're on the way to transform the data to time domain (using IFFT) and it has some tricks that you may know but I'll mention briefly:</p> <p>(From Matlab's FFT documentation)</p> <ol> <li><p>Space between 0 [Hz] and f_i [Hz] must be filled in (keeping the distance between points as in the results) and assigned zero amplitude, to let IFFT algorith work correctly</p></li> <li><p>Do an amplitude "de-normalization"</p></li> <li><p>"Reflect" the frequency spectra using the last frequency element as pivot, omitting the first one and conjugating this copied values</p></li> <li><p>Apply IFFT, and done.</p></li> </ol> <p>So far, we've made and proved a code that does this steps using the .csv file as entry. The test was realized with a .csv created from a .wav file and it resulted ok:</p> <p>(Subplot 1: original. Subplot 2: after process)</p> <p><a href="https://i.sstatic.net/U2dv3.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/U2dv3.png" alt="enter image description here"></a></p> <h2>The problem</h2> <p>Our analysis was made from 0.1 to 200 Hz with steps of 0.1 Hz. When we transformed the results to time domain, the signal was 10 secs long but we expected it to be at least 30 secs (since was a model similar to last's plot one). We tried to reduce the distance between points by interpolating it, as $`\Delta f = 1/T`$ say (with $`T`$ as signal duration). However, when applying again IFFT the plot was exactly the same!</p> <p><a href="https://i.sstatic.net/aWwCV.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/aWwCV.png" alt="enter image description here"></a></p> <p>So, how can I process my data to get a longer signal in the time domain? </p> <p>Hope I have been clear enough. Thanks in advance.</p> <p>EDIT: showing correctly the list before first image</p> Answer:
https://dsp.stackexchange.com/questions/50075/making-longer-a-time-domain-signal-by-adding-values-on-its-frequency-domain-wha
Question: <p>How can I analyze a basic sine wave for its frequency phase and amplitude at a particular point in time in MATLAB? Are there any tools to do that? I am trying to do additive synthesis of inharmonic sounds in MATLAB, but having a great difficulty to extract the needed phase amplitude and frequency data of the partials I am trying to generate. Can someone shed some light regarding signal analysis in MATLAB? </p> Answer: <p>If your the unknown signal $x(n)$ is modeled as: $$x(n)=A \sin(2 \pi f n+ \phi)+w(n)$$ and you want to estimate $A$,$f$,and $\phi$ accurately, you can use least square estimation. Unfortunately the cost function is nonlinear. You can use nonlinear least square in MATLAB to find the parameters as follows:</p> <p>Make a cost function: </p> <pre><code>f=@(A,f,phi) x[n]-A sin(2*pi* f *n+ phi) </code></pre> <p>and use </p> <pre><code>p0=[A0,f0,phi0]; p = lsqnonlin(f,p0); </code></pre> <p>to find the unknown parameters. Note that the optimizer will have a hard time finding $f$ as the problem is not convex. So it is best if you can give an initial estimate of frequency by using a method like fft.</p> <p>If the frequency is known then the problem can be converted to a linear estimation as: $$x(n)=A \sin(2 \pi f n+ \phi)+w(n)$$ $$=A \sin(2 \pi f n) \cos (\phi) +A \cos(2 \pi f n) \sin (\phi)+w(n)$$ $$=p_1 S[n] +p_2 C[n]+w(n),$$ where $p_1=A \cos(\phi)$ and $p_2=A \sin(\phi)$ are unknown parameters, and $S[n]$ and $C[n]$ are known.</p>
https://dsp.stackexchange.com/questions/17142/how-can-i-analyze-a-basic-sine-wave-for-its-frequency-phase-and-amplitude-at-a-p
Question: <p>I have an FRA (frequency response analysis) of a device that have magnitude and phase as shown in the following figure. Since the response is look different at different frequencies based on the operating point of the device under test, I want to extract the features from this response to further use for machine learning to classify different operation conditions. So far, I have been working on statistical approaches like mean, variance, skewness etc, but they prove to be ineffective, as they generalize peak behavior that can be noticed in the response plots.</p> <p>I want to reach out to the experts in this community to guide me on more effective features extraction that could help me to quantify the response data in more flatten (1D) way. Any comment or suggestions are really appreciated.</p> <p>Thank you for your time in advance.</p> <p><a href="https://i.sstatic.net/fzErGf46.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/fzErGf46.png" alt="Frequency response analysis results(mag &amp; phase)" /></a></p> Answer:
https://dsp.stackexchange.com/questions/96473/feature-extraction-of-the-magnitude-and-phase-data-from-fra-frequency-response
Question: <p><strong>Experiment:</strong> Vibration analysis (i.e.: major concern is on transfer function or frequency response).</p> <p>The input is an impulse (imagine as a knocking effect or knocking force), defined as a half sine curve. The output is the vibration speed of the specimen (measured by laser vibrometer). The vibration is naturally damped, so within <span class="math-container">$0.6\ \rm s$</span>, the vibration speed has greatly decreased - but it is most certainly removed after <span class="math-container">$1.2~1.3\ \rm $</span>s. The results are then computed with FFT to convert into frequency domain (automatic process done by the computer) and then the transfer function would be investigated.</p> <p>My questions are as followed:</p> <ol> <li><strong>Would having long measurement period (i.e.: one sample period) have any effect on the frequency spectrum?</strong> This is assuming the number of sampling points (in time domain) or the number of spectral/FFT lines is kept the same. The measurement time can be changed via the selected bandwidth (and thus, the sampling frequency)</li> <li>Is there any proven work or mathematic, saying that for the same bandwidth and same sampling frequency, increasing the frequency resolution (i.e.: make the spectrum coarser) would decrease the height of the peak?</li> <li>Would changing the time increment (time between 2 consecutive sampling points in time domain) change the frequency spectrum?</li> </ol> <p>Though I think that these 3 questions are somewhat the same as each other, it is worth writing all of them down.</p> <p>Reference graph: different bandwidths (and thus, different frequency resolutions, different measurement time, and different time increment) lead to different frequency response (or transfer function). The most &quot;problematic&quot; are the 2 peaks at 300 and 330 Hz. Normally, by increasing the frequency resolution, the common belief is that the amplitude would be lower.</p> <p><a href="https://i.sstatic.net/uf42f.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/uf42f.png" alt="enter image description here" /></a></p> <p>And then, question 4:</p> <ol start="4"> <li>Would the Gibbs phenomenon have any (visible) effect on the frequency spectrum?</li> </ol> <p>Thanks for your help.</p> Answer:
https://dsp.stackexchange.com/questions/72554/the-effect-of-time-increment-delta-t-frequency-resolution-delta-f-and-gib
Question: <p>Let's say I have an audio sample, whose pitch is known to be C4 (don't wanna go in detail here, let's say I just sampled a tuned piano playing the C4 key).</p> <p>The rules of the game are: I can only change the sample playback rate by any ratio. No pitchshifter module, no frequency analysis. If I set the playbackrate to 2.0, for example, the sample is played back at twice its speed. If I set it to 0.5, the sample is played back at half its speed, and so on. This changes the playback time as well as the sample pitch.</p> <p>If I wanted to generate any arbitrary "note" from this sample, what is the relation between the playback rate and the sample pitch? For example, I know that C4 fundamental frequency is 261.63 Hz. What playback rate should I set to make the sample "sound like" a C#4/Db4 (277.18 Hz) or a D4 (293.66 Hz)? What is the general, formulaic, relationship?</p> Answer: <p>The ratio of sample playback rates should be equal to the ratio of pitches you want to obtain.</p> <p>For example, if your C4 note was sampled at 48kHz, you'll need to play it back at $48000 \times \frac{277.18}{261.63} = 50.85kHz$ to make it sound like a C#4.</p>
https://dsp.stackexchange.com/questions/7721/pitch-vs-playback-rate
Question: <p>This is a cross posting from the crossvalidated stack exchange as I thought this may be a better forum to ask.</p> <p>I have a dataset consisting of respiratory time series signals of different lengths obtained from different groups of patients. I want to either classify or cluster the patients using these timeseries by using the commonalities of the time series of each group. However, I have no experience in dsp.</p> <ol> <li><p>Firstly, I am confused if I am supposed to filter my signals to get rid of any frequencies above the Nyquist frequency. My sampling frequency is 32Hz and my time series is somewhat noisy and has some artifacts. I am also unsure of which filter to select for this.</p> </li> <li><p>Secondly, I wanted to look at the periodogram and the average power spectral density at each frequency within a group - but I am not sure if I understand the periodogram very well - if I have different time series lengths then my periodogram length will vary too, so I am not sure how this comparison can be made.</p> </li> </ol> <p>Being from Pure Math, I know Fourier analysis purely from the perspective of functions and using Fourier transforms to obtain the coefficients that describe the projection of these functions onto an orthonormal system. With periodograms however, I noticed that the x-axis represents sample frequencies. I am confused with the distinction between sampling frequencies vs. underlying frequencies of the generating function (say I have <span class="math-container">$\sin(2\pi x)$</span> sampled at 10Hz, does the periodogram characterize the 1Hz underlying frequency of the function?)</p> <p>Any resources on understanding how to analyze and remove noisy components of time signals from a machine learning perspective would be much appreciated! Due to time constraints, I have shied away from long textbooks on digital signal processing. Thanks a lot.</p> Answer: <blockquote> <p>Firstly, I am confused if I am supposed to filter my signals to get rid of any frequencies above the Nyquist frequency. My sampling frequency is 32Hz and my time series is somewhat noisy and has some artifacts. I am also unsure of which filter to select for this.</p> </blockquote> <p>That ship has sailed.</p> <p>Let <span class="math-container">$S=\left\{\left.\alpha e ^{i(\omega t+\varphi)}\right|\alpha &gt; 0, 0\le \varphi &lt;2\pi, \omega \in \mathbb R\right\}$</span>, i.e. the set of all distinct complex sinusoid with an amplitude, frequency and phase.</p> <p>Then <span class="math-container">$(S,\cdot)$</span> is a commutative semigroup (proof trivial).</p> <p>Introducing the equivalence relation <span class="math-container">$\sim: a\sim b \iff a\left(\frac{n}{r}\right)= b\left(\frac{n}{r}\right) \forall n\in\mathbb Z$</span> (&quot;two signals are identical after sampling with rate <span class="math-container">$r$</span>&quot;), we see that signals <span class="math-container">$s_l=\alpha e^{i(\omega_l t + \varphi)}, l=1,2,\ldots$</span> are <span class="math-container">$s_1\sim s_2$</span> if <span class="math-container">$\frac{\omega_1-\omega_2}{2\pi}=nr, n\in\mathbb Z$</span>, i.e. we can't tell signals apart after sampling if their frequency differed by a multiple of the sampling rate.</p> <p>Let's formalize this: <span class="math-container">$T=\left\{\alpha e^{i([ft+\phi]\mod 2\pi)}\right\}$</span> is a quotient semigroup of <span class="math-container">$S$</span>, i.e. <span class="math-container">$T\preceq S$</span>, and each of the elements is a leader of a <span class="math-container">$\sim$</span>-equivalence class – and this homomorpism <span class="math-container">$S\mapsto T$</span> is in fact sampling, which, as we can see above, is not bijective.</p> <p>Hence, all the original frequency components from <span class="math-container">$S$</span> got mapped to some component from <span class="math-container">$T$</span> with frequency normalized to the sampling frequency. That mapping is called <em>aliasing</em>.</p> <p>What an anti-alias filter <span class="math-container">$h$</span> does is</p> <p><span class="math-container">$$h(s): S\mapsto S, h=\begin{cases} s, &amp; f&lt; f_\text{nyquist}\\ 0 &amp; \text{else,} \end{cases} $$</span></p> <p>and as you'll figure out when inserting <span class="math-container">$h(s)$</span> above is that this yields only the elements that are not aliased to a different frequency.</p> <p>Thus, everything that &quot;survives&quot; <span class="math-container">$h$</span> will also &quot;survive&quot; aliasing without undergoing a change in frequency.</p> <p>So, if you needed an anti-aliasing filter, it's now too late. Go and do your recording again.</p> <blockquote> <p>Secondly, I wanted to look at the periodogram and the average power spectral density at each frequency within a group - but I am not sure if I understand the periodogram very well - if I have different time series lengths then my periodogram length will vary too, so I am not sure how this comparison can be made.</p> </blockquote> <p>In that case, the periodogramm is not a useful mapping on its own – you'll need to add something like a truncation / padding operation to bring all signals to the same duration, for example. At which point the periodogram doesn't seem to be a sensible approach anymore.</p>
https://dsp.stackexchange.com/questions/71917/help-with-denoising-signal-and-periodogram-analysis-resources
Question: <p>I have two time-domain signals sampled at 100 Hz that were measured using two different oscillators and therefore have a time drift between them. I have two synchronization points, one at the start and one at the end of the measurement (usually about 24h long).</p> <p>The drift is very small, about 1 second for a 24h measurement, i.e. about 0.001% or 1/86400. I assume a linear model for the drift. </p> <p>The length of the measurement and the relative scale of the drift prohibit usual resampling techniques: I'd have to up- and down-sample the longer signal by large factors.</p> <p>My approach would be to drop every 86400th sample of the longer measurement, the questions I have are:</p> <ul> <li>Is there a better approach?</li> <li>What's the frequency-domain equivalent of dropping a sample? I imagine it would shift the spectrum by a tiny amount and introduce some high-frequency noise. </li> </ul> <p>To be honest, the second question is more academic than practically relevant; most of the analysis is done in small chunks and I can just exclude the chunks with the dropped samples from the analysis.</p> Answer:
https://dsp.stackexchange.com/questions/53246/matching-two-signals-with-small-time-drift
Question: <p>I'm trying to get an intuitive understanding of the different coefficients in detrended fluctuation analysis (DFA).</p> <p>It is used to detect fractal patterns in time series and it yields a coefficient, Alpha, which, as I understand is a Hurst coefficient mapped for different scales — the slope of which is the alpha.</p> <p><a href="https://i.sstatic.net/3TWTO.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/3TWTO.png" alt="enter image description here" /></a></p> <p>What I don't understand is if alpha shows a correlation between the frequency fluctuation and the scale (i.e. the bigger is the scale, the higher are the frequency fluctuations at that scale) — why is it that a time series is scale-free when alpha is around 1 or random when alpha is around 0.5?</p> <p>We have a correlation in both cases, so where do these precise values come from? Why 0.5 and not 0.3? Why 1 and not 0.9?</p> <p>Maybe somebody has an explanation for this as I haven't found anything precise in scientific literature.</p> Answer: <p>The application of the DFA method starts with a conversion of a bounded time series under test into an unbounded process, the elements of the unbounded process being partial sums of the bounded time series sequence.</p> <p>Let we have a (discrete-time) realization of WGN of length N. It is a bounded time series. The starting conversion procedure of the DFA method transforms this WGN time series sequence into a realization of the random-walk process by the definition of the random walk process. For the RMS deviation's log-log plot of this random-walk process realization (this RMS deviation named the <strong>fluctuation</strong> in the DFA parlance), we draw a straight trend line using the least squares method. The slope of this trend line <a href="https://en.wikipedia.org/wiki/Random_walk#Gaussian_random_walk" rel="nofollow noreferrer">approaches 1/2 when N tends to infinity.</a></p> <p>Hence the exact equality of DFA's alpha to 1/2 for the random process. You may have failed to find an explanation in scientific literature, because it should be read from textbooks, for example, read <a href="https://en.wikipedia.org/wiki/Detrended_fluctuation_analysis" rel="nofollow noreferrer">the Wikipedia article on DFA</a>.</p> <p>UPDATE</p> <p>For an uncorrelated random walk of length N, fluctuation <em>F(N)</em>, introduced in the DFA Wiki article, grows like a square root of <em>N</em>, i.e., its Hurst exponent is 1/2. Recall that the &quot;fluctuation&quot; of the uncorrelated time sequence such as a white noise realization does not depend on the sequence length by definition, its Hurst exponent is 0, and a white noise realization has its self-affinity at negative maximum -- the stretches of steady increase/decrease must be compensated by the stretches of the opposite direction, because the mean is zero. The alphas between zero and 1/2 correspond to an &quot;anti-correlated&quot; behavior from the POV of self-similarity. Likewise, the alphas between 1/2 and 1 correspond to correlation, and the alphas greater than one bear witness of the presence of non-stationary, unbounded process. The alpha=1 process is the stationary process, correlated at the maximum amount of self-affinity, it is the &quot;<em>1/f</em> noise&quot;, because its PSD(f) is proportional to the inverse of frequency. The variance of an uncorrelated random walk is proportional to the square root of the series length; for the time series characterized by the Hurst exponent H, the variance and higher order moments are proportional to the series length raised to power <em>H</em>. This statistics results in the scaling behavior <span class="math-container">$$ x(at) \sim a^Hx(t) $$</span> where <em>x</em> is a random variable of the time series generating distribution, <em>a</em> is the scaling coefficient, <em>H</em> is the Hurst coefficient.</p> <p>With <em>H=1</em>, the scaling behavior is closest to the concept of pure self-similarity, <em>x(at) ~ ax(t)</em>, reproducing the system behavior at every time range.</p> <p>These explanations do not prove the self-similarity claims, as mathematics requires it. But it would greatly help you learn the signal processing theory and master developer skills, if you compute and simulate the problems and processes. You can create an array of data and initialize it with a WGN samples in Matlab or Python; transform this array into a random walk process realization; compute trend lines with least squares and plot log-log graphs. Then, you can generate 1/f noise samples (or whatever noise spectrum you want) and plot trend lines for these distributions. Changing time scales, you will see for youself the claimed self-similarity properties. And in the process, you will master the necessary math.</p>
https://dsp.stackexchange.com/questions/72512/why-does-alpha-of-0-5-in-detrended-fluctuation-analysis-indicate-randomness
Question: <p>I'm attempting to perform multi-resolution analysis via Continuous-Wavelet Transform (CWT) using Pywavelets. I've heard that CWT is supposed to be superior to STFT due to varying frequency content as a function of the time-window.</p> <p>My test signal is two sinusoids of 1Hz and 5Hz, each lasting 10 seconds (see picture): <code>f=np.sin(2.*np.pi*t)*((t&gt;=10)&amp;(t&lt;=20))+np.sin(2*np.pi*5*t)*((t&gt;=30)&amp;(t&lt;=40))</code>. The sampling period is 20Hz.</p> <p><a href="https://i.sstatic.net/Uz5gO.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Uz5gO.png" alt="Time Domain" /></a></p> <p>Using Pywavelets, I perform the CWT as follows with the resulting spectrogram:</p> <pre><code>scales = np.arange(0.6,65,step=0.2) coef, freqs=pywt.cwt(f,scales,'cgau1', sampling_period=dT) </code></pre> <p><a href="https://i.sstatic.net/3IL9Q.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/3IL9Q.png" alt="CWT" /></a></p> <p>As you can see the frequency resolution is quite lousy, and the peak (complex magnitude) doesn't even seem to line up at 5Hz for the second segment.</p> <p>In contrast, a STFT using the Gaussian window with a standard deviation of 5 results in much sharper frequency resolution (at the expense of time sharpness):</p> <p><a href="https://i.sstatic.net/PYO7x.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/PYO7x.png" alt="STFT" /></a></p> <p>Am I doing something here? I'm willing to sacrifice time resolution but I do need to sharpen up the frequency.</p> Answer: <p>The family of continuous wavelet transforms (CWT) is not, <em>per se</em>, superior to STFT. Due to its variations in scale, the CWT can be better, for instance, when:</p> <ul> <li>you address natural signals where transients are shorter than more stationary parts,</li> <li>you do not know the appropriate scale of observation,</li> <li>deterministic or random processes follow scaling laws (like the Brownian motions).</li> </ul> <p>which is not the case from your signal: precise frequency on the same support.</p> <p>On the one hand, you can work with a continuous wavelet with more oscillations, and better refine the scales and voices.</p> <p>On the other hand, there are so-called STFT with windows whose width vary with frequency.</p> <p>Add-ons like hybrid time-scale/time-frequency transformations, reassignement, etc. may be used, but choosing the appropriate tool requires to refine your goal.</p>
https://dsp.stackexchange.com/questions/58939/cwt-disapointing-frequency-separation
Question: <p>Since a couple of months I started working on the extraction (estimation) of signal frequency and amplitude components by means of two different time-frequency approaches, namely the Hilbert transform and the Teager-Kaiser energy operator.</p> <p>I tested both methods on standard signals, such as chirps, sine, cosine, etc. This preliminary analysis seemed to highlight Teager-Kaiser has better resolution in both frequency and amplitude estimation.</p> <p>Afterwards I applied the two methods on some acceleration signal derived from a tool simulating the dynamic behavior of a given system. Surprisingly enough, Hilbert transform provided more reliable results in terms of frequency estimation. Teager-Kaiser operator shows some high-frequency content estimation, which is hardly expectable.</p> <p>I developed the two techniques in Simulink, as visible here: <img src="https://i.sstatic.net/2x60A.png" alt="enter image description here"></p> <p>The results on a synthetic acceleration signal are here: <img src="https://i.sstatic.net/qULgn.jpg" alt="enter image description here"></p> <p>What did I miss in the design of the Teager-Kaiser operator? Is it any possible to avoid those "false" frequency estimates (those with the arrows)?</p> Answer: <p>This paper may be of interest:</p> <p>David Vakman, "On the Analytic Signal, the Teager-Kaiser Energy Algorithm, and Other Methods for Defining Amplitude and Frequency." IEEE Trans. Signal Processing. (1996)</p> <p>Summarising from the paper:</p> <p>$$\Psi(u) = a^2w^2 = [u'(t)]^2 - u(t)u''(t)$$ $$\Psi'(u') = a^2w^4 = [u''(t)]^2 - u'(t)u'''(t)$$</p> <p>where $u(t)$ is the signal, and $a$ and $w$ iare the amplitude and frequency estimates to solve for.</p> <p>$$a(t) = \frac{\Psi(u)}{\sqrt{\Psi(u')}}$$ $$w(t) = \sqrt{\frac{\Psi(u')}{\Psi(u)}}$$</p> <p>But this means if at some point in the signal $u'(t)=1$ and $u''(t)=u''''(t)=0$, for example, then $\Psi(u) = 1$ and $\Psi'(u) = 0$ and thus $a(t) = \infty$ and $w(t) = 0$.</p> <p>The paper thus explains this causes spikes in amplitude and zero frequencies with the Teager-Kaiser algorithm.</p> <p>For your signal, the reverse must be true. If $\Psi(u) = 0$ and $\Psi'(u) = 1$ then you would get spikes in frequency when amplitude is zero. This would occur when $[u'(t)]^2 = u(t)u''(t)$</p> <p>The Hilbert transform uses the entire signal to compute. It is implemented by doubling the positive frequencies and setting the negative frequencies to zero. Therefore the <em>energy of the signal</em> does not change (Parseval's theorem). Thus, intuitively, there can be no infinite spikes, as this would require infinite energy.</p>
https://dsp.stackexchange.com/questions/21662/teager-kaiser-operator-vs-hilbert-transform
Question: <p>I am not sure if I am missing something, but from what I read I understand that modern control systems work in the time domain rather than the frequency frequency or S-domain.</p> <p>Wikipedia article snapshot below:</p> <p><a href="https://i.sstatic.net/mXuF3.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/mXuF3.png" alt="enter image description here" /></a></p> <p>Why is the time domain preferred in modern systems?</p> <p>I thought the entire point of going to S domain is because it simplifies the equations and associated maths with the Laplace or Fourier transforms.</p> <p>Is state space representation an alternative to the Laplace transform and is it better/faster than analysis in the S-domain?</p> Answer: <p>I would say that the difference is not about time domain or frequency domain, is more about using transfer function or state space equations.</p> <p>The state equation for a system with a single input and a single output is</p> <p><span class="math-container">$$\sum_{n=0}^{N} a_n \left(\frac{d}{d t}\right)^n y(t) = \sum_{n=0}^{N} b_n \left(\frac{d}{d t}\right)^n u(t)$$</span></p> <p>The state space representation for a system</p> <p><span class="math-container">$$\dot{x}(t) = A \, x(t) + B \, u(t), \\ y(t) = C \, x(t) + D \, u(t)$$</span></p> <p>where <span class="math-container">$y(t)$</span>, <span class="math-container">$x(t)$</span> and <span class="math-container">$u(t)$</span> all can be vectors, extending this easily to multiple inputs and multiple outputs. For a high order system the number of parameters in state space representation is much larger, and there are multiple possible representations, however there are some canonical representations that are unique to a given system, and may have as few parameters as the transfer function.</p> <h2>Linking the two representations</h2> <p>This can be represented in the Laplace domain as</p> <p><span class="math-container">$$s \cdot X(s) = A \, X(s) + B \, U(s), \\ Y(s) = C \, X(t) + D \, U(s)$$</span></p> <p>If you want to understand the dynamic of the system you can manipulate the state update equation as follows</p> <p><span class="math-container">$$s X(s) - A\, X(s) = B \, U(s) \\ (s \mathbb{I} - A) X(s) = B \, U(s)$$</span></p> <p>From the above equation you start to notice that when <span class="math-container">$X(s)$</span> is an eigenvector of You have <span class="math-container">$(s \mathbb{I} - A) v = s v - \lambda v$</span>, and this will define one mode of the system <span class="math-container">$x(t) = x(0) e^{\lambda t}$</span>, this is why you can study the dynamic of the system in terms of the eigenvalues of <span class="math-container">$A$</span>.</p> <p>Proceeding to the transfer function we can solve the above equation for <span class="math-container">$X(s)$</span></p> <p><span class="math-container">$X(s) = (s \mathbb{I} - A)^{-1} B \, U(s)$</span></p> <p>and replace in the outptut equation</p> <p><span class="math-container">$$Y(s) = C \, X(s) + D \, U(s) \\ C \, (s \mathbb{I} - A)^{-1} B \, U(s) + D \, U(s) \\ (C \, (s \mathbb{I} - A)^{-1} B + D) U(s) $$</span></p> <p>And finally the transfer function is</p> <p><span class="math-container">$$H(s) = \frac{Y(s)}{U(s)} = (C \, (s \mathbb{I} - A)^{-1} B + D) U(s)$$</span></p> <p>The result is so difficult to write that I will skip (and that is what is called classical control).</p> <p>This equation will have rational functions (ratio of polynomials) in <span class="math-container">$s$</span>, If a system has multiple inputs and multiple outputs it will be a matrix of scalar transfer functions mapping the effect of each input to each output.</p> <p>Apart from notation compactness, linear algebra methods scale well to higher dimensions. One example of other advantage that I can cite is related to my master's degree. You can study system stability using Lyapunov stability condition, and this leads to linear matrix inequalities that can be applied to uncertain systems (with uncertainty in the model matrices).</p>
https://dsp.stackexchange.com/questions/75281/why-is-modern-control-theory-in-the-time-domain-instead-of-the-s-domain
Question: <p>I have just started taking signal &amp; systems lessons and here is my question:</p> <p>If we say that <code>x0(t) = A.cos(w0t)</code>. (<em>a cosine signal with zero phase shift, w0 radian frequency)</em> And if we would like to time-shift this signal by for example <code>t1</code>.</p> <p>The resulting phase shift should be found by <code>-w0*t1 = phi</code>. (phi denoting phase shift).</p> <p>By this logic, if I wanted to find the phase-shift for this signal: <code>x(t) = sin(pi/4*t-pi/4)</code></p> <p>What would the result be? Can I apply the first formula for phase for already phase shifted signals? Or am I missing something very big here? :)</p> <p>Thank you very much for any kind of help.</p> Answer: <p>Indeed, you can apply the same technique:</p> <p>As you said, given a sine signal with time shift $t_1$, which is $x(t)=\sin(w(t-t_1))$, this becomes $x(t)=\sin(w t - wt_1)=\sin(wt+\phi)$ and $\phi=-wt_1$.</p> <p>Now, if you encounter a signal $x(t)=\sin(\frac{\pi}{4} t - \frac{\pi}{4})$ you identify $w=\frac{\pi}{4}$ and $\phi=-\frac{\pi}{4}$. What remains is to solve $\phi=-w t_1$ for $t_1$ and you have it.</p>
https://dsp.stackexchange.com/questions/50461/converting-time-shift-to-phase-shift
Question: <p>I'm reading about when a <span class="math-container">$H(z)$</span> system is min phase or max phase, and I get when a system is a min phase or max phase depending on the location of the zeroes. But I don't get at all the phase shift part. on one point wikipedia says that these two transfer functions:</p> <p><span class="math-container">$\frac{s+10}{s+5} \; and \;\; \frac{s-10}{s+5} $</span> <span class="math-container">$\\\\$</span></p> <p>&quot;have equivalent magnitude responses but however the second system has a much larger contribution to the phase shift.&quot; So what is phase shift?</p> Answer: <p>Let the complex frequency response of a (real-valued) LTI system be</p> <p><span class="math-container">$$H(\omega)=M(\omega)e^{j\phi(\omega)}\tag{1}$$</span></p> <p>with magnitude <span class="math-container">$M(\omega)$</span> and phase <span class="math-container">$\phi(\omega)$</span>. If the input to such a system is <span class="math-container">$x(t)=A\sin(\omega_0t+\theta)$</span>, then its output is given by</p> <p><span class="math-container">$$y(t)=AM(\omega_0)\sin\big(\omega_0t+\theta+\phi(\omega_0)\big)$$</span></p> <p>The quantity <span class="math-container">$\phi(\omega_0)$</span> is called the phase shift at frequency <span class="math-container">$\omega_0$</span>. The negative of the phase shift is usually called <em>phase lag</em>.</p> <p>The minimum-phase system has the smallest phase lag of all systems with the same magnitude response <span class="math-container">$M(\omega)$</span>.</p> <p>Another property of minimum-phase systems is that they have the smallest group delay of all systems with the same magnitude response <span class="math-container">$M(\omega)$</span>. Group delay is defined as the negative derivative of the phase with respect to frequency.</p> <p>For a first-order system with transfer function</p> <p><span class="math-container">$$H(s)=\frac{s+a}{s+b}\tag{2}$$</span></p> <p>the phase is given by</p> <p><span class="math-container">$$\phi(\omega)=\arctan\left(\frac{\omega}{a}\right)-\arctan\left(\frac{\omega}{b}\right)\quad(\pm\pi)\tag{3}$$</span></p> <p>The presence of the additive term <span class="math-container">$\pm\pi$</span> depends on the signs of <span class="math-container">$a$</span> and <span class="math-container">$b$</span>, but since we're interested in the derivative of <span class="math-container">$(3)$</span>, this term is irrelevant. Taking the negative derivative of <span class="math-container">$(3)$</span> gives</p> <p><span class="math-container">$$\tau_g(\omega)=\frac{b}{\omega^2+b^2}-\frac{a}{\omega^2+a^2}\tag{4}$$</span></p> <p>Since <span class="math-container">$H(s)$</span> must be stable, we require <span class="math-container">$b&gt;0$</span>, which results in a positive contribution to the group delay. A positive value of <span class="math-container">$a$</span>, corresponding to a minimum-phase system, results in a negative contribution due to the right-most term in <span class="math-container">$(4)$</span>, hence reducing the group delay. For <span class="math-container">$a&lt;0$</span> (maximum-phase), the contribution of the second term on the right-hand side of <span class="math-container">$(4)$</span> is positive, hence maximizing the group delay.</p>
https://dsp.stackexchange.com/questions/75064/what-is-phase-shift
Question: <p>I heard that an IIR filter has delay and phase shift effect, but not clearly what are they. For example, 1-pole Lowpass has 90 degree phase shift, 2-pole Lowpass has 180 degree? So does it mean two 2-pole Lowpass filters has 360 degree phase shift? Beside the HighPass, LowPass, AllPass filter, other IIR filter like LowShelf, HighShelf, Peak... has phase shift too?<br/> When I apply an IIR filter using biquad transfer function, does it has any phase shift diffirent if I use direct form I (4 delay registers) vs direct form II (2 delay registers)?<br/> If IIR filter has phase shift, the phase shift occurred at the filter's target frequency, or all the frequencies? How can I phase shift (all frequencies) 90 degree clockwise &amp; counterclockwise just using AllPass filter?<br/><br/> I know some of my questions are noob, but I'm just study dsp myself, and there're somethings that I really confused about. Sorry for my bad English too :)</p> Answer: <p>I believe you have received no answers to your questions because your first three questions are so strange, so puzzling, that no one where to start to even begin to compose answers. See:</p> <p><a href="http://www.bing.com/videos/search?q=digital%20filter%20phase%20response&amp;qs=n&amp;form=QBVR&amp;pq=digital%20filter%20phase%20response&amp;sc=0-0&amp;sp=-1&amp;sk=#view=detail&amp;mid=3DC56A834B9C701B5FE93DC56A834B9C701B5FE9" rel="nofollow">http://www.bing.com/videos/search?q=digital%20filter%20phase%20response&amp;qs=n&amp;form=QBVR&amp;pq=digital%20filter%20phase%20response&amp;sc=0-0&amp;sp=-1&amp;sk=#view=detail&amp;mid=3DC56A834B9C701B5FE93DC56A834B9C701B5FE9</a></p> <p>and</p> <p><a href="http://www.bing.com/videos/search?q=digital%20filter%20phase%20response&amp;qs=n&amp;form=QBVR&amp;pq=digital%20filter%20phase%20response&amp;sc=0-0&amp;sp=-1&amp;sk=#view=detail&amp;mid=85921946745DEDD05D7385921946745DEDD05D73" rel="nofollow">http://www.bing.com/videos/search?q=digital%20filter%20phase%20response&amp;qs=n&amp;form=QBVR&amp;pq=digital%20filter%20phase%20response&amp;sc=0-0&amp;sp=-1&amp;sk=#view=detail&amp;mid=85921946745DEDD05D7385921946745DEDD05D73</a></p> <p>Good Luck.</p>
https://dsp.stackexchange.com/questions/24317/iir-filter-and-phase-shift
Question: <p>I'm trying to apply a frequency shift to a generated despreading code in order to find and track a broadcast signal CDMA. Expected doppler shift range of the signal from center frequency would be approx +/- 5KHz. Based on freq2 = c/(c-orbitspeed) * freq1.</p> <p>I am wanting to shift the code based on equations, assuming data set is made of complex numbers.</p> <ul> <li>N = sample size</li> <li>imaginary j = (0, 1) same as notation i</li> <li>new sample bin <span class="math-container">$$k = \texttt{FFT}(\texttt{generated code})[k] \times e^{-j2\pi \frac{\texttt{shift amount}}{N} k}$$</span></li> </ul> <p>This &quot;* j&quot; makes the power an imaginary number part <code>e()</code> being the same as *10^power, 10 being a real number (10, 0j). Do I need to follow the complex^complex rule to evaluate the <code>e()</code> expression? Then use the complex * complex to finish the product??</p> <pre><code>void adjust_CodeDoppler(int shift) // of fft data, apply fft in place first on gen_code { complex power; complex e; complex multiplier; power.m_re = 0; e.m_re = 10; e.m_im = 0; for(int n=0; n&lt;N; n++) { power.m_im = (-2*PI*shift/n*N); //*j part makes this the imag part of power double ph = phaseAngleComp(e); //for (10, 0j) is always 0 = 0/10 double mg = magnatudeComp(e); //for (10, 0j) is alwyas 10, sqrt( 10^2 + 0^2 ) multiplier.m_re = pow(mg, power.m_re) * exp(-1 * power.m_im * ph) * cos(power.m_re * ph + power.m_im * log(mg) ); //= 10^power real part multiplier.m_im = pow(mg, power.m_re) * exp(-1 * power.m_im * ph) * sin(power.m_re * ph + power.m_im * log(mg) ); //= 10^power imag part shift_gen_code[n] = multiplier * gen_code[n]; //using complex operator * } } </code></pre> <p>Separately to affect phase shift in data, Is this done in time domain?? Can this be sufficient to adjust phase offsets without changing a NCO/VCO on the quad mixer?</p> <p>Based on equations: also assuming data is already I / Q A/D converted</p> <ul> <li>ph = phase angle</li> <li>n = bin position, time domain?</li> <li>Wc = expected center frequency</li> <li>Dpd = desired phase offset at time []</li> </ul> <pre><code>adjusted_ph = ph[n-1] + Wc + Dpd[n] //limit phase shift if(adjusted_ph[n] &gt; 2* PI){adjusted_ph[n] = adjusted_ph[n] - 2*PI;} </code></pre> Answer:
https://dsp.stackexchange.com/questions/13841/frequency-shift-and-phase-shift-doppler
Question: <p>Suppose I have a sine wave <span class="math-container">$u(t) = \sin(2\pi f t + \phi)$</span> of known frequency but unknown phase shift and I want to find the phase shift. One way of doing this is multiply-and-adding <span class="math-container">$u(t)$</span> by a <span class="math-container">$\cos(2\pi f t)$</span> and a <span class="math-container">$\sin(2\pi f t)$</span> wave, then using <code>atan2</code> to get the phase shift like so:</p> <pre><code>f = 1; % 1 Hz. t = 0:1/f/100:2/f; % 2 cycles, 100 samples per cycle. phi0 = deg2rad(73.42); % Phase shift of the original wave. u = sin(2*pi*f*t + phi0); %% Multiply and Add using Cos and Sin I = u * cos(2*pi*f*t)'; Q = u * sin(2*pi*f*t)'; phi1 = atan2(I, Q); v = sin(2*pi*f*t + phi1); error1 = phi1 - phi0; fprintf(&quot;phi0 = %f\n&quot;, rad2deg(phi0)); % phi0 = 73.420000 fprintf(&quot;phi1 = %f\n&quot;, rad2deg(phi1)); % phi1 = 73.575271 fprintf(&quot;error1 = %f\n&quot;, rad2deg(error1)); % error1 = 0.155271 figure hold on grid on plot(t, u); plot(t, v); hold off </code></pre> <p>Next, instead of multiplying by <span class="math-container">$\cos$</span> and <span class="math-container">$\sin$</span>, I tried multiplying <span class="math-container">$u(t)$</span> by <span class="math-container">$e^{2\pi i f t}$</span>.</p> <pre><code>f = 1; % 1 Hz. t = 0:1/f/100:2/f; % 2 cycles, 100 samples per cycle. phi0 = deg2rad(73.42); % Phase shift of the original wave. u = sin(2*pi*f*t + phi0); %% Multiply and Add using Complex Exponential Z = u * exp(2*pi*i*f*t)'; phi2 = angle(Z); % -pi/2 (-90 deg) out of phase with phi0. w = sin(2*pi*f*t + phi2); error2 = phi2 - phi0; fprintf(&quot;phi0 = %f\n&quot;, rad2deg(phi0)); % phi0 = 73.420000 fprintf(&quot;phi2 = %f\n&quot;, rad2deg(phi2)); % phi2 = -16.424729 fprintf(&quot;error2 = %f\n&quot;, rad2deg(error2)); % error2 = -89.844729 figure hold on grid on plot(t, u); plot(t, w); hold off </code></pre> <p>But the result is 90 degrees out of phase. Why? Does it have something to do with the fact that it's multiplying a real value with a complex value?</p> Answer: <p>Two issues with your assumptions here. One in the way you are modeling the added phase and the other about he functioning of the <code>atan2</code> function.</p> <p>You are modeling the phase as <code>u = sin(2*pi*f*t + phi0)</code> and then making the following comparison:</p> <pre><code>I = u * cos(2*pi*f*t)'; Q = u * sin(2*pi*f*t)'; </code></pre> <p>This will match the Q (quadrature / imaginary) component with your input signal and, by convention, this will be a 90 degree phase shift as the in phase component is treated as 0 degrees.</p> <p>Also, according to the MATLAB help page for <a href="https://www.mathworks.com/help/matlab/ref/atan2.html" rel="nofollow noreferrer"><code>atan2</code></a>:</p> <blockquote> <p>P = atan2(Y,X) returns the four-quadrant inverse tangent (tan<sup>-1</sup>) of Y and X, which must be real. The atan2 function follows the convention that atan2(x,x) returns 0 when x is mathematically zero (either 0 or -0).</p> </blockquote> <p>When this is compared to the <code>angle</code> function:</p> <blockquote> <p>theta = angle(z) returns the phase angle in the interval [-π,π] for each element of a complex array z. The angles in theta are such that z = abs(z).*exp(i * theta).</p> </blockquote> <p>This is roughly equivalent to <code>angle(z) = atan2(imag(z), real(z))</code>, I think some of the edge cases may differ.</p> <p>So the modifications I would suggest are to change <code>u = sin(2*pi*f*t + phi0)</code> in both scripts and <code>phi1 = atan2(I, Q)</code> to <code>phi1 = atan2(Q, I)</code>.</p>
https://dsp.stackexchange.com/questions/83101/finding-phase-shift-using-complex-exponential
Question: <p>I'm seeking a good advice for a filter. Can you help me?</p> <p>Right now I made my own simple filter. Not sure what I'm doing, but it seems to work.</p> <pre><code>function testFilter (t, y, p) % Forward filtering % Do first filtering by jumping k/2 elements in the future l = length(t); ye = y; for i = 1:l sum = 0; k = 0; for j = 0:p-1 if(i + j &lt;= l) sum = sum + ye(i + j); k = k + 1; end end if(k != 0) ye(i+floor(k/2)) = sum/k; end end % Do the first p elements! for i = p:-1:1 sum = 0; for j = 1:i sum = sum + ye(j); end ye(i) = sum/i; end % Done! figure plot(t, ye, t, y); legend("Filtered", "Noisy") end </code></pre> <p>It's some kind of moving average, ich. The reason why I selected this is beacuse a low pass filter caused phase shift and I don't like that. </p> <p>Here is a plot that shows a example how my filter algorithm works. I think it's OK, but can it be done better without phase shift? Do you think Fast Fourier Transform is a much better filter in this noisy case?</p> <p>If there is no filter that cause phase shifting, can you recommend a good filter for me then with low phase shift?</p> <p><a href="https://i.sstatic.net/6v94r.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/6v94r.png" alt="enter image description here"></a></p> Answer: <p>If your filter is <span class="math-container">$h[n] \leftrightarrow H(e^{j\omega})$</span>, then the DTFT of the time reversed filter <span class="math-container">$h[-n]$</span> is <span class="math-container">$H^*(e^{j\omega})$</span>. Consider the result of passing your signal through the combined filter <span class="math-container">$h[n]*h[-n]$</span>, which has a DTFT of <span class="math-container">$H(e^{j\omega})H^*(e^{j\omega})=|H(e^{j\omega})|^2$</span> and has zero-phase. In this setup, I've assumed that <span class="math-container">$h[n]$</span> is causal so that makes <span class="math-container">$h[-n]$</span> anticausal, and this makes the overall filter <span class="math-container">$h[n]*h[-n]$</span> noncausal and not applicable for real time applications but can be used for offline processing. </p> <p>This is the idea used in the MATLAB command <code>filtfilt</code>. You pass <code>filtfilt</code> the filter coefficients and it runs the input signal through the filter and then the time reversed filter. Of course, you can also just as well do that by hand.</p> <p>Here is a dumb example of a noisy sine wave and a moving average filter just to illustrate. </p> <p><a href="https://i.sstatic.net/AuTPJ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/AuTPJ.png" alt="enter image description here"></a></p>
https://dsp.stackexchange.com/questions/66617/a-filter-with-low-phase-shift-or-no-phase-shift-at-all-which-one
Question: <p>So I got some oscilloscope captures for a project I'm doing and I'd like to find a phase shift between them because I don't trust the scope calculation. </p> <p>So I extracted data from a .csv file and loaded it into Matlab and now I'd like to find a phase shift using FFT (I think). Is there a way to do this even though the second signal, output, is not a perfect sinusoid?</p> <p><a href="https://i.sstatic.net/IINwt.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/IINwt.png" alt="Signals"></a></p> Answer: <p>Your waveforms appear to have a low enough noise level to use interpolation of FFT results for phase estimation. First do an fftshift (to rotate the data halfway around your FFT vector) so that the FFT result phase reference point is in the center of you original data (not at the discontinuity or edges of your waveform data). Then do the FFTs, and estimate the location of the frequency peak (if between FFT result bins by interpolation and/or successive approximation, or by knowledge of the exact frequency by other means if available), then interpolate the complex phase between bins, if needed. Then compare the two phase estimations between the two waveforms.</p>
https://dsp.stackexchange.com/questions/33485/phase-shift-between-two-signals
Question: <p>Fred, a DSP engineer, goes to his favorite DSP store to do some shopping.</p> <p><strong>Fred:</strong> Hi, I'd like to buy a phase shifter.</p> <p><strong>Shop assistant:</strong> Hmm, what exactly do you mean?</p> <p><strong>Fred:</strong> Well, you know, if you put in a sinusoid like $x(t)=\sin(\omega_0t)$ you get $y(t)=\sin(\omega_0t-\theta)$ at the output, for any $\omega_0$. And of course, $\theta$ must be adjustable.</p> <p><strong>Shop assistant:</strong> Oh, I see. Sorry, no, we don't have those. But I remember other guys needing the same thing, and they always buy a Hilbert transformer, a couple of multipliers, and an adder, and they somehow connect all these things together to make an adjustable phase shifter.</p> <p><strong>Fred:</strong> Oh yes, right!</p> <p>Fred pretends to understand what the guy is talking about. Of course he has no idea how to do that. He buys everything the guy said he needed, and thinks by himself that he might figure it out at home, or, everything else failing, he could ask it at DSP.SE.</p> <p>How can Fred build a phase shifter with adjustable phase shift $\theta$ using the components he got at the store?</p> Answer: <p>Nice question! It uses one of my favorite trig identities (which can also be used to show that quadrature modulation is actually simultaneous amplitude and phase modulation).</p> <blockquote class="spoiler"> <p> The Hilbert transform of $\sin(2\pi f_0t)$ is $-\cos(2\pi f_0t)$. Also, $$\sin(2\pi f_0t+\theta)=a\sin(2\pi f_0t)+b\cos(2\pi f_0t)$$ (constrained to $a^2+b^2=1$), with $\theta=\text{atan2}(b,a)$. This suggest one possible approach. Say Fred needs $\theta=2.1$ radians. He calculates $\tan(2.1)\approx-1.71$. Then, he needs to find $a$ and $b$ such that $a^2+b^2=1$ and $b/a=-1.71$, with $a&lt;0$ and $b&gt;0$, which is a simple algebra problem. Set $a_0=-1$, $b_0=1.71$, $n=\sqrt{a_0^2+b_0^2}$, $a=a_0/n$, and $b=b_0/n$. Then, Fred can easily generate a sine with the desired phase by using a Hilbert transformer, two multipliers, two DC sources (one set to $a$ volts and the other to $-b$ volts, to take care of the sign of the cosine), and one adder.</p> </blockquote> <p>The impulse response of the system described above is given by:</p> <blockquote class="spoiler"> <p> $a\delta(t)+\frac{b}{\pi t}$</p> </blockquote> <p>Block diagram:</p> <blockquote class="spoiler"> <p> <a href="https://i.sstatic.net/ISyhp.jpg" rel="noreferrer"><img src="https://i.sstatic.net/ISyhp.jpg" alt="enter image description here"></a></p> </blockquote>
https://dsp.stackexchange.com/questions/31597/how-to-build-a-phase-shifter-with-arbitrary-phase-shift
Question: <p>What is the difference between Digital phase modulation(DPM) and Phase shift keying (PSK)? <a href="http://suraj.lums.edu.pk/zartash/publications/2007-DigitalPhaseMod.pdf" rel="nofollow noreferrer">http://suraj.lums.edu.pk/zartash/publications/2007-DigitalPhaseMod.pdf</a> It says that PSK is a special case of DP.</p> Answer: <p>Phase shift keying is linear modulation.</p> <p>Digital phase modulation is not necessarily linear.</p>
https://dsp.stackexchange.com/questions/41039/confusion-in-phase-shift-keying
Question: <p>To help demonstrate why a time delay appears as a linear phase shift and not a constant phase shift I wanted to plot what a constant phase shift looks like.</p> <p>I have been looking at the Hilbert transform, which shifts the phase (of positive frequencies) by <span class="math-container">$-90^\circ$</span>, but I was unable to find a transform or technique that allowed shifting the phase by an arbitrary amount. </p> <p>How can I shift the phase of a signal arbitrarily? </p> Answer: <p>You can't design a filter that creates a phase shift that's constant with frequency for real valued input (if that's what you are trying to do).</p> <p>A Hilbert transformer appears to be doing this. However, the problem is, you can't implement a perfect Hilbert transformer since it's non causal with an infinite length impulse response.</p> <p>The tricky part is that the DC and Nyquist components of the spectrum have to be real valued and that the phase at these frequencies is constrained to <span class="math-container">$0$</span> or <span class="math-container">$\pi$</span>. Any phase shifter would have to have a transition band from DC to the to target phase and from the target phase to Nyquist. </p> <p>That's exactly what happens if you design a real-world Hilbert transformer: you trade off the size of the transition bands against the length &amp; complexity of the filter.</p> <p>The class of filters that only manipulate phase and not the amplitude are called allpass filters. One can easily show that </p> <ul> <li>Allpass filters have a phase that's monotonously decreasing</li> <li>For an allpass filter of oder <span class="math-container">$N$</span> the phase from DC to Nyquist decreases by <span class="math-container">$N \cdot \pi$</span></li> <li>Allpass have zeros that are inverses of the poles,</li> <li>The z-transform numerator polynomial is the reverse of denominator polynomial</li> </ul> <p>Of course you can always design an "approximation" that's good enough for your requirement. You'd have to specify the target bandwidth, max phase error, max amplitude error and then deploy a suitable FIR or IIR design method</p> <p>Even an approximate design of absolute phase shift is quite difficult, especially if you have latency or causality constraints. Constant relative phase shift is a lot easier. A popular technique is to run a signal through two parallel allpass filters which are designed to have a constant phase difference over the frequency area of interest. The outputs have identical amplitude as the input but have approximately constant phase shift with respect to each other (although not with respect to the input) </p>
https://dsp.stackexchange.com/questions/59270/how-to-achieve-an-arbitrary-phase-shift
Question: <p>I would like to apply a phase shift by multiplying by a complex exponential in Fourier space, then taking the inverse transform. I've almost got it, but it's a factor of 2 off. I want the phase shift to be <span class="math-container">$\pi/4$</span>, but it's showing a shift of <span class="math-container">$\pi/2$</span>. What am I doing wrong and why? I don't just want to insert a 2 just to make it work.</p> <pre><code>import numpy as np import matplotlib.pyplot as plt # Parameters Fs = 1000 # Sampling frequency (Hz) T = 1.0 / Fs # Sampling period (s) t = np.arange(0, 1, T) # Time vector (1 second of data) f0 = 50 # Frequency of sine wave (Hz) phi = np.pi / 4 # Phase shift (in radians) # Generate the original sine wave x = np.sin(2 * np.pi * f0 * t) # Compute the FFT of the sine wave X = np.fft.fft(x) # Create a complex exponential for phase shift n = np.arange(len(t)) # Frequency index phase_shift = np.exp(1j * phi * n) # Complex exponential # Apply the phase shift in the frequency domain X_shifted = X * phase_shift # Compute the inverse FFT to get the shifted sine wave x_shifted = np.fft.ifft(X_shifted) # Plot the results plt.figure(figsize=(10, 6)) plt.subplot(2, 1, 1) plt.plot(t[:40], x[:40], label=&quot;Original Sine Wave&quot;,marker='o') plt.title(&quot;Original Sine Wave&quot;) plt.xlabel(&quot;Time [s]&quot;) plt.ylabel(&quot;Amplitude&quot;) plt.grid(True) plt.subplot(2, 1, 2) plt.plot(t[:40], np.real(x_shifted)[:40], label=&quot;Phase-shifted Sine Wave&quot;, color=&quot;orange&quot;,marker='o') plt.title(f&quot;Phase-shifted Sine Wave (Phase = {phi} rad)&quot;) plt.xlabel(&quot;Time [s]&quot;) plt.ylabel(&quot;Amplitude&quot;) plt.grid(True) plt.tight_layout() plt.show() </code></pre> <p><a href="https://i.sstatic.net/XIzSDt0c.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/XIzSDt0c.png" alt="enter image description here" /></a></p> Answer: <p>Recall the time shift property of the Fourier Transform: <span class="math-container">$$\mathcal{F}\{x(t - t_0)\} = e^{-j\omega t_0}X(\omega )$$</span></p> <ol> <li><p><code>n = np.arange(len(t))</code> is wrong. You need the indices of the frequency bins used by the FFT: <code>n = np.fft.fftfreq(len(t), 1 / Fs)</code></p> </li> <li><p>When you multiply your FFT by <code>np.exp(-1j * phi * n)</code>, you're introducing a phase shift that increases linearly with frequency. At your sine wave's frequency (<span class="math-container">$50 \tt{Hz}$</span>), the phase shift is <span class="math-container">$50\pi/4$</span>. Since phase is modulo <span class="math-container">$2\pi$</span>, that's <span class="math-container">$50\pi/4 \text{ mod } 2\pi = \pi/2 $</span>, resulting in what you're seeing.</p> </li> </ol> <p>You need to have a constant phase shift: <code>phase_shift = np.exp(-1j * phi/f0 * n)</code>:</p> <p><a href="https://i.sstatic.net/OlJLOXt1.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/OlJLOXt1.png" alt="enter image description here" /></a></p>
https://dsp.stackexchange.com/questions/95727/apply-phase-shift-using-fft-and-complex-exponential
Question: <p>I have read some literatures about the different topologies of beamforming and it came to my mind a question : where is applied the phase shift for each channel depending on the type of topology/technology used?</p> <p>For analog beamforming, it is obvious as there is only one signal, the modulated carrier signal which is splitted to the different channels and phase shifting occurs afterward. The phase shifting stage comprises a gain/attenuation stage and a phase shifter stage. If the modulated signal is built by a digital stage, there is one DAC used for all channels prior to mixing and phase shifting.</p> <p>In digital beamforming, the topology is a bit different: one DAC is used for each channel. This enables more possibilities, among them the possibility to phase shift digitally each channel when defining the modulation. However two types of digital beamforming exist:</p> <ul> <li>one with LO mixing if the DAC is not fast enough to produce a RF signal, </li> <li>another using RF-DAC where no LO mixer is required.</li> </ul> <p>As in the first situation LO signal is generally the same for all channels, no phase shift is applied on LO-IF signal. Is the phase shift on IF modulation signal is enough or is it needed to phase shift the signal after mixing (to obtain an equivalent behavior as in analog beamforming?).</p> <p>Best regards</p> Answer: <p>In a first analysis, it does not matter where the phase shifting is inserted, as long as the mixing stage is linear.</p> <p>Indeed, shifting a temporal signal is equivalent to multiplying it with a complex number integration the phase shift <span class="math-container">$\theta$</span> :</p> <ul> <li>Unshifted signal : <span class="math-container">$s(t)$</span></li> <li><span class="math-container">$\theta$</span> phase shifted signal : <span class="math-container">$s'(t) = s(t).e^{j\theta}$</span></li> <li><span class="math-container">$f_0$</span> carrier mixed unshifted signal : <span class="math-container">$s_c(t) = s(t).c(t) = s(t).e^{2j\pi f_0.t}$</span></li> <li><span class="math-container">$f_0$</span> carrier mixed <span class="math-container">$\theta$</span> shifted signal : <span class="math-container">$s'_c(t) =s(t).e^{2j\pi f_0.t}.e^{j\theta}$</span> = <span class="math-container">$s(t).c'(t)$</span> </li> </ul> <p>where <span class="math-container">$c'(t) = e^{j(2\pi f_0.t+\theta)}$</span> is the shifted carrier.</p> <p>In the end phase shifting the signal to be modulated is equivalent to phase shifting after carrier modulation.</p>
https://dsp.stackexchange.com/questions/64093/digital-beamforming-and-phase-shift-stage-insertion
Question: <p>I am researching a dynamic system. It takes in a sine wave <code>A*sin(2*pi*f*t) + D</code> and outputs a non-isosceles triangle wave. Let's call input signal SP and output signal PV. I want to create amplitude and phase characteristics of this system. I have taken measurements of SP and PV for different <code>f</code>s. Amplitude <code>A</code> was the same for every measurement. Now, calculating amplification of the system is easy (using Matlab notation: <a href="https://www.mathworks.com/help/stats/range.html" rel="nofollow noreferrer">range</a>):</p> <p><code>range(PV) / range(SP)</code></p> <p>But I have a problem with calculating phase shift. I have came up with a following algorithm, but I think it is not universal:</p> <pre class="lang-matlab prettyprint-override"><code>% t is the time vector dt = t(2) - t(1); % SP and PV are read from file earlier % here they are centered around 0 PV = centerSignal(PV); SP = centerSignal(SP); % T is the period of the signals derived from their frequency f T = 1/f; % f ranges from 0.1 Hz to 10 Hz % I specify MinPeakDistance to ignore possible errors in data peakDistance = round(0.5 * T / dt); % find positive and negative peak's locations in SP and PV [~,posPeaksPV] = findpeaks( PV + abs(PV),&quot;MinPeakDistance&quot;,peakDistance); [~,posPeaksSP] = findpeaks( SP + abs(SP),&quot;MinPeakDistance&quot;,peakDistance); [~,negPeaksPV] = findpeaks(-PV + abs(PV),&quot;MinPeakDistance&quot;,peakDistance); [~,negPeaksSP] = findpeaks(-SP + abs(SP),&quot;MinPeakDistance&quot;,peakDistance); % select only those peaks of PV that are after first peak of SP posPeaksPV = posPeaksPV(posPeaksPV &gt; posPeaksSP(1)); negPeaksPV = negPeaksPV(negPeaksPV &gt; negPeaksSP(1)); % make peaks array the size of the smaller array lenPos = min([length(posPeaksPV) length(posPeaksSP)]); lenNeg = min([length(negPeaksPV) length(negPeaksSP)]); posPeaksPV = posPeaksPV(1:lenPos); posPeaksSP = posPeaksSP(1:lenPos); negPeaksPV = negPeaksPV(1:lenNeg); negPeaksSP = negPeaksSP(1:lenNeg); % calculate phase shift posPhaseShift = mean(t(posPeaksSP) - t(posPeaksPV)); negPhaseShift = mean(t(negPeaksSP) - t(negPeaksPV)); phaseShift = mean([posPhaseShift negPhaseShift]) * (360 / T) function sigOut = centerSignal(sigIn) minSig = min(sigIn); maxSig = max(sigIn); sigOut = sigIn - ((maxSig - minSig)/2 + minSig); end </code></pre> <p>Matlab reference: <a href="https://www.mathworks.com/help/signal/ref/findpeaks.html" rel="nofollow noreferrer">findpeaks</a></p> <p>I have made interactive version of this algorithm (and sort of my data) on <a href="https://www.desmos.com/calculator/bnen9chrlo" rel="nofollow noreferrer">Desmos</a>. The position I left the moveable points of triangle signal in, imitates this one sample below I've been analysing while trying to come up with the algorithm:</p> <p><a href="https://i.sstatic.net/4VEdJ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/4VEdJ.png" alt="Sample signals of frequency 1.8 Hz" /></a></p> <p>The calculation of amplification and phase shift on Desmos are analogical to those done by Matlab code above.</p> <p>The one problem I've discovered while playing with visualisation on Desmos was that if you put one point on the peak of the sine wave and only move the other one the phase shift changes which seem kind of wrong.</p> <p>Summarizing: <strong>Is there a standard way of determining a phase shift between a sine wave and a non-isosceles triangle wave?</strong></p> <p>Edit: By &quot;phase shift&quot; I mean how much is one signal shifted in time in respect to other signal. For sinusoids its easy: signals have the same phase when their peaks and valleys occur at the same time. But for non-isosceles triangle wave its not quite straightforward.</p> Answer: <blockquote> <p>Is there a standard way of determining a phase shift between a sine wave and a non-isosceles triangle wave?</p> </blockquote> <p>Not really. The operation you describe is highly non-linear so the concept of a transfer function doesn't apply.</p> <p>Probably the best you can do here is to define the phase shift in terms of the fundamental. The triangle output can be represented as a Fourier Series with the same fundamental frequency as the input. You could define the shift as the phase difference between the input and the fundamental of the triangle. Each of the harmonics of the triangle also have a phase associated with them but there is no &quot;one size fits all&quot; way of defining a phase reference for them. Even if you did: they'd be all different numbers.</p> <p>Whether any of this useful or not depends on what exactly your application or requirements are.</p>
https://dsp.stackexchange.com/questions/91541/phase-shift-of-non-isosceles-triangle-wave
Question: <p>I'm trying to find the phase shift between two 100x100 matrices, s and p. To start with I'm using two sine waves (2D) slightly shifted. I manage to compute the correct amplitude spectrum (using the Fourier Transform of the cross correlation between s and p) but the phase value at the peaks is not the one that I have set. I'm not using cpsd because I did not manage to understand the correct way to use it for 2D matrices. The manual is very confusing and I couldn't get any help online.</p> <p>When I do the same procedure for 1D sine waves, using cpsd or fft of xcorr employing the welch method, I get both the amplitude and phase right. I suppose that conceptually I'm doing the right thing, but there's sth about how to get the phase shift between two matrices that is bugging me.</p> <p>I really would appreciate any tips on how to compute the phase shift between matrices. Some real piece of code would be lovely.</p> <p>thank you in advance for your time</p> Answer:
https://dsp.stackexchange.com/questions/24611/phase-shift-between-two-images-matrices
Question: <p>I try to make graph/print for magnitudes and phase shifts for impulse response calculated by FFT. For magnitude everything works perfect, but for phase shift I get some strange curve for higher frequencies. I can't figure out why. Could anyone help me?</p> <p>I calculate phase shift by that: <code>atan2(fftOutput.imag(),fftOutput.real()) * 180.0/M_PI;</code></p> <p>And for simply impulse, like: impulse[1024] = { 1, 0, 0, 0 ... 0 }</p> <p>with no processing I expect straight line (phase shift for all freq bin should be zero).</p> <p>But I get something like that (I drawn it in paint, cause I can't run my app at the moment, but it looks almost exactly the same):</p> <p><a href="https://i.sstatic.net/21IQb.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/21IQb.png" alt="enter image description here"></a></p> <p>Why is that?</p> Answer: <p>Something is wrong with your FFT. This looks like your input signal is either time reversed or shifted (circular) by one sample to the left. </p>
https://dsp.stackexchange.com/questions/51841/phase-shift-problem-in-fast-fourier-transform
Question: <p>I want to shift the response phase of an audio signal (float array, length N, value range -1..1). I'm about using Fast Hartley Transform to transform it to the frequency-domain, process phase shift, then convert back to the time-domain and output the result.<br/> I'm now can do the Hartley transform, and I also can calculate the phase of k<em>th</em> bin:<br/></p> <pre><code>real(k) = (x(k) + x(-k))/2 imag(k) = (x(k) - x(-k))/2 phase(k) = atan2(imag(k), real(k)) </code></pre> <p>I want to shift the phase(k) by an α degree. What should I do?</p> Answer: <p>I think your notation is a bit fishy but I'll use it. Assuming that your $\text{phase}(k)$ calculation is correct, do a complex multiplication of $\text{real}(k) + i\ \text{imag}(k)$ by $e^{i\alpha} = \cos(alpha) + i\sin(alpha)$. That can be done using four real multiplications and a few add/sub. Then you need to reverse the process of how you obtained $\text{real}(k)$ and $\text{imag}(k)$:</p> <p>$$x(k) = \text{real}(k) + \text{imag}(k)$$ $$x(-k) = \text{real}(k) - \text{imag}(k)$$</p> <p>Finally retransform.</p>
https://dsp.stackexchange.com/questions/24357/audio-phase-shift-using-hartley-transform
Question: <p>In MATLAB's Comm System Toolbox there is an option for 'Phase Rotation', defined as the phase difference between previous and current modulated symbols when the input is zero. This is the first time I've heard of this concept. </p> <p>Let's take DQPSK as an example. Say my previous symbol had an absolute phase of $0$, (1+j0) and I am trying to encode '01'. Under the DQPSK scheme I'm familiar with, '01' corresponds to a phase shift of $\pi/2$. Therefore the absolute phase of this symbol would be $\pi/2$, (0+j1). MATLAB would describe this scheme as having a phase rotation of 0.</p> <p>If the same example were to use a phase rotation as $\pi/2$ then the absolute phase of the symbol would be:</p> <p>$0$ (phase of last symbol) + $\pi/2$ (shift due to modulation) + $\pi/2$ (additional phase rotation) = $\pi$</p> <p>This brings me to my question. Performing the additional phase shift requires increased complexity at the receiver and transmitter. So what is to be gained from the process of adding an additional phase shift? Why do it in the first place?</p> Answer: <p>A QPSK constellation could in theory have any rotation. For example, $$\mathcal{S}=\lbrace 1, j, -1, -j \rbrace $$ is a QPSK constellation, and $e^{j\phi}\cdot\mathcal{S}$ is also a QPSK constellation. Matlab's <code>phaserot</code> parameter in the <code>dpskmod</code> command is $\phi$ in the equation above.</p> <p>What is to be gained depends on the particular application I guess. In particular, note that $\phi=\pi/4$ is nice because then the ML decoding rule is equivalent to finding what quadrant the received point is in.</p>
https://dsp.stackexchange.com/questions/30252/reasoning-behind-additional-phase-shift-in-dpsk
Question: <p>The most common type of discrete cosine transform (DCT-II) is defined as <span class="math-container">\begin{align} X_k&amp;=\sum_{n=0}^{N-1}x_n\cdot \cos\left(\frac{\pi}{N}\left(n+\frac{1}{2}\right)\cdot k\right)&amp;\text{where }&amp; k=0,1,...,N-1 \end{align}</span> (c. f. <a href="https://en.wikipedia.org/wiki/Discrete_cosine_transform" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Discrete_cosine_transform</a>)</p> <p>My problem is that I just don't get what that phase shift of <span class="math-container">$\frac{1}{2}$</span> is for. In the <a href="https://www.ic.tu-berlin.de/fileadmin/fg121/Source-Coding_WS12/selected-readings/Ahmed_et_al.__1974.pdf" rel="nofollow noreferrer">paper introducing the DCT-II</a> it was just defined that way, seemingly because the authors wanted to link it to Chebyshev polynomials. That analogy may be neat, but what are the actual benefits of the phase shift?</p> <p>For all I can say, we might as well leave it out. But obviously, there must be something to it since it is still used today. Sadly all the books I've consulted just give the definition of the DCT without justifying the phase shift. Could someone explain or point me to a good source?</p> Answer: <p>I think that phase shift is what causes the DCT-II to have different boundary properties compared to the DCT-I, as shown on the <a href="https://en.wikipedia.org/wiki/Discrete_cosine_transform#Informal_overview" rel="nofollow noreferrer">DCT Wikipedia page</a>. It means that it is even around <span class="math-container">$n=-1/2$</span> and <span class="math-container">$N-1/2$</span>. I suspect that this helps it to be sparser, and might also be important for other applications.</p>
https://dsp.stackexchange.com/questions/72892/phase-shift-of-discrete-cosine-transform-dct
Question: <p>I'm not a specialist in this field and learnt FFT fairly recently.</p> <p>I want to calculate phase difference of between 1 MHz signals sampled at 4 MHz. The sample counts are both 144. I think the magnitudes and the frequencies are all correct. But phase shifts are off.</p> <p>So, I decided to go back and start with simpler sets of data. I do fft on 16 samples of a channel sampled at 16 Hz.</p> <p>The code that actually makes wave data is as below;</p> <pre><code> class FunctionGenParam { public int portionNumber; public double nXRes; public int sampleCount; public FunctionGenParam(int portionnumber, double xresolution, int samplecount) { portionNumber = portionnumber; nXRes = xresolution; sampleCount = samplecount; } public List&lt;GraphParam&gt; lstGraphParam = new List&lt;GraphParam&gt;(0); } private void GenerateYourPortion(object functionparam) //portionNumber를 object로 정의한 것은 parameterizedthreadstart가 object를 받기 때문에 나중에 편하려고.. { FunctionGenParam param = (FunctionGenParam)functionparam; List&lt;double&gt; lstdbl = new List&lt;double&gt;(0); float start = param.portionNumber * param.sampleCount; for (float n = 0; n &lt; param.sampleCount; n++) { float y = 0f; if (param.lstGraphParam.Count== 0) return; for (int i = 0; i &lt; param.lstGraphParam.Count; i++) { switch (param.lstGraphParam[i].Graph) { case &quot;Sine&quot;: float sineresult = (float)Math.Sin((((n+start) * param.nXRes) + param.lstGraphParam[i].PhaseAngle) * radian * param.lstGraphParam[i].Frequency) * param.lstGraphParam[i].Amplitude + param.lstGraphParam[i].Offset; y += sineresult; break; case &quot;Cosine&quot;: float cosineresult =(float)Math.Cos((((n + start) * param.nXRes) + param.lstGraphParam[i].PhaseAngle) * radian * param.lstGraphParam[i].Frequency) * param.lstGraphParam[i].Amplitude + param.lstGraphParam[i].Offset; y += cosineresult; break; //case &quot;Pulse&quot;: // float pulseresult = (float)Math.Sin((((n + start) * param.nXRes) + param.lstGraphParam[i].PhaseAngle) * radian * param.lstGraphParam[i].Frequency) * param.lstGraphParam[i].Amplitude + param.lstGraphParam[i].Offset; // if (pulseresult &gt; 0f) // y += param.lstGraphParam[i].Amplitude + param.lstGraphParam[i].Offset; // else // y += -param.lstGraphParam[i].Amplitude + param.lstGraphParam[i].Offset; // break; } } //inputsignal.channel1.lstInData.Add((double)y); lstdbl.Add((double)y); } arDblList[param.portionNumber] = lstdbl; } </code></pre> <p>And the code that calls it is as below;</p> <pre><code>#region CH1 if (lvSig_In_CH1.CheckedItems.Count &gt; 0) { Thread[] threads = new Thread[Environment.ProcessorCount]; nXRes = 360 / (double)inputsignal.SamplingFrequency; int nSampleCount = (int) (inputsignal.SamplingFrequency * Convert.ToInt32(tboxSeconds.Text.ToString()))/threads.Length; if (tboxSampleCount.Text != &quot;&quot;) nSampleCount = (int)(Convert.ToInt32(tboxSampleCount.Text.ToString())/threads.Length); for (int i = 0; i &lt; threads.Length; i++) { FunctionGenParam paramchannel1 = new FunctionGenParam(i, nXRes, nSampleCount); for (int j = 0; j &lt; lvSig_In_CH1.CheckedItems.Count; j++) { GraphParam gpm = new GraphParam(lvSig_In_CH1.CheckedItems[j].SubItems[1].Text, // Graph Type Convert.ToSingle(lvSig_In_CH1.CheckedItems[j].SubItems[2].Text), // Frequency Convert.ToSingle(lvSig_In_CH1.CheckedItems[j].SubItems[3].Text), // Amplitude Convert.ToSingle(lvSig_In_CH1.CheckedItems[j].SubItems[4].Text), // Phase Convert.ToSingle(lvSig_In_CH1.CheckedItems[j].SubItems[5].Text)); // Offset paramchannel1.lstGraphParam.Add(gpm); } threads[i] = new Thread(GenerateYourPortion); threads[i].Start(paramchannel1); } // Thread.Join을 통해서 모든 쓰레드가 다른 쓰레드가 작업 중일 때는 기다렸다가 // 자기 차례가 오면 자기 작업을 수행하도록 한다. // 이건 쓰레드를 Start 시키고 난 후에 호출해야한다. for (int i = 0; i &lt; Environment.ProcessorCount; i++) threads[i].Join(); for (int i = 0; i &lt; Environment.ProcessorCount; i++) { inputsignal.channel1.lstInData.AddRange(arDblList[i]); } } inputsignal.channel1.ElapsedSeconds = Convert.ToSingle(tboxSeconds.Text); #endregion CH1 </code></pre> <p>Now assume shift is 1.5 degree.</p> <p>The results are below; Frequency: Result</p> <ul> <li>1 : 1.5 (Correct)</li> <li>2 : 3.0 (Doubled!!!)</li> <li>3 : 3.0 (Tripled!!!)</li> </ul> <p>Now assume shift is 180. Frequency: Result</p> <ul> <li>1 : 180 (Correct)</li> <li>2 : 360 (Doubled!!!)</li> <li>3 : 180 (Correct)</li> <li>4 : 360 (Doubled!!!)</li> </ul> <p>This is Time Domain of 2 Hz with 180 degree phase difference; <a href="https://i.sstatic.net/dDOaR.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/dDOaR.png" alt="enter image description here" /></a></p> <p>And this is the table of data; <a href="https://i.sstatic.net/ImBvn.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ImBvn.png" alt="enter image description here" /></a> As you can see, only when the frequency is 1 Hz, the phase angle is correct.</p> <p>This is the frequency domain graph with data. The grey graph shows phases;</p> <p><a href="https://i.sstatic.net/bJ40g.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/bJ40g.png" alt="enter image description here" /></a> I use VS C# code to get the phase angle as below;</p> <pre><code>double nPhaseAngle = 0d; nPhaseAngle = Math.Atan2(cpxchannel1[i].Imaginary/10, cpxchannel1[i].Real); nPhaseAngle = nPhaseAngle * (180 / Math.PI) + 90; if (nPhaseAngle &lt; 0) nPhaseAngle = 360 + nPhaseAngle; dblchannel1_Phase.Add(nPhaseAngle); </code></pre> <p>Please experts!! Help me. Frankly speaking, I learn how to do it long time ago but still can't figure this thing out.</p> <p>Sukho Suh</p> Answer:
https://dsp.stackexchange.com/questions/88501/calculate-phase-shift-using-fft
Question: <p>I was learning Modulation Techniques and was on the topic Phase Shift Keying (PSK). As far as I have understood, </p> <p>In Binary PSK we encode a single bit on a one signal element and we differentiate between two bits (or two signal elements) by their different phase. And that it's favorable to keep the phase different maximum between the two different signal elements, so we use a phase difference of 180 degrees. </p> <p>In Quadrature PSK, we want to transmit two bits per signal element. Since there are four different possible combinations of two bit numbers, we want four distinguishable signal element to distinguish between the four combinations. So we use signal elements with four different phases and with a difference between them of 90 degree (which is maximum possible).</p> <p>Untill here, I seem to understand it. Correct me if anything from above is wrong.</p> <p>I read from a source that in QPSK, the four different phases are 45°, 135°, 225°, and 315°. The excerpt from the said text is as under</p> <blockquote> <p>It makes sense to seek maximum separation between the four phase options, so that the receiver has less difficulty distinguishing one state from another. We have 360° of phase to work with and four phase states, and thus the separation should be 360°/4 = 90°. So our four QPSK phase shifts are 45°, 135°, 225°, and 315°</p> </blockquote> <p>My first question is, aren't phases relative? What are these phase shift of 45°, 135°, 225°, and 315° relative to? My common understanding makes me wonder wouldn't just four sine waves, one not shifted at all, second sifted 90° relative to the first, third shifted 180° relative to the first, fourth shifted 270° relative to the first make more sense and be appropriate to represent different data elements?</p> <p>The same text states that </p> <blockquote> <p>The term “quadrature modulation” refers to modulation that is based on the summation of two signals that are in quadrature. In other words, it is I/Q-signal-based modulation. QPSK is an example of I/Q-based modulation.</p> </blockquote> <p>My second question is, how exactly is four different phases achieved by modulating the amplitude of just two- I &amp; Q signals? At first, it seems to me that I/Q signaling can only be used to shift a signal 90° (i.e., 45° in each direction).</p> <p>Also, Whether Binary PSK is also done using I/Q-based signals?</p> <p>There's another question <a href="https://dsp.stackexchange.com/questions/6446/i-and-q-components-and-the-difference-between-qpsk-and-4qam">I and Q components and the difference between QPSK and 4QAM</a> which (maybe) addresses my problem, but it's too complicated and mathemaical for a beginner like me.</p> Answer: <p>(1) The phases are indeed relative. The numbers 45, 135, 225 and 315 are relative to the transmitter's oscillator. The receiver, of course, has a different oscillator, so it will need to do some procesing to estimate the phases.</p> <p>Related to this subject, there is also differential modulation, where 1s and 0s are transmitting by changing the phase relative to the previous symbol.</p> <p>(2) This identity is useful to understand I/Q modulation: <span class="math-container">$$A_I \cos(2\pi f t) + A_Q \sin(2\pi f_c t) = S_{IQ} \cos(2\pi f_c t - \theta_{IQ}) $$</span> where <span class="math-container">$$ S_{IQ} = \sqrt{A_I^2 + A_Q^2}$$</span> and <span class="math-container">$$\theta_{IQ} = \tan^{-1}\frac{A_Q}{A_I}.$$</span> So, as you can see, you can achieve any phase <span class="math-container">$\theta_{IQ}$</span> by adding the I and Q signals with appropriate amplitudes.</p> <p>(3) Binary PSK is just an I signal. Since the two phases in BPSK are zero and 180, the Q portion of the signal is always zero.</p>
https://dsp.stackexchange.com/questions/60902/binary-and-quadrature-phase-shift-keying
Question: <p>When I have digital audio signal, represented in samples, I can easily phase-shift the signal by 180° by simply inverting the value of each sample.</p> <p>But what if I want to phase shift an arbitrary voice audio signal by say +90° or -90°?</p> <p>How do I transform an arbitrary, discrete signal by phase-shifting it by an arbitrary phase angle?</p> Answer: <p>The answers to <a href="https://dsp.stackexchange.com/q/31597/4298">this question</a> explain the solution for the continuous-time case. In discrete time, the solution is completely analogous. The impulse response of a phase shifter with phase shift $\theta$ is given by</p> <p>$$h[n]=\cos(\theta)\delta[n]+\sin(\theta)g[n]\tag{1}$$</p> <p>where $g[n]$ is the impulse response of an (ideal) <a href="https://en.wikipedia.org/wiki/Hilbert_transform#Discrete_Hilbert_transform" rel="nofollow noreferrer">discrete-time Hilbert transformer</a>. Eq. $(1)$ shows that the solution is just a linear combination of the identity system and a Hilbert transformer (which performs a $90$ degree phase shift).</p>
https://dsp.stackexchange.com/questions/48976/how-to-calculate-arbitrary-phase-shift-in-discrete-signal
Question: <p>This is probably a really basic question but I'm a little stumped and would appreciate some practical input on how to go about doing this rather than reading dockets of equations semi-related to what I am doing. </p> <p>So say I have data which is largely reminiscent of a sine wave. I do an forward Fourier transform and low pass filter it to remove some noise. Is it possible to then find the phase or shift of the remaining sine wave with the transformed data in the frequency domain before performing the inverse transform?</p> <p>I did some reading and it looks like the phase shift information is stored in the imaginary part of the transform?</p> <p>I've written two algorithms for finding the phase shift in the time domain, but they are clunky and unfortunately unreliable. Any help would be appreciated.</p> <p>Also, I'm not specifically asking for the answer but keywords to research, or places to find information would be highly appreciated.</p> Answer:
https://dsp.stackexchange.com/questions/23655/sine-wave-phase-shift-from-fourier-transform
Question: <p>I designed an FIR highpass filter which is causing a phase shift to the output. The output signal is also not stable (?) on start. Are these normal or am I doing something wrong? If these are normal, what causes these? (Attached is a diagram showing the input in blue and the output in red).<img src="https://i.sstatic.net/wZaw4.png" alt="enter image description here"> Thanks. </p> Answer: <p>This is perfectly normal. At the beginning you see the transient effect because the signal suddenly starts and the filter was at rest before (zero initial condition). A causal filter will always add some phase shift to your signal. This phase shift is usually frequency dependent, but for a <em>linear phase</em> FIR filter the resulting delay is independent of frequency.</p> <p>If $H(e^{j\omega})$ is the frequency response of the filter and $\phi(\omega)=\arg\{H(e^{j\omega})\}$ is its phase response, then the phase shift experienced by a sinusoid with frequency $\omega_0$ is simply $\phi(\omega_0)$, i.e. the corresponding time delay equals $-\phi(\omega_0)/\omega_0$.</p>
https://dsp.stackexchange.com/questions/23369/fir-filter-phase-shift-and-stability
Question: <p>I know about <a href="http://whatis.techtarget.com/definition/phase" rel="nofollow">phase of a 1D signal</a>. But when I go into higher dimensions like 2D,3D etc, it becomes headache to grasp the concept. </p> <ul> <li>What are the terms phase shift and phase spectrum mean in case of multidimensional(2D,3D etc.) signal like an Image or video signal? </li> <li>How is the phase term represented mathematically? </li> <li>How do we analyze phase spectrum? </li> <li>Which information do we get from phase spectrum about the signal? </li> <li>Can anybody explain with a plot or figure ?</li> </ul> Answer: <p>For a real signal, the <strong>magnitudes</strong> of the Fourier transform bins tell what are the amplitudes of the sinusoidal components that an infinite tiling of the signal frame can be decomposed into. The <strong>phases</strong> of the bins encode <strong>translation</strong> of the sinusoids along their direction, like so:</p> <p><img src="https://i.sstatic.net/UXDW8.png" alt="enter image description here"></p> <p>The translation can be decomposed into a series of component translations one along each of the axes. The axes of an image are spatial axes, and in video the third axis is temporal. The component translations have magnitudes inversely proportional to the frequencies indicated by the multidimensional index of the bin. For example, you can easily spatially translate an image in the frequency domain by adding to all phases (in a polar form representation of the bins) a function of form $af_x + bf_y$ where $a$ and $b$ are constants that give the amount of translation and $f_x$ and $f_y$ are the vertical and horizontal frequencies (bin indexes).</p> <p>Translation of a sinusoid of zero frequency is a bit of an oxymoron. With real FFT its phase is fixed to zero.</p>
https://dsp.stackexchange.com/questions/22711/phase-shift-and-phase-spectrum-terms-in-multidimensional-signal
Question: <p>While going through FFT I came to know that, shifting of phase in frequency domain results on shifting of time in time domain.</p> <p>According to this, in wireless communications, from the transmitter side having 2 antennas,signal s1 transmitted from Ant 1 and phase shifted version of sig2 in frequency domain transmitted from Ant2, sig2 will become a delayed version of sig1. And when both the antennas transmitting sig1 and sig2 at the same time how sig2 will become a delayed version or a multipath component to sig 1. </p> Answer: <p>Suppose one signal is $a_1(t) = \cos(\omega t)$ and the other is $a_2(t) = \cos(\omega t - \theta)$. Note the phase shift $\theta$ between the two signals, and note also that we can write $$a_2(t) = \cos(\omega t - \theta) = \cos\left(\omega\left(t-\frac{\theta}{\omega}\right)\right) = \cos(\omega (t - t_0)) = a_1(t-t_0)$$ where $t_0 = \frac{\theta}{\omega}$ showing that $a_2(t)$ is a <em>delayed</em> version of $a_1(t)$. Suppose that $a_1(t)$ and $a_2(t)$ are transmitted from the two separate antennas <em>simultaneously</em>, that is, no additional time delay between them, and reach the receiver over paths of delays $\tau_1$ and $\tau_2$ respectively and gains $A_1$ and $A_2$ respectively. Then the received signals are $$\begin{align} A_1a_1(t-\tau_1) &amp;= A_1\cos(\omega (t -\tau_1)) = A_1\cos(\omega \hat{t})\\ A_2a_2(t-\tau_2) &amp;= A_2\cos(\omega (t -t_0 - \tau_2))\\ &amp;= A_2\cos(\omega (\hat{t} +\tau_1 -t_0-\tau_2))\\ &amp;= A_2\cos(\omega (\hat{t} - (t_0 + \tau_2-\tau_1))\\ &amp;= A_2\cos(\omega \hat{t} -\hat{\theta}) \end{align}$$ where $\hat{t} = t-\tau_1$ is the <em>time as measured by the receiver clock</em>. Thus we see that the second signal is delayed <em>with respect</em> to the former by $t_0+\tau_2-\tau_1$, that is, the delay introduced at the transmitter plus the difference in the delays between the two paths, and this can be expressed as a phase shift of $\hat{\theta}= \frac{t_0+\tau_2-\tau_1}{\omega}$.</p> <ul> <li><p>If $\tau_1 = \tau_2$ so that the two paths are of identical lengths, the second signal looks like a multipath signal with respect to the first with a delay of $t_0$ (equivalently the same phase shift $\theta$ as existed at the transmitter).</p></li> <li><p>If $t_0 = 0$ so that effectively only one signal is transmitted, but is received over paths of different lengths, the second signal <em>is</em> a multipath signal with respect to the first with a delay of $\tau_2-\tau_1$ and it too can be expressed as a phase shifted version of the first signal.</p></li> </ul>
https://dsp.stackexchange.com/questions/9154/frequency-domain-phase-shift
Question: <p>I have ECG signal sampled at 100Hz &amp; using Python to remove noise, and generate a template signal from the collection of ECG from a total of almost 4700 signals. I have removed the noise from ECG using PCA and now looking to 'stack' together signals on top of each other to generate a template signal which will serve as a filter to improve SNR. Now I have run into a little problem, some signals are shifted and I cannot manually go through 4700 signals to remove the shift, is there any method to remove the phase shift or align the signals. The pictures depict the problem I am facing.</p> <p><a href="https://i.sstatic.net/ARt8G.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ARt8G.png" alt="enter image description here" /></a></p> <p><a href="https://i.sstatic.net/5drKf.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/5drKf.png" alt="enter image description here" /></a></p> Answer:
https://dsp.stackexchange.com/questions/89069/removing-phase-shift-in-ecg-signal
Question: <p>I have two signals with nearly the same frequency, and i would like to find the phase shift between them, since i am using micro-controller, i would like to do it in the less expensive way.</p> <p>I know how to calculate Goertzel for a specific frequency bin (for each signal), but how do i calculate the angle for this bin by using Goertzel? </p> <p>If you know a lower computational method, please advice.</p> <p>Thanks </p> Answer: <p>If the complex frequency bin outputs of the two Goertzel filters are $a$ and $b$, you can calculate the phases as $\alpha = \text{atan2}\left(\text{Im}(a),\ \text{Re}(a)\right)$ and $\beta = \text{atan2}\left(\text{Im}(b),\ \text{Re}(b)\right)$, where $\text{Re}$ returns the real component and $\text{Im}$ returns the imaginary component of the argument. Most programming languages will have the two-argument $\text{atan2}$ function. The phase difference can be calculated as $\alpha - \beta = \text{atan2}\left(\text{Im}\left(a\ \text{conj}(b)\right),\ \text{Re}\left(a\ \text{conj}(b)\right)\right)$, where $\text{conj}$ denotes taking the complex conjugate, saving you one $\text{atan2}$ evaluation and wrapping of the phase, at the cost of one complex multiplication. </p> <p>There's one more trick available to calculate $a\ \text{conj}(b)$. Multiply the Goertzel output $a$ by the second input signal and lowpass filter the result. In frequency domain it looks like this:</p> <p><img src="https://i.sstatic.net/9MMH7.png" alt="enter image description here"></p> <p>The lowpass filtering isolates the circled spectral peak that corresponds to $a\ \text{conj}(b)$. This saves you one Goertzel filter at the cost of a lowpass filter. If you use this trick you must also take into account the phase shift due to the lowpass filter.</p> <p>For fast $\text{atan2}$ see <a href="https://dsp.stackexchange.com/q/28814/15347">Methods of computing fixed point atan2 on FPGA</a>.</p>
https://dsp.stackexchange.com/questions/23944/using-goertzel-to-find-phase-shift
Question: <p>Consider the measurements of two modulated AC signals (voltage and current) which may have noise, harmonics and a DC bias. Each measured signal consists of a list for the time and a list for the corresponding values.</p> <p>My goal is to find out the phase shift in degrees between these two signals in a robust way.</p> <p>I would like to realize this in the frequency domain perhaps by calculating and evaluating the fundamental waves of the signals.</p> <p>Any help or sample code (MATLAB) would be very much appreciated.</p> Answer: <p>Do this procedure on both signals, and subtract the results to get what you want (it would be a nearly constant sequence whose value is phase shift in radians)</p> <ol> <li><p>Perform FFT on the signal to obtain its spectrum.</p></li> <li><p>Find the dominant harmonic of the signal : $f_c$ (where the peak of FFT occurs).</p></li> <li><p>Filter the signal with a narrow-band linear phase filter (center = $f_c$, bandwidth as less as possible).</p></li> <li><p>Again, perform FFT on the signal and extract its phase.</p></li> </ol> <p>Note : It is assumed that the signal has a dominant frequency otherwise a phase shift is pointless</p>
https://dsp.stackexchange.com/questions/10723/calculate-phase-shift-between-two-signals
Question: <p>I red that 180 degree phase shift causes spurious high frequency components which As a result methods such as OQPSK are invented, but I can't understand how it can happens? In fact, I can't find any connection between 180 degree phase shift and the creation of high frequency components. or for example why 90 degree doesn't cause such an effect?! I would appreciate it if you could explain.</p> Answer: <p>OQPSK is used specifically to limit the peak-avg ratio of the QPSK waveform, as it avoids transitions from going through the origin. When the modulation in QPSK changes from one point in the constellation to another that is opposite (which is a 180 degree phase transition), the transition with go through or near the origin and with that result in larger variations in the magnitude of the modulated waveform. What is the real concern is the magnitude, specifically the variation in the envelope of the waveform. This leads to requiring greater back-offs in average input power to power amplifiers, to keep them running in their linear regions. The non-linearity in amplitude (not phase) leads to spectral regrowth in the output of the power amplifier. OQPSK limits transitions at any give time to adjacent instead of opposite points in the constellation, so never goes through or near the origin.</p> <p>Linearity for amplifiers is often specified as &quot;1 dB compression (P1dB)&quot; and &quot;2-tone third order Intercept (IP3)&quot;. Running an amplifier closer to their P1dB levels results in much greater power efficiency, which motivates waveforms with reduced peak-avg ratio such as OQPSK, pi/4 QPSK, GMSK, etc. Please also see <a href="https://dsp.stackexchange.com/a/41133/21048">DSP.SE #41130</a> where I provide further examples and details of this. This also motivates significant efforts in crest factor reduction and pre-distortion for waveforms that do have very high peak-avg ratios (such as OFDM).</p> <p>To help illustrate the significance of this, below is a plot I have used to demonstrate the motivation for &quot;pulse-shaping&quot;. The blue is if we transmitted QPSK with rectangular pulses: instantly going from one point on the constellation to any other with no transition time. The red is what we get by slowly transitioning with carefully shaped pulses so that we limit the bandwidth without introducing inter-symbol interference:</p> <p><a href="https://i.sstatic.net/zsxa2.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/zsxa2.png" alt="QPSK spectrum" /></a></p> <p>If we drive that carefully shaped waveform into a non-linearity, in the worst case a hard limiter, we would return this to the rectangular pulse case and &quot;regrow&quot; the blue spectrum- hence &quot;spectral regrowth&quot;. A typical result we may see is as shown in the plot below, the growth adjacent to the spectrum limits our ability to space two channels closer together, and ultimately frequency regulatory bodies such as the US FCC will impose a spectral mask on what can be transmitted adjacent to and within assigned frequencies, and driving a PA too hard will cause the spectral mask to fail. As another consideration, that noise adjacent to the spectrum is also within the spectrum and with that degrades waveform quality (EVM).</p> <p><a href="https://i.sstatic.net/pvLt7.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/pvLt7.png" alt="Spectral regrowth" /></a></p> <p><em>Like what you see? These plots and other cool demonstrations are part of my DSP courses where I try to bring intuition together with the math involved for a deeper and more creative understanding of signal processing concepts. You can find the latest course listings at <a href="https://dsprelated.com/courses" rel="nofollow noreferrer">https://dsprelated.com/courses</a> and <a href="https://ieeeboston.org/courses/" rel="nofollow noreferrer">https://ieeeboston.org/courses/</a> Course registration is open now for courses starting very soon!</em></p>
https://dsp.stackexchange.com/questions/93604/whats-wrong-with-180-degree-phase-shift-in-qpsk
Question: <p>What are Method to phase shift 50 Hz digital signal using microcontroller. Appart from storage of samples to array and shift sample wise,how to shift this signal fractionally.</p> Answer: <p>You do it by creating a windowed sinc filter that has a wide enough pass-band to preserve the energy of whatever it is you are trying to phase shift. Instead of centering the sinc function, though, you shift it by whatever phase shift you want to introduce. You then filter the signal, which will now have that phase shift.</p> <p>As Jason states in his comment, what we really want is a time delay, which means convolving with an impulse. The problem is that you can only do delays that are an integer multiple of the sample period with this technique. We get around that by creating a low-pass filter in the form of a windowed sinc. This is effectively the same as an impulse in terms of faithfully reproducing the signal-of-interest as long as the energy of the SOI is within the pass-band of the LPF. We then convolve the LPF with a fractionally delayed impulse. We do this by calculating the values of the underlying sinc function at those shifted time points. </p> <p>Because convolution is a linear operation convolving your signal with the shifted sinc is equivalent to convolving the signal with a fractionally shifted impulse function and then convolving it with a LPF.</p>
https://dsp.stackexchange.com/questions/4709/phase-shifting-of-50hz-signal
Question: <p>I am aware of the fact that a time shift of say <span class="math-container">$t_0$</span>, results in a phase shift in the frequency spectrum. What confuses me is how this scales the rotational part of the transform by <span class="math-container">$t_0$</span> and doesn’t add a factor of <span class="math-container">$t_0$</span>.</p> <p>For example, <span class="math-container">$FT(x(t-t_0))=X(j\omega)e^{-j\omega t_0}$</span></p> <p>I understand the magnitude isn’t changed, but how is this a phase <em>shift</em>? This results in <span class="math-container">$cos(\omega t_0)+jsin(\omega t_0)$</span>, but to my understanding this is not a shift, but a scaling of the frequency. A shift would be <span class="math-container">$cos(\omega+t_0)+jsin(\omega+t_0)$</span>.</p> <p>I probably have a misunderstanding with complex exponential, but the lack of info on this is keeping me up at night.</p> Answer: <p>Consider first that in the time domain that a phase rotation or shift in phase or phase shift specifically is done by multiplying the waveform with <span class="math-container">$e^{j\phi}$</span> which rotates or shifts the complex phase for each sample in time by <span class="math-container">$\phi$</span>. Realize that <span class="math-container">$e^{j\phi}$</span> is a complex phasor of magnitude <span class="math-container">$1$</span> and angle <span class="math-container">$\phi$</span>. In contrast a time delay is given as <span class="math-container">$x(t-t_o)$</span> as the OP has indicated.</p> <p>This is no different in the frequency domain where we have a complex waveform just the same but with a different independent variable (frequency instead of time). Similarly we can multiply the frequency domain waveform by the <span class="math-container">$e^{jt_o \omega}$</span> which for a given sample at frequency <span class="math-container">$\omega$</span> will cause a constant phase rotation of that sample.</p> <p>In the frequency domain <span class="math-container">$e^{jt_o \omega} = cos(t_o \omega) + jsin(t_o \omega)$</span> is a constant phase shift of <span class="math-container">$t_o \omega$</span> for each sample given by <span class="math-container">$\omega$</span> and is not a scaling of frequency as the OP suspects since we are in the frequency domain (in the time domain a scaling of frequency would be of similar form given as <span class="math-container">$y(t) = cos((\omega t_o) t)$</span> but that is not what is occuring here since we have <span class="math-container">$Y(j\omega) = X(j\omega)e^{-j\omega t_o}$</span>. </p> <p>Consider a very simple case of <span class="math-container">$X(j\omega_1) = Ae^{j\phi_1}$</span>, which means that the magnitude of frequency <span class="math-container">$\omega_1$</span> is <span class="math-container">$A$</span> and the phase of this frequency is <span class="math-container">$\phi_1$</span>. After the time delay given by <span class="math-container">$x(t-t_o)$</span> the result would be:</p> <p><span class="math-container">$$Ae^{j\phi_1} e^{-j\omega_1 t_o} = Ae^{j(\phi_1-\omega_1 t_o)}$$</span></p> <p>Where <span class="math-container">$\omega_1 t_o$</span> represents a constant phase shift or rotation.</p>
https://dsp.stackexchange.com/questions/65891/how-does-a-shift-in-time-domain-result-in-phase-shift-in-frequency-spectrum
Question: <p>I'm using Octave and trying to use the "instfreq" function from the <a href="http://tftb.nongnu.org/" rel="nofollow">time frequency toolbox</a> which requires an analytic signal input. To get this analytic signal I'm using the Octave function "hilbert" on my real valued signal thus:</p> <pre><code>analytic_sig = hilbert( my_real_valued_signal ) ; [ instf, t ] = instfreq( analytic_signal ) ; </code></pre> <p>where instf is the instantaneous frequency I'm trying to obtain. However, the results are not quite what I expected. I suspect that the 90 degree phase shift induced by the hilbert transform is where the problem lies, so my question is how can I alter the output of the Octave "hilbert" function to compensate/adjust for this phase shift?</p> <p><strong>Edit</strong> in response to comments</p> <p>With a simple test case I'm creating a signal x with instantaneous frequency ifl</p> <pre><code>octave:1&gt; [x ifl] = fmlin(10,0.05,0.35) x = -0.97815 - 0.20791i -0.80902 - 0.58779i -0.30902 - 0.95106i 0.50000 - 0.86603i 1.00000 + 0.00000i 0.30902 + 0.95106i -0.91355 + 0.40674i -0.30902 - 0.95106i 1.00000 - 0.00000i -0.50000 + 0.86603i ifl = 0.050000 0.083333 0.116667 0.150000 0.183333 0.216667 0.250000 0.283333 0.316667 0.350000 </code></pre> <p>but in my envisioned real life application I will only have data for the real component</p> <pre><code>octave:2&gt; real_sig = real(x) real_sig = -0.97815 -0.80902 -0.30902 0.50000 1.00000 0.30902 -0.91355 -0.30902 1.00000 -0.50000 </code></pre> <p>using the hilbert function I create an analytic signal from my available real data</p> <pre><code>octave:3&gt; anal_sig = hilbert( real_sig ) anal_sig = -0.97815 + 0.07265i -0.80902 - 0.41187i -0.30902 - 0.92331i 0.50000 - 0.81514i 1.00000 + 0.04490i 0.30902 + 0.98765i -0.91355 + 0.52573i -0.30902 - 0.89042i 1.00000 + 0.28002i -0.50000 + 1.12978i </code></pre> <p>and when this is put in to the instfreq function I get the measured instantaneous frequency instf</p> <pre><code>octave:4&gt; instf = instfreq( anal_sig ) instf = 0.10520 0.13131 0.15427 0.18209 0.20487 0.24755 0.31328 0.30974 </code></pre> <p>The instfreq function returns values in the range [2:end-1] of its input, so padding to make an easy comparison</p> <pre><code>octave:5&gt; [ ifl [ 0 ; instf ; 0 ] ] ans = 0.05000 0.00000 0.08333 0.10520 0.11667 0.13131 0.15000 0.15427 0.18333 0.18209 0.21667 0.20487 0.25000 0.24755 0.28333 0.31328 0.31667 0.30974 0.35000 0.00000 </code></pre> <p>it can be seen that the measured frequency is different from the true, known frequency. Thinking of a phasor diagram, I was thinking that perhaps some trigonometric manipulation of the real and imaginary components of the hilbert function output might correct this. </p> Answer: <p>1) A Hilbert transform has a very very long impulse response (above some given noise floor), so you need a ton more data to manufacture an analytic signal, otherwise you won't have enough to span the width of the Hilbert impulse response filter without serious edge truncation effects.</p> <p>2) Instantaneous frequency estimates from this type of artificially approximated analytic signal can be very noisy, so often has to be low pass filtered to significantly below half your sample rate.</p>
https://dsp.stackexchange.com/questions/16507/compensate-for-phase-shift-of-hilbert-transform
Question: <p>I was wondering if there is something like a Hilbert Transform but that can implement an arbitrary phase shift to every frequency component.</p> <p>I mean, I know that the magnitude response of a &quot;Hilbert filter&quot; is 1 for all frequencies and the phase response is <span class="math-container">$-\pi/2$</span> for all positive frequencies, but I would like to obtain different phase shifts like <span class="math-container">$\pi/3, \pi/4, \ldots$</span> etc.</p> <p>Is there a transform that can accomplish that? I guess it would be something like a &quot;trascendental Hilbert Transform&quot;</p> Answer:
https://dsp.stackexchange.com/questions/72009/something-like-hilbert-transform-to-obtain-arbitrary-phase-shift
Question: <p>I have an incoming digitally sampled sine wave pulse, so my FPGA has the ADC level from an I and Q channel. I want to be able to shift the phase by some arbitrary amount. </p> <ul> <li>What's the most efficient way to do this?</li> </ul> <p>The most obvious way to shift phase would be just to multiply by $e^{i\phi}$, but that would be slow and wasteful. I've also seen someone recommend using an allpass filter with some phase shift.</p> <ul> <li>Is there any other options I should be considering? Or is the allpass filter the best way to do this?</li> </ul> Answer: <p>The allpass you're describing is a multiplication with multiple numbers. Hence, if you want to shift your phase, the only mathematically viable and easiest way is indeed a multiplication with $e^{i\phi}$.</p> <p>I don't see why that would be overly slow – in a modern FPGA, you'd probably utilize DSP slices to do the (real-valued) two multiplications and additions that make up a complex $\cdot$ complex multiplication.</p> <p>Now, if you need to increment your phase, so you need to *calculate the value of $e^{i\phi}$ first, then there might be room for optimization. In fact, digital tuning happens in FPGAs, in the DSP chains of software defined radio devices like the Ettus USRP series.</p> <p>There, a pretty standard CORDIC algorithm was employed to approximate a complex sinusoid $e^{i2\pi f}$ of arbitrary relative frequency $f$. Have a look at the USRP X3xx's GPL-licensed <a href="https://github.com/EttusResearch/fpga/blob/b108e88865ee0fa68e685461681d8ca6a320b937/usrp3/lib/dsp/ddc_chain_x300.v#L102" rel="nofollow">RX DSP DDC chain</a>:</p> <pre><code>cordic_z24 #(.bitwidth(cwidth)) cordic(.clock(clk), .reset(rst), .enable(run), .xi(to_cordic_i),. yi(to_cordic_q), .zi(phase[31:32-zwidth]), .xo(i_cordic),.yo(q_cordic),.zo() ); </code></pre> <p>The <a href="https://github.com/EttusResearch/fpga/blob/b108e88865ee0fa68e685461681d8ca6a320b937/usrp3/lib/dsp/cordic_z24.v" rel="nofollow"><code>cordic_z24</code></a> is really just a multi-<a href="https://github.com/EttusResearch/fpga/blob/b108e88865ee0fa68e685461681d8ca6a320b937/usrp3/lib/dsp/cordic_stage.v" rel="nofollow">stage</a> CORDIC implementation with pre-computed atan coefficients.</p> <p>It runs at complex 64MS/s even on 2005 Spartan FPGAs, and doesn't really blink much of an eye about 200MS/s on modern Kintex7 FPGAs. </p> <p>It avoids explicit multiplication alltogether.</p>
https://dsp.stackexchange.com/questions/31226/best-way-to-implement-variable-phase-shift-on-fpga