Interpolation via Zero Padding
29 次查看(过去 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")
0 个评论
采纳的回答
Sulaymon Eshkabilov
2024-1-3
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 个评论
Sulaymon Eshkabilov
2024-1-5
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
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Filter Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!