Generation of n_th anonymouse Walsh function

6 vues (au cours des 30 derniers jours)
Andrei
Andrei le 27 Oct 2023
I need Walsh functions for fourier approximation of some test function (let it be sinx on interval from -pi to pi). So I need to find n_th Walsh function as a function of x to use in integral for coefficients. Here is my try (I tried to use haddamar matrices)
function y = wal(x,n)
N = 2^n;
H = hadamard(N);
id = fix(x*N -1e-9) + 1;
y = H(N,id);
end
But here is my problem, first of all these functions are not correct. Secondly, they are defined only on (0,1) interval, and I don't know how to generalise in on [-pi,pi]. Thirdly input x is an array, and I need to make anonymous func @(x), but then my id is undefined and function is not working at all

Réponse acceptée

Suraj Kumar
Suraj Kumar le 3 Oct 2024
Hi Andrei,
To generate the nth Walsh function in MATLAB, you can refer to the following steps and the attached code snippets:
1. To use Walsh functions over the interval [-π, π], you can map this interval to the interval [0,1].
% Map x from [-pi, pi] to [0, 1]
x_mapped = (x + pi) / (2 * pi);
2. Ensure the Hadamard matrix is of appropriate size to compute the Walsh function correctly by using ‘nextpow2’ function.You can refer the following documentations for more information:
N = 2^nextpow2(n);
H = hadamard(N);
3. Use arrayfun function to compute the Walsh function for each element in the array and calculate the index in the Hadamard matrix ensuring it is within the bounds.
walshFunc = @(x) arrayfun(@(xi) computeWalsh(xi, n, H, N), x);
id = fix(x_mapped * N - 1e-9) + 1;
if id > N
id = N;
elseif id < 1
id = 1;
end
For more information on ‘hadamard’ or ‘arrayfun function in MATLAB, kindly go through the following links:
Hope this helps!

Plus de réponses (0)

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by