1
$\begingroup$

The setup is the following:

I am using a RedPitaya board to measure the phase shift of two input signals. These input signals will sweep logarithmically from 1kHz to 100 kHz in 10 seconds.

Currently, I am using 512 samples of the input signals which then get zero-padded until they reach a size of 1024 in order to perform the correlation using FFT. The sample frequency is 488.281 kHz (can get up to 125 MHz) in order to ensure that an entire period worth of data from the lowest input signal frequency gets sampled. My code works and accurately measures the phase for an input signal of 1 kHz.

Currently, I want to calculate the cross correlation and thereafter the phase for all of the input frequencies using only one set sample frequency. Once the input signals start rising in frequency, the measurement will obviously decrease in resolution/accuracy. If the decrease in accuracy is to much I might have to change my approach here. My problem is that I do not know how to calculate the Resolution for higher frequencies, or any frequency really.

How can I calculate the loss of accuracy for higher frequencies?

My trial and error approach in MATLAB has told me that I need quite significant oversampling in order to correctly measure the phase shift using cross Correlation, but I do not really understand why.

Code can be provided if needed (pure C with RedPitaya specific Header for I/O-control).

$\endgroup$
4
  • 1
    $\begingroup$ 512 is already a power of 2 – no advantage computationally to zero pad to 1024 for an FFT. Or are you doing this to gain resolution? $\endgroup$ Commented Mar 1, 2022 at 10:06
  • $\begingroup$ Im zero padding to 1024 because the cross Correlation of two signals is 2*signalsize-1. im performing fft of both signals, then conjugating signal 2 and multiplying them. The Result of the multiplication gets ifft'd. So i do need 1024 size arrays. $\endgroup$ Commented Mar 1, 2022 at 10:15
  • $\begingroup$ I believe Marcus Müller is asking due to the fact that you can calculate the Cross Correlation function for specific lags with the following formula, without the need to zero-pad $$ r (\tau) = \mathcal{R} \left\{ \mathbf{R}_{xy} e^{-2 \pi j f \tau} \right\} $$ $\endgroup$
    – ZaellixA
    Commented Mar 1, 2022 at 10:42
  • $\begingroup$ (continued) where $\mathcal{R}$ denotes the real part, $\mathbf{R}_{xy}$ the cross spectrum (I have dropped the frequency dependence for clarity), $f$ is the temporal frequency and $\tau$ the lag. $\endgroup$
    – ZaellixA
    Commented Mar 1, 2022 at 10:48

1 Answer 1

1
$\begingroup$

I assume you have situation where you have two input signals that are derived from the same sweep but through different channels, i.e.

$$X_1(\omega) = H_1(\omega) \cdot S(\omega) \\ X_2(\omega) = H_2(\omega) \cdot S(\omega) $$

and you want to determine the phase difference

$$\phi(\omega) = \angle H_2(\omega) - \angle H_1(\omega) $$

The accuracy with which you can do this will depend a lot on how this phase differences are created on the first place. Let's look at a simple example of a straight path and a delayed path, i.e. $H_1(\omega) = 1$ and $H_2(\omega) = e^{-j\omega \tau}$ where $\tau$ is the delay.

Your analysis window is very short: $t_A = 512/488281Hz \approx 1ms$. If the channel delay is on the order or larger than 1ms, your method will work only poorly or not at all:, the frames of the input won't event contain the same frequencies.

The most straight forward way would be to capture both signals completely, Fourier Transform them and subtract the phases (of the frequencies that have good enough SNR). This will require a fair bit of memory and CPU, but if you have the resources, it's pretty much "foolproof".

If you have limited resources, the best method will depend a lot on the nature of the phase differences. I would start trying to estimate the maximum group delay of the inter-channel transfer function and choose a frame size of at least 2 or 3 times that much. It may also be a good idea to use an analysis window (Hanning for example) and overlap the frames by 50%.

The excitation signal (sweep) should match the shape of the inter-channel phase. If the phase is inherently logarithmic (like a lowpass or bandpass filter), use a log sweep, if it's more linear (like a delay), a linear sweep would work better.

$\endgroup$
4
  • $\begingroup$ Thank you very much for your answer. I should have specified that the input signal is a sine wave. This wave enters the device in one channel unchanged. The other channel receives the same sine wave, but not before it has gone through a filter (either active or passive). Basically im Trying to record the phase response of several filters. Capturing the signals completely is not necesarry (i think) as they are sinusoidal and therefore repeat after every period. I am indeed limited in resources because its a small board. I cannot use windowing as I do not have a dedicated fft library. $\endgroup$ Commented Mar 1, 2022 at 10:53
  • $\begingroup$ Are you using an actual sweep or stepped sine waves ? This sounds like a standard transfer function measurement problem. There are plenty of methods on how to do this: cross correlation is not necessarily a good choice here, but that depends somewhat and the properties of the filters you want to measure $\endgroup$
    – Hilmar
    Commented Mar 1, 2022 at 13:01
  • $\begingroup$ There will be an actual sweep generator that generates the signal. However there will be several different filters, of which the phase response is required. My professor said that cross correlation is good because noise doesn't matter and I should use cross correlation. Is dividing 360 by the number of points per period a naiv approach for calculating the accuracy of the measurement? $\endgroup$ Commented Mar 1, 2022 at 13:28
  • $\begingroup$ Yes, I'm afraid that's a naïve approach. I gave you an example where your current approach won't work at all. Without narrowing down a little bit of what the filters do, it's hard to give advice $\endgroup$
    – Hilmar
    Commented Mar 1, 2022 at 16:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.