- https://www.mathworks.com/help/matlab/ref/hadamard.html
- https://www.mathworks.com/help/matlab/ref/arrayfun.html
Generation of n_th anonymouse Walsh function
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposta accettata
Suraj Kumar
il 3 Ott 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!
0 Commenti
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!