Interpolation via Zero Padding
29 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Zaref Li
le 3 Jan 2024
Commenté : Sulaymon Eshkabilov
le 5 Jan 2024
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 commentaires
Réponse acceptée
Sulaymon Eshkabilov
le 3 Jan 2024
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 commentaires
Sulaymon Eshkabilov
le 5 Jan 2024
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
Plus de réponses (1)
Balaji
le 3 Jan 2024
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 commentaires
Voir également
Catégories
En savoir plus sur Filter Analysis dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!