Discrete cosine transform for unevenly spaced sample points

8 Ansichten (letzte 30 Tage)
Mario Basallo
Mario Basallo am 18 Jun. 2024
Kommentiert: Mario Basallo am 18 Jun. 2024
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

Antworten (1)

Hassaan
Hassaan am 18 Jun. 2024
Bearbeitet: Hassaan am 18 Jun. 2024
% 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)]);
Reconstruction error: 4.4061e-16
% 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;
  2 Kommentare
Mario Basallo
Mario Basallo am 18 Jun. 2024
Thank you Hassan!
Regarding the code you submitted, how can I reconstruct the original non-uniform data?
Also, you are using interpolated data and the standard dicrete cosine transform applied to the uniform points obtained from the interpolation. I wonder if there is a way to obtain the discrete cosine transform directly from the non-uniform sample points.
Regards,
Mario
Mario Basallo
Mario Basallo am 18 Jun. 2024
Thank you for extending your answer Hassaan!
Your code relies on the computation of an spline interpolation for reconstructing the original non-uniform data. Unfortunately, the computation of an spline interpolation would not be possible in the context I am dealing with.
In my case, I would like to reconstruct the data directly from the Fourier series expansion, i.e., use a function involving the summation of cosine terms to reconstruct the data instead of relying on an spline interpolation to do so. I wonder if it is possible to obtain such function of cosine terms to get the reconstruction.
Regards,
Mario

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Interpolation finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by