How to separate signals with diffrent frequencies

t = linspace(0, 1, 1001);
x=sin(2*pi*t*3) + sin(2*pi*t*6) + sin(2*pi*t*10)+sin(2*pi*t*13)+sin(2*pi*t*20)+sin(2*pi*t*50)+sin(2*pi*t*100)+sin(2*pi*t*200);
% my signal with frequencies 3,6,10,13,20,50,100,200 KHz
sigma=0.1;
y=x+randn(size(x)).*sigma; % adding noise
I filtered the signal using fft.
I want to separate signals.
Eg : from my original signal, I want a signal with frequency range say 3 to 8 KHz, another signal say from 100 to 200 KHz. How can I separate them and display those signals.How can I do this. Anybody Please help me to solve this.?

2 Kommentare

you must read about chebishev and butter filter
i too want to seperate certain frequency range from my original signal. can you help me?

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Shoaibur Rahman
Shoaibur Rahman am 1 Jan. 2015

5 Stimmen

Add the following lines of code at the bottom of your code (after y=x+randn(size(x)).*sigma;):
ffty = fft(y);
ffty = abs(ffty(1:ceil(length(y)/2)));
ffty(ffty<100)=0;
[~,locs] = findpeaks(ffty);
freqs = (locs-1)/t(end)
signal_1 = sin(2*pi*t*freqs(1))+sin(2*pi*t*freqs(2))+sin(2*pi*t*freqs(3)); % 3-10
signal_2 = sin(2*pi*t*freqs(6))+sin(2*pi*t*freqs(7)); % 50-100
subplot(211), plot(t,signal_1)
subplot(212), plot(t,signal_2)

10 Kommentare

Srey
Srey am 1 Jan. 2015
Bearbeitet: Srey am 1 Jan. 2015
In above code, the range is set based on the values obtained in freqs. If the signal is x1 =
0.0022
0.0012
0.0012
0.0009
0.0006
0.0006
0.0006
0.0012
0.0006
0.0006
0.0012
0.0009
0.0006
0.0009
0.0003
0.0009
0.0012
0.0009
0.0006
0.0012
0.0006
0.0015
0.0006
0.0009
0.0012
0.0009
0.0009
0.0012
0.0012
0.0012
0.0009
0.0012
0.0009
0.0019
0.0019
0.0015
0.0015
0.0015
0.0015
0.0012
0.0015
0.0015
0.0012
0.0009
0.0012
0.0012
0.0012
0.0012
0.0009
0.0009
0.0012
0.0009
0.0006
0.0009
0.0009
0.0003
0.0009
0.0012
0.0009
0.0009
0.0006
0.0009
0.0006
0.0006
0.0012
0.0009
0.0022
0.0012
0.0012
0.0012
0.0012
0.0009
0.0012
0.0009
0.0006
0.0009
0.0009
0.0015
0.0009
0.0009
0.0012
0.0003
0.0006
0.0009
0.0006
0.0012
0.0006
0.0009
0.0015
0.0006
0.0015
0.0006
0.0009
0.0012
0.0009
0.0009
0.0015
0.0009
0.0006
0.0022
0.0015
0.0015
0.0009
0.0012
0.0009
0.0012
0.0012
0.0009
0.0006
0.0012
0.0003
0.0012
0.0009
0.0012
0.0009
0.0006
0.0012
0.0009
0.0009
0.0012
0.0009
0.0009
0.0015
0.0003
0.0009
0.0012
0.0012
0.0009
0.0012
0.0015
0.0015
0.0012
0.0009
0.0009
0.0012
0.0012
0.0015
0.0009
0.0012
0.0006
0.0006
0.0009
0.0012
0.0015
0.0006
0.0015
0.0006
0.0009
0.0012
0.0003
0.0006
0.0009
0.0009
0.0006
0.0006
0.0009
0.0009
0.0012
0.0009
0.0012
0.0015
0.0009
0.0015
0.0009
0.0009
0.0012
0.0012
0.0012
0.0009
0.0012
0.0012
0.0012
0.0006
0.0006
0.0015
0.0009
0.0012
0.0006
0.0009
0.0009
0.0015
0.0015
0.0012
0.0009
0.0012
0.0012
0.0012
0.0015
0.0012
0.0012
0.0012
0.0012
0.0006
0.0015
0.0009
0.0019
0.0009
0.0012
0.0012
0.0009
0.0009
0.0006
0.0012
0.0006
0.0006
0.0012
0.0009
0.0009
0.0006
0.0012
0.0012
0.0012
0.0009
0.0012
0.0012
0.0006
0.0009
0.0012
0.0015
0.0015
0.0015
0.0003
0.0009
0.0012
0.0012
0.0003
0.0012
0.0009
0.0019
0.0015
0.0012
0.0012
0.0009
0.0012
-0.0000
0.0006
0.0009
0.0003
0.0006
0.0003
0.0015
0.0009
0.0012
0.0012
0.0009
0.0009
0.0012
0.0003
0.0012
0.0009
0.0009
0.0012
0.0012
0.0012
0.0006
0.0006
0.0009
0.0006
0.0012
0.0009
0.0009
0.0006
0.0012
0.0012
0.0006
0.0009
0.0006
0.0003
0.0015
0.0015
0.0009
0.0009
0.0012
0.0009
0.0009
0.0012
0.0003
0.0009
0.0012
0.0009
0.0012
0.0012
0.0015
0.0012
0.0022
0.0009
0.0012
0.0009
0.0019
0.0012
0.0006
0.0009
0.0012
0.0012
0.0012
0.0012
0.0009
0.0012
0.0006
0.0012
0.0009
0.0009
0.0003
0.0006
0.0009
0.0009
0.0009
0.0009
0.0019
0.0009
0.0015
0.0019
0.0012
0.0006
0.0012
0.0012
0.0006
0.0006
0.0012
0.0009
0.0009
0.0012
0.0009
0.0012
0.0009
0.0006
0.0009
0.0009
0.0012
0.0012
0.0009
0.0006
0.0006
0.0015
0.0009
0.0006
0.0009
0.0012
0.0012
0.0012
0.0009
0.0015
0.0009
0.0009
0.0015
0.0012
0.0015
0.0012
0.0012
0.0009
0.0015
0.0012
0.0012
0.0006
0.0009
0.0015
0.0012
0.0006
0.0006
0.0006
0.0006
0.0012
0.0006
0.0012
0.0019
0.0006
0.0009
0.0009
0.0006
0.0009
0.0015
0.0015
0.0012
0.0012
0.0006
0.0009
0.0012
0.0009
0.0009
0.0009
0.0006
0.0012
0.0012
0.0009
0.0012
0.0006
0.0012
0.0009
0.0009
0.0012
0.0012
0.0006
0.0012
0.0012
0.0012
0.0009
0.0009
0.0006
0.0015
0.0009
0.0006
0.0012
0.0009
0.0012
0.0015
0.0009
0.0012
0.0012
0.0006
0.0009
0.0006
0.0006
0.0009
0.0012
0.0012
0.0015
0.0009
0.0006
0.0009
0.0006
0.0015
0.0006
0.0012
0.0012
0.0009
0.0009
0.0012
0.0019
0.0006
0.0012
0.0012
0.0009
0.0012
0.0015
0.0006
0.0015
0.0019
0.0025
0.0006
0.0012
0.0009
0.0009
0.0006
0.0012
0.0006
0.0009
0.0006
0.0009
0.0009
0.0006
0.0009
0.0009
0.0009
0.0009
0.0009
0.0009
0.0009
0.0006
0.0009
0.0009
0.0012
0.0009
0.0015
0.0009
0.0012
0.0012
0.0012
0.0006
0.0015
0.0006
0.0009
0.0006
0.0006
0.0015
0.0015
0.0009
0.0012
0.0003
0.0012
0.0009
0.0003
0.0009
0.0006
0.0009
0.0006
0.0009
0.0006
0.0009
0.0012
0.0009
0.0012
0.0012
0.0006
0.0012
0.0009
0.0019
0.0012
0.0012
0.0012
0.0009
0.0009
0.0009
0.0006
0.0006
0.0009
0.0015
0.0003
0.0006
0.0012
0.0009
0.0012
0.0006
0.0006
0.0015
0.0019
0.0009
0.0009
0.0006
0.0009
0.0009
0.0012
0.0009
0.0006
0.0009
0.0009
0.0006
0.0015
0.0012
0.0012
0.0009
0.0015
0.0012
0.0006
0.0009
0.0015
0.0012
0.0015
0.0012
0.0012
0.0009
0.0006
0.0009
0.0006
0.0012
0.0009
0.0012
0.0012
0.0012
0.0006
0.0006
0.0006
0.0006
0.0006
0.0012
0.0006
0.0015
0.0012
0.0009
0.0015
0.0012
0.0009
0.0012
0.0019
0.0012
0.0012
0.0009
0.0012
0.0009
0.0012
0.0006
0.0009
0.0006
0.0012
0.0006
0.0009
0.0012
0.0006
0.0012
0.0009
0.0009
0.0019
0.0015
0.0009
0.0012
0.0009
0.0012
0.0009
0.0006
0.0012
0.0009
0.0012
0.0012
0.0009
0.0012
0.0003
0.0009
0.0009
0.0019
0.0019
0.0012
0.0012
0.0009
0.0012
0.0012
0.0003
0.0006
0.0012
0.0006
0.0012
0.0009
0.0009
0.0009
0.0012
0.0015
0.0012
0.0009
0.0012
0.0009
0.0012
0.0009
0.0015
0.0012
0.0012
0.0012
0.0019
0.0012
0.0009
0.0006
0.0009
0.0006
0.0012
0.0012
0.0006
0.0012
0.0003
0.0015
0.0006
0.0006
0.0012
0.0012
0.0009
0.0012
0.0012
0.0006
0.0009
0.0015
0.0012
0.0012
0.0003
0.0012
0.0012
0.0012
0.0006
0.0012
0.0012
0.0009
0.0012
0.0006
0.0009
0.0009
0.0006
0.0009
0.0012
0.0006
0.0012
0.0012
0.0006
0.0012
0.0009
0.0003
0.0006
0.0015
0.0009
0.0012
0.0009
0.0009
0.0006
0.0009
0.0012
0.0012
0.0009
0.0006
0.0009
0.0012
0.0015
0.0012
0.0009
0.0009
0.0012
0.0009
0.0009
0.0015
0.0009
0.0012
0.0012
0.0006
0.0009
0.0009
0.0012
0.0006
0.0012
0.0009
0.0012
0.0009
0.0009
0.0012
0.0012
0.0009
0.0009
0.0009
0.0009
0.0015
0.0012
0.0012
0.0012
0.0003
0.0019
0.0009
0.0012
0.0009
0.0009
0.0012
0.0006
0.0012
0.0012
0.0006
0.0012
0.0009
0.0006
0.0009
0.0003
0.0012
0.0012
0.0009
0.0012
0.0012
0.0006
0.0012
0.0012
0.0012
0.0006
0.0012
0.0009
0.0012
0.0009
0.0009
0.0009
0.0009
0.0012
0.0006
0.0012
0.0006
0.0009
0.0009
0.0009
0.0009
0.0009
0.0003
0.0006
0.0009
0.0012
0.0012
0.0012
0.0009
0.0009
0.0009
0.0006
0.0006
0.0012
0.0012
0.0015
0.0009
0.0006
0.0009
0.0006
0.0019
0.0009
0.0009
0.0009
0.0009
0.0006
0.0006
0.0006
0.0012
0.0012
0.0009
0.0015
0.0009
0.0015
0.0009
0.0012
0.0012
0.0019
0.0009
0.0006
0.0015
0.0009
0.0006
0.0006
0.0006
0.0009
0.0006
0.0006
0.0006
0.0012
0.0009
0.0009
0.0006
0.0012
0.0012
0.0009
0.0012
0.0012
0.0009
0.0012
0.0009
0.0012
0.0012
0.0006
0.0012
0.0012
0.0009
0.0012
0.0012
0.0009
0.0012
0.0012
0.0009
0.0012
0.0006
0.0012
0.0009
0.0006
0.0012
0.0015
0.0006
0.0012
0.0015
0.0009
0.0009
0.0015
0.0009
0.0015
0.0012
0.0009
0.0012
0.0015
0.0012
0.0012
0.0012
0.0012
0.0009
0.0012
0.0019
0.0006
0.0009
0.0012
0.0012
0.0006
0.0009
0.0009
0.0009
0.0009
0.0003
0.0006
0.0012
0.0006
0.0012
0.0006
0.0009
0.0012
0.0009
0.0009
0.0009
0.0012
0.0009
0.0006
0.0006
0.0015
0.0009
0.0012
0.0012
0.0019
0.0012
0.0009
0.0012
0.0009
0.0009
0.0006
0.0006
0.0006
0.0006
0.0012
0.0006
0.0003
0.0012
0.0009
0.0006
0.0006
0.0009
0.0006
0.0009
0.0015
0.0009
0.0009
0.0019
0.0015
0.0015
0.0015
0.0009
0.0012
0.0009
0.0012
0.0009
0.0015
0.0012
0.0009
0.0012
0.0009
0.0015
0.0015
0.0009
0.0015
0.0003
0.0009
0.0009
0.0012
0.0012
0.0009
0.0012
0.0015
0.0012
0.0015
0.0009
0.0006
0.0012
0.0015
0.0012
0.0012
0.0012
0.0015
0.0015
0.0009
0.0019
0.0012
0.0009
0.0015
0.0015
0.0012
0.0003
0.0015
0.0012
0.0009
0.0012
0.0012
0.0006
0.0003
0.0006
0.0009
0.0003
0.0009
0.0015
0.0009
0.0012
0.0012
0.0015
0.0015
0.0019
0.0012
0.0009
0.0015
0.0009
0.0012
0.0012
0.0006
0.0019
0.0009
0.0009
0.0009
-0.0000
0.0009
0.0009
0.0009
0.0006
0.0009
0.0006
0.0009
0.0009
0.0012
0.0012
0.0003
0.0012
0.0009
0.0009
0.0009
0.0006
0.0012
0.0009
0.0009
0.0012
Now i want to separate those frequency ranges, from this signal.I am getting, freqs =
Empty matrix: 1-by-0
Also, ,ffty(ffty<100)=0; ,why giving 100?
ffty(ffty<100)=0; is for thresholding the data at 100.
To do this for any other data, first see the plot(abs(fft(y))), and select the threshold value so that no peak is left away.
Srey
Srey am 1 Jan. 2015
Bearbeitet: Srey am 1 Jan. 2015
FRom the above code, the plot(abs(fft(y)))gives the following output: BY seeing , what value can be set as a threshold. Peaks are around 500.
For my data, used plot(abs(fft(y)), got the following output
What to do?
Okay, for some reason findpeaks function does not detect the peak at 1. You can also set your threshold inside the findpeaks function. So, modify the code a little bit:
ffty = abs(fft(y));
ffty = ffty(1:ceil(length(y)/2));
ffty = fftshift(ffty);
[~,locs] = findpeaks(ffty,'threshold',100);
freqs = (locs-1)/t(end)-floor(length(ffty)/2)
For previous signal: you can use threshold at any value below the maximum in the plot, like 100, 200, 300, 400........(make sure to keep the peaks, but remove the noise).
For next signal: threshold value can be 0.2, 0.3.......
Also, for aperiodic signal like your second one, use t(end)=1
Srey
Srey am 1 Jan. 2015
Bearbeitet: Srey am 1 Jan. 2015
t = linspace(0, 1,1001);
y=data(1:1000,1);% the signal provided above
t(end)=1;
plot(abs(fft(y)))
ffty = abs(fft(y));
ffty = abs(ffty(1:ceil(length(y)/2)));
ffty = fftshift(ffty);
[~,locs] = findpeaks(ffty,'threshold',0.2);
freqs = (locs-1)/t(end)-floor(length(ffty)/2)
i have tried this code, but freqs=0;
The data seems like a noise (may not be). Also, if you take the fft of it, you will see only one peak at 0. This means the frequency of this signal is 0. So, I think, you are getting correct result.
However, in case this is not a noise, don't leave the smaller peaks when thresholding. The fft peak locations in frequency domain are the frequencies of a signal. If you force them to be zeros by thresholding, then certainly you will miss those frequencies.
Srey
Srey am 1 Jan. 2015
Thank you so much..
Srey
Srey am 1 Jan. 2015
How can we then plot those signals, if frequencies are present in the signal.
Use any sinusoidal function to generate a signal with that frequency, and then plot that against time. For example:
t = .....
out1 = sin(2*pi*f1*t);
out2 = cos(2*pi*f2*t);
etc....
This is just from the Fourier analysis, that states any signal (with some criteria) can be represented as summation of infinite sinusoidal functions. So, to represent only one frequency, use one sinusoidal function, or to represent multiple frequency components, use summation of multiple sinusoidal functions with those frequencies.
Srey
Srey am 1 Jan. 2015
Thank you so much..It works.:)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Pourya Alinezhad
Pourya Alinezhad am 1 Jan. 2015

0 Stimmen

1-you can use several filters with different center frequencies (chebishev or butter filter)
h = fdesign.bandpass('N,F3dB1,F3dB2', N, Fc1, Fc2, Fs);
Hd = design(h, 'butter');
filter (Hd,input_signal);
2- you can use an adaptive filter and feed the signal and the desired signals to it (LMS filter).

2 Kommentare

Srey
Srey am 1 Jan. 2015
I want a signal with freq range:say 3-10Hz and another signal with freq say 50-100. I want to plot them separately.How can be done from my original signal
assign Fc1, Fc2 values as 3 and 10Kz for a filter. then make another filter with 50 to 100 kHz spectrum.

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by