How can I add two fft functions?
Show older comments
I want to convert 2 sine functions of time to functions of frequency using fourier transform and then I tried adding 2 of the fft functions I got and it is showing error. d=zabs+xabs is showing error.
A=1;
t=0:0.001:0.1;
x=A*sin(2*pi*1046*t);
xft=fft(x,1046);
xabs=abs(xft);
A=1;
t=0:0.0001:0.01;
z=A*sin(2*pi*523*t);
zft=fft(z,523);
zabs=abs(zft);
d=zabs+xabs;
subplot(211);
plot(d);
Accepted Answer
More Answers (1)
Star Strider
on 18 Jan 2024
Edited: Star Strider
on 18 Jan 2024
1 vote
It is obvious from looking at the code that the fft results have different lengths, specifically 523 and 1046 elements in each. In order to add them, they have to have the same numbers of elements.
The solution is to have the same fft lengths in both ‘zabs’ and ‘xabs’. Ideally, they should also have the same frequencies at the same locations in the frequency vector (that you will need to code separately). The fft documentation has examples that illustrate that process for one-sided and two-sided fft results.
EDIT — Corrected typographical errors.
.
Categories
Find more on Fourier Analysis and Filtering 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!