Clear Filters
Clear Filters

How to create 2D DFT matrix image from the given DFT formula?

5 views (last 30 days)
I want to create a matrix e(m,n) from a 2D DFT expression. Discrete cosine transform has only cosine terms. and one more factor. e(m,n)= sigma(p from 1 to L/2) sigma(q from 1 to L/2)(1/k^a)cos(2pi.m.p/L+rand(0,2*pi).cos(2pi.n.q/L+rand(0,2*pi)) How to create the points(matrix)e(m,n) for above expression for different a values( it means that a is variable too). m and n vary from 1 to L.

Answers (1)

Balavignesh
Balavignesh on 3 Jul 2024 at 5:50
Hi Vibha,
As per my understanding, you would like to create a matrix e(m,n) from a 2D DFT expression. I assumed 'a' to be a variable, and 'm' and 'n' vary from 1 to 'L'. A cell array 'e_matrices' is initialized to store the result matrices for different 'a' values. The matrices are displayed using 'imagesc' along with colorbars and titles indicating the corresponding 'a' values.
% Parameters
L = 10; % Define L (can be any positive integer)
a_values = [0.5, 1, 1.5]; % Example values for a (can be any array of positive values)
% Initialize the result matrices for different 'a' values
e_matrices = cell(length(a_values), 1);
% Loop over each value of 'a'
for idx = 1:length(a_values)
a = a_values(idx);
e = zeros(L, L); % Initialize the matrix e(m,n)
% Nested loops to compute e(m,n)
for m = 1:L
for n = 1:L
sum_value = 0;
for p = 1:L/2
for q = 1:L/2
k = sqrt(p^2 + q^2); % Compute k
term1 = cos(2*pi*m*p/L + rand*2*pi);
term2 = cos(2*pi*n*q/L + rand*2*pi);
sum_value = sum_value + (1/k^a) * term1 * term2;
end
end
e(m,n) = sum_value;
end
end
% Store the result matrix for the current 'a' value
e_matrices{idx} = e;
end
% Display the results
for idx = 1:length(a_values)
a = a_values(idx);
figure;
imagesc(e_matrices{idx});
colorbar;
title(['Matrix e(m,n) for a = ', num2str(a)]);
xlabel('n');
ylabel('m');
end
Feel free to modify the parameters and 'a_values' array as needed for your specific application.
Hope that helps!
Balavignesh

Community Treasure Hunt

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

Start Hunting!