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 个评论

I am trying to plot the furrier transform
Not to be confused with the fuzzier transform... ;)

请先登录,再进行评论。

回答(1 个)

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 个评论

But that wouldnt work for me
I basiclly need this
B and A have already the same dimansion, 1x800 double, f cant have the same dimansion, f is just one value that I will use to plot( A[n] , f ). Is there any other way to make this work?
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 的更多信息

产品

版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by