I am trying to understand the zero-padding in frequency domain and discovered that original sequence in interpolated data only when (N/M) = integer where N and M are the lengths of output and input.
clear all;
close all;
M = 9;
N = 18;
m_p = (M - 1) / 2;
x1 = [2 4 5 2 1 3 1 7 9];
y1 = fft(x1);
y2 = (N/M) * [y1(1:m_p+1) zeros(1, N-M) y1(m_p+2:M)];
z_c = N - M;
z_f = 1 + (z_c-1) / 2
z_b = z_f - 1;
y3 = (N/M) * [zeros(1, z_f) (y1(m_p+2:M)) y1(1:m_p+1) zeros(1,z_b)]
x2 = ifft(y2, N)
x3 = ifft(y3, N)
Also, why zero-padding at the ends of the spectrum gives negatives values of interpolated data and positive of original sequence?
x2 =
2.0000 + 0i
2.1303 + 0.0000i
4.0000 - 0.0000i
5.2490 + 0i
5.0000 + 0i
3.6885 - 0.0000i
2.0000 + 0i
0.8029 - 0.0000i
1.0000 + 0.0000i
2.3184 + 0i
3.0000 - 0.0000i
1.9939 + 0.0000i
1.0000 + 0i
2.7335 - 0.0000i
7.0000 - 0.0000i
10.0992 + 0i
9.0000 + 0.0000i
4.9842 + 0.0000i
x3 =
2.0000 + 0i
-2.1303 - 0.0000i
4.0000 - 0.0000i
-5.2490 + 0i
5.0000 + 0i
-3.6885 + 0.0000i
2.0000 + 0i
-0.8029 + 0.0000i
1.0000 + 0.0000i
-2.3184 + 0i
3.0000 - 0.0000i
-1.9939 - 0.0000i
1.0000 + 0i
-2.7335 + 0.0000i
7.0000 - 0.0000i
-10.0992 + 0i
9.0000 + 0.0000i
-4.9842 - 0.0000i