Discrete cosine transform for unevenly spaced sample points
8 次查看(过去 30 天)
显示 更早的评论
Hello
My name is Mario. I am working on a problem that requires the computation of the discrete cosine transform (DCT) and its inverse in two or more dimensions. However, I am dealing with a situation where the sample points are not evenly (nonuniformly) spaced, unlike in the usual computation of the classical DCT. I am not sure how to perform these computations in Matlab. I know that Matlab has some functions for this in the case of the Fourier transform; however, my application requires the use of a discrete cosine transform. I would appreciate it if you could provide me with any information or suggestions regarding this.
Thank you!
Regards,
Mario
0 个评论
回答(1 个)
Hassaan
2024-6-18
编辑:Hassaan
2024-6-18
% Non-uniformly spaced sample points and corresponding data values
x_nonuniform = sort(rand(1, 10) * 10); % Non-uniformly spaced sample points
y_values = sin(x_nonuniform); % Data values at these non-uniform points
% Defining a uniform grid over the range of non-uniform data
x_uniform = linspace(min(x_nonuniform), max(x_nonuniform), length(x_nonuniform));
% Interpolating non-uniform data to a uniform grid
y_uniform = interp1(x_nonuniform, y_values, x_uniform, 'spline');
% Applying DCT on uniformly spaced data
Y_dct = dct(y_uniform);
% Computing the inverse DCT
y_reconstructed = idct(Y_dct);
% Plotting original non-uniform data, interpolated uniform data, and reconstructed data
figure;
plot(x_nonuniform, y_values, 'ro', 'DisplayName', 'Original Non-Uniform Data');
hold on;
plot(x_uniform, y_uniform, 'bo-', 'DisplayName', 'Interpolated Uniform Data');
plot(x_uniform, y_reconstructed, 'gx-', 'DisplayName', 'Reconstructed Data after Inverse DCT');
legend show;
xlabel('Sample Points (x)');
ylabel('Data Values (y)');
title('DCT and Inverse DCT on Interpolated Uniform Data');
grid on;
% Compare the interpolated and reconstructed values for error analysis
error = norm(y_uniform - y_reconstructed);
disp(['Reconstruction error: ', num2str(error)]);
% Computing inverse DCT to get reconstructed data on the uniform grid
y_reconstructed_uniform = idct(Y_dct);
% Reverse interpolating from the uniform grid back to the original non-uniform points
y_reconstructed_nonuniform = interp1(x_uniform, y_reconstructed_uniform, x_nonuniform, 'spline');
% Plot to compare original and reconstructed non-uniform data
figure;
plot(x_nonuniform, y_values, 'ro', 'DisplayName', 'Original Non-Uniform Data');
hold on;
plot(x_nonuniform, y_reconstructed_nonuniform, 'bx', 'DisplayName', 'Reconstructed Non-Uniform Data');
legend show;
xlabel('Sample Points (x)');
ylabel('Data Values (y)');
title('Comparison of Original and Reconstructed Non-Uniform Data');
grid on;
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!