Sum of signals and filter the sum and recuperate the inicial frequencies

Hello, I am new to matlab,
I would like to generate two diffrent sinus signal with diffrent frequencies f1 and f2. One generated I want to do the sum of them (let's call it totalSignal) . Next, I want t filter the total signal and recuperate f1 and f2.
Any body can help me?

 Akzeptierte Antwort

Jakob B. Nielsen
Jakob B. Nielsen am 12 Mär. 2020
Bearbeitet: Jakob B. Nielsen am 12 Mär. 2020
Making the simulated signal is quite simple. First, make a vector t which covers the time domain you are interested in. Then, generate your two sine vectors from this x, and add them together:
t=0.001:0.001:1; %this gives you t that starts from 0.001, in steps of 0.001, up to 1.
f1=10;
f2=100;
totalSignal=sin(2*pi*f1*t)+sin(2*pi*f2*t); %two signals with frequency 10 and 100 Hz, lets imagine.
plot(t,totalSignal);
Now that you have your signal, you can look into different options for recovering your original input frequencies. Fourier analysis is a great way of achievting this - check out the fft documentation for more info.

5 Kommentare

Hi, I did what you told me, I have created wave1 with f1=30Hz and wave2 with f2=60Hz. I did their sum "total".
The next step is to recuperate wave1 from the "total". I didi the FFT of the total. I got two peaks one in 30Hz and the other in 60Hz. Next, I have filtered out (Low pass filter) the wave2. Now that I got the peak corresponding to wave1 (30Hz). My question is how to do the ifft in a right way to get the wave1 back. My code gives my a signal diffrent to wave1 (see the pictures) I dont know where is the problem
>>t=0:1/1000:0.1;
>> f1=30;
>> T1=1/f1;
>> f2=60;
>> T2=1/f2;
>> wave1=sin(2*pi*t/T1);
>> wave2=sin(2*pi*t/T2);
>> total=wave1+wave2;
>> xdft3=fft(total);
>> frq3=0:1000/length(total):1000/2;
>> xdftPos3=xdft3(1:length(total)/2+1);
>> xdftNorm3=xdftPos3/max(xdftPos3);
>> figure
>> plot(frq3,abs(xdftNorm3))
>> XX=(find(frq3>40)); % Low pass filter to recuperate the wave1
>> xdft4=xdft3;
>> xdft4(XX)=0;
>> invers3=ifft(xdft4);
>> figure
>> plot(t,invrs3)
What you must know when filtering like this is, that a fourier transform is a two-sided mirror images around the center. Like, try inserting this to visualize it;
test=0:1000/length(total):999;
plot(test,xdft3);
Now you can see, that since you actually remove almost the entirety of your transformed data, when you invert the transform it will muddle up a bit. What you must do is to retain the mirror part as well; with your current code, you keep only the first 5 indexes. Therefore, you must also keep the last 5 indexes.
Finally, you dont want to plot the absolute of your inverted data - but rather, the real part. For your specific example, try:
XX=(find(frq3>40)); % Low pass filter to recuperate the wave1
xdft4=xdft3;
xdft4(6:end-5)=0;%keep the first 5 and last 5 indexes!
invers3=ifft(xdft4);
figure
plot(t,real(invers3)) %plot the real part.
Thank you sooooooooo much. I really appreaciate your help. Now I can see it.
One more question, when I do:
plot(t,wave1)
hold on
plot(t,real(invers3))
the signal are not 100% similar, there is a slight diffrence, is it normal or not ? and why they are not 100% similar.
Jakob B. Nielsen
Jakob B. Nielsen am 13 Mär. 2020
Bearbeitet: Jakob B. Nielsen am 13 Mär. 2020
It is probably a matter of "resolution". If you look at the frequency domain plot, you will see that the "peaks" at 30 and 60 Hz has some 'shoulder' like qualities, as well as at 70 Hz the power dips below 0 for a little bit. All of this is information; but since you only have 50 frequencies to spread this information out on, some of it will invariably be lost hwne you do a very 'crude' filtering.
Try, for example, to set your "sampling resolution" to 10000 instead of 1000, and repeat the entire thing; you will see your ifft comes much much closer to your original 30 Hz signal then. If you took a "resolution" of 100000 it would be even closer.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by