Function with sum of vector elements
显示 更早的评论
Hi, so I am trying to plot the furrier transform of a set of data. A is a row vector with:
A = [0.0001:0.0001:0.08]
And B is the row vector with the Y values for the sound wave, with the same dimension so that a function g can be defined as mapping from every nth element of A to every nth element of B
The function that I came up to give me the furrier transform was:
function [ f_intensity ] = FT_g( f )
f_intensity = sum(B.*exp(-2*pi*1i*f.*A));
end
Both A and B are in my workspace but it keeps saying that the variable B is undefined.
>> FT_g(1)
Undefined function or variable 'B'.
Error in FT_g (line 3)
f_intensity = sum(B.*exp(-2*pi*1i*f.*A));
Anyone has any idea how I could solve this?
1 个评论
Matt J
2019-2-7
I am trying to plot the furrier transform
Not to be confused with the fuzzier transform... ;)
回答(1 个)
Star Strider
2019-2-7
You need to pass ‘A’ and ‘B’ as arguments to your funciton:
function [ f_intensity ] = FT_g( f, A, B )
Then call it the same way.
Note that ‘A’, ‘B’, and ‘f’ all have to have the same dimensions.
2 个评论
Mathias Sven Strassburger Maluf
2019-2-7
Star Strider
2019-2-7
If ‘f’ is one frequency, I would do something like this:
A = [0.0001:0.0001:0.08];
B = sin((0 : 50 : 150)'*A); % Create ‘B’
f = 10;
f_intensity = @(f,A,B) sum(B.*exp(-2*pi*1i*f.*A));
figure
plot(A, abs(f_intensity(f,A,B)))
grid
See if that does what you want.
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!