Generation of n_th anonymouse Walsh function

조회 수: 6 (최근 30일)
Andrei
Andrei 2023년 10월 27일
답변: Suraj Kumar 2024년 10월 3일
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

채택된 답변

Suraj Kumar
Suraj Kumar 2024년 10월 3일
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개)

카테고리

Help CenterFile Exchange에서 Hilbert and Walsh-Hadamard Transforms에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by