# What happens to the phase spectrum when I resample?

[An update is added at the end of the post after receiving first response]

I have an algorithm which is very sensitive to phase shifts. It works with signal sampled at 40MHz (it's a neural network so actually the sampling rate is not very flexible)

I have a data sampled at 21.818e6 MHz and I resample it to ~40 MHz by:

sample_cnt = len(test_data)
Fs_org = 21.818e6
Fr = 40e6
resam_cnt = np.floor(Fr * sample_cnt / Fs_org)
test_data_re = scipy.signal.resample(test_data, resam_cnt.astype(int), axis=0)


test_data is sensor data with 1704 sample numbers so (1704,1).

When I look at frequency spectrum and phase response of the resampled data the frequency spectrum matches original signal (it's a bandpass signal with center frequency of 5MHz) but phase response for higher frequencies is flat (see image).

pyolt.figure()
pyplt.phase_spectrum(test_data_re, Fr, fc=5e6)
pyplt.phase_spectrum(test_data, Fs_org, fc=5e6)


Blue line is corresponded to the phase response of resampled data and orange line is corresponded to original data which is overlapped on the resampled data.

1- Is this resampling correct?

2- Is there a solution to create any kind of corresponding phase information for higher frequencies?

[Update]

I resampled same data with Matlab:

resample(test_data,2,1)


Then saved the data, loaded in python and compared two resampled signal (see image)

The blue one is the python resampled data and the orange one is the matlab resampled data

I do agree with @Hilmar that "When you re-sample you extend the frequency range, but the energy at these new frequencies (between 11 MHz and 20 MHz) is close to or exactly zero. That's the whole point of a "good" interpolation: make sure you don't add stuff that wasn't there before.

That means the phase at the new frequencies is either undefined or doesn't really matter since there is no relevant energy. If the magnitude is zero, it doesn't matter what the phase is"

Now it rises this question that how come Matlab is creating phase information in those frequencies?

1- Is this resampling correct?

No. Resampling is almost never 100% correct but it usually requires a complicated trade off between different artifacts and properties: passband extension and flatness, stop-band attenuation and size, aliasing rejection, phase distortion, onset & transient preservation, causality, CPU and memory requirements etc.

Which trade off is the best, depends a lot on the requirements of your specific application.

2- Is there a solution to create any kind of corresponding phase information for higher frequencies?

Why would you need that? Your original signal cannot contain any energy at frequencies equal or above the original Nyquist frequency. When you re-sample you extend the frequency range, but the energy at these new frequencies (between 11 MHz and 20 MHz) is close to or exactly zero. That's the whole point of a "good" interpolation: make sure you don't add stuff that wasn't there before.

That means the phase at the new frequencies is either undefined or doesn't really matter since there is no relevant energy. If the magnitude is zero, it doesn't matter what the phase is.

• Thanks for your response, I need phase information because the data that I used for training, however is bandpass but has phase information (now I am wondering why!!) in higher frequencies which then in absence of that information the solution will not be applicable for data sampled at lower frequencies. Dec 8 '20 at 17:22
• I updated the question with a resampling from Matlab too, now I am confused what is happening in Matlab and how phase information is created? Dec 8 '20 at 18:10