Function with sum of vector elements
Show older comments
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 Comment
Matt J
on 7 Feb 2019
I am trying to plot the furrier transform
Not to be confused with the fuzzier transform... ;)
Answers (1)
Star Strider
on 7 Feb 2019
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 Comments
Mathias Sven Strassburger Maluf
on 7 Feb 2019
Star Strider
on 7 Feb 2019
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.
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!