signal processing - Wave interference: adding two waves with opposite phases + using FFT - MATLAB problems -
i have 2 main questions, starting beginning: wanted know how fft (fast fourier transform) works on real examples. created 2 sinusoidal waves (for example wave1 = 5 hz , wave2 = 15 hz amplitude), added 2 , made fft third "wave3". looks ok - saw "peaks" around 5 , 15 hz.
blue = 5 hz, red = 15 hz, yellow = blue + red. fft "yellow" wave, looks good:
ok, , have changed data. have 2 waves identical amplitudes opposite phases. if add them, amplitude 0 - , seems correct me.
two waves opposite phases. yellow - wave1+wave2 + strange fft of yellow wave:
and part don't understand @ all. here questions:
1) if see on picture third yellow wave has amplitude equal 0, it's not in data tables. after adding 2 main waves (and have opposite data!) strange result.
example: 5 first points in data
wave 1:
- 0,0627905195293128
- 0,125333233564304
- 0,187381314585724
- 0,248689887164855
- 0,309016994374947
wave 2:
- -0,0627905195293134
- -0,125333233564304
- -0,187381314585724
- -0,248689887164855
- -0,309016994374947
wave 3 (sum) :
- -5,68989300120393e-16
- -1,11022302462516e-16
- -1,11022302462516e-16
- 3,05311331771918e-16
- -1,11022302462516e-16
why sum of these waves not equal 0, shown in picture? why fft looks strange? there possibility fft show real amplitudes of 2 identical waves opposite phases? thought not, what's truth?
here matlab code:
three waves:
d = 1; % 1 second s = 1000; % sampling rate p = 0.5; % phase t = 1/s; % sampling period t = [t:t:d]; % time myphi=2*pi*p; myphi2=2*pi*1; syn3 = sin(2*10*t*pi+myphi); % first wave syn2 = sin(2*10*t*pi+myphi2); % second wave sinmax=syn2+syn3; % yellow wave figure; plot(t,syn3,t,syn2,t,sinmax,'linewidth',2); grid on; xlabel('time (seconds)'); ylabel('amplitude');
fft code:
l = length(sinmax); myfft = fft(sinmax,s); myfft=myfft/l; %scale output 1 freq = s/2*linspace(0,1,s/2); figure; stem(freq,abs(myfft(1:length(freq)))); xlabel('frequency (hz)'); ylabel('amplitude');
thank in advance...
mary
first things first, calculations correct.
because 2 graphs auto-resized, easy make mistake interpreting them amplitudes way smaller on 2nd 1 1st (10e-16 vs. 10e1
, respectively).
on 2nd graph, 1 leaves puzzled, you victim of numerical errors : these numbers can interpreted 0
.
from there, have 2 simple solutions :
- you fine results have, , can tweak figures display results on same scale avoid misleading interpretation
- you have "proper 0 values" instead of "small ones"
1) set limit y-axis
you can add line (it example - change meet needs) when plotting figures :
ymax = max(abs(my_fft)); ymin = - ymax; ylim([ymin ymax])
2) set limit filtering numerical errors
like in lot of numerical methods algorithms, might want consider 0
values in between 0
, small interval, called epsilon
:
abs_fft = abs(my_fft); epsilon = 10e-12 % threshold abs_fft(abs_fft < epsilon) = 0;
you might want check out eps
built-in matlab variable, meant kind of cases.
Comments
Post a Comment