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!