Interpolation via Zero Padding

26 次查看(过去 30 天)
Hello everyone,
Below is the interpolation code with zero padding. But I want to make some changes to this code. I want to interpolate by a factor of 5 in the time domain using the following. Which factor component should I change here? Can you help me?
N = 30;
x = (0:N-1)/N;
Ni = 300;
xi = (0:Ni-1)/Ni;
f = exp.(sin.(2*pi*x));
ft = fftshift(fft(f))
Npad = floor(Int64, Ni/2 - N/2)
ft_pad = [zeros(Npad); ft; zeros(Npad)];
f_interp = real(ifft( fftshift(ft_pad) )) *Ni/N ;
plot(x,f, label="Original samples",markershape=:circle)
plot!(xi,f_interp,label="Interpolated values")

采纳的回答

Sulaymon Eshkabilov
Is this what you are trying to get:
N = 30;
x = (0:N-1)/N;
Ni = 5 * N; % By a factor "5"
xi = (0:Ni-1)/Ni;
f = exp(sin(2*pi*x));
ft = fftshift(fft(f));
Npad = floor((Ni/2 - N/2));
ft_pad = [zeros(1, Npad), ft, zeros(1, Npad)];
f_interp = real(ifft(fftshift(ft_pad))) * Ni / N;
plot(x, f, 'ro', 'MarkerFaceColor', 'y', 'DisplayName',"Original samples"), hold on
plot(xi, f_interp, 'b-', 'LineWidth',2, 'DisplayName',"Interpolated values")
legend('show')
xlabel('x')
ylabel('f(x)')
grid on
  2 个评论
Zaref Li
Zaref Li 2024-1-5
Thank you for your help. Can I ask a question? If we want to change the signal with cos(2*pi*0.2*n) n:0:1:15. Where do I need to make a change?
Sulaymon Eshkabilov
It would be something like this one:
N = 16;
x = (0:N-1)/N;
Ni = 5*N; % By a factor "5"
xi = (0:Ni-1)/Ni;
f = exp(cos(2*pi*0.2*x));
ft = fftshift(fft(f));
Npad = floor((Ni/2 - N/2));
ft_pad = [zeros(1, Npad), ft, zeros(1, Npad)];
f_interp = real(ifft(fftshift(ft_pad))) * Ni / N;
plot(x, f, 'ro', 'MarkerFaceColor', 'y', 'DisplayName',"Original samples"), hold on
plot(xi, f_interp, 'b-', 'LineWidth',2, 'DisplayName',"Interpolated values")
legend('show', 'Location', 'Best')
xlabel('x')
ylabel('f(x)')
grid on

请先登录,再进行评论。

更多回答(1 个)

Balaji
Balaji 2024-1-3
Hi Zaref
To interpolate by 'interpolate_size=5' you can assign
Ni = N*interpolate_size
You can modify your code as below:
N = 30;
x = (0:N-1)/N;
interpolate_size = 5;
Ni = N*interpolate_size;
xi = (0:Ni-1)/Ni;
f = exp(sin(2*pi*x));
ft = fftshift(fft(f));
Npad = floor(Ni/2 - N/2);
ft_pad = [zeros(1, Npad) ft zeros(1, Npad)];
f_interp = real(ifft( fftshift(ft_pad) ))*Ni/N ;
figure(1)
stem(x,f)
figure(2)
stem(xi,f_interp)
Hope this helps
Balaji

类别

Help CenterFile Exchange 中查找有关 Multirate Signal Processing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by