Discrete cosine transform for unevenly spaced sample points
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
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)]);
% 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
Siehe auch
Kategorien
Mehr zu Interpolation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!