Borrar filtros
Borrar filtros

I want to use Interpole with Zero Padding

3 visualizaciones (últimos 30 días)
Zaref Li
Zaref Li el 5 de En. de 2024
Editada: Hassaan el 5 de En. de 2024
Hi everyone,
I have a signal [ cos(2*pi*0.2*n) n:0:1:15]. I want Interpolate in time domain by a factor of 5 using zero padding in frequency domain. I write this code but I am not sure that it is correct.
n = 1:15;
x = cos(2*pi*0.2*n);
N = length(x);
X = fft(x, N*5);
x_interpolated = ifft(X);
figure;
subplot(2,1,1);
stem(n, x);
title('Original Signal');
subplot(2,1,2);
stem(1:length(x_interpolated), x_interpolated);
title('Interpolated Signal');

Respuesta aceptada

Image Analyst
Image Analyst el 5 de En. de 2024
Editada: Image Analyst el 5 de En. de 2024
Why are you doing anything with fft? Just use interp1
xInterp = linspace(min(n), max(n), 5 * length(n));
x_interpolated =interp1(n, x, xInterp);
Or just change your step in your n:
n = 1 : 0.2 : 15;
x = cos(2*pi*0.2*n);

Más respuestas (1)

Hassaan
Hassaan el 5 de En. de 2024
Editada: Hassaan el 5 de En. de 2024
n = 0:15; % n should start at 0
x = cos(2*pi*0.2*n);
N = length(x);
% Define the half_N variable correctly
half_N = ceil((N+1)/2);
% FFT of the original signal
X = fft(x);
% Zero-padding should be done by adding zeros in the middle of the array, not at the end
% to maintain the Hermitian symmetry of the FFT for a real signal.
X_padded = [X(1:half_N), zeros(1, (N*5)-(N)), X(half_N+1:end)];
% To maintain symmetry, ensure that the number of zeros padded is even
% This can be done by appending an extra zero if the number of points to pad is odd
num_zeros = N*5 - N;
if mod(num_zeros, 2) ~= 0
X_padded = [X(1:half_N), zeros(1, num_zeros+1), X(half_N+1:end)];
end
% IFFT to get the interpolated signal
x_interpolated = ifft(X_padded, 'symmetric'); % Use 'symmetric' to ensure the output is real
% Time vector for the interpolated signal
n_interpolated = linspace(0, max(n), length(x_interpolated));
figure;
subplot(2,1,1);
stem(n, x);
title('Original Signal');
subplot(2,1,2);
stem(n_interpolated, x_interpolated);
title('Interpolated Signal');
------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering

Community Treasure Hunt

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

Start Hunting!

Translated by