Clear Filters
Clear Filters

i have a signal with many frequencies. how to find this frequencies and reconstruct the signal from these frequencies

4 views (last 30 days)
I've attached a MATLAB code, in that timeseries is the signal for which frequencies have to be found. I've tried using FFT but not getting the answer. my code for frequency and regeneration: t =0:1:2048; y=timeseries;
ffty = fft(y);
ffty = abs(ffty(1:ceil(length(y)/2))); % ffty(ffty<2)=0; [~,locs] = findpeaks(ffty); freqs = (locs-1)/t(end); signal_1=0; for n=1:1:length(freqs) signal_1 = (signal_1+sin(2*pi*freqs(n)*t)); end hold on plot(smooth(signal_1));
hold on plot(y,'b');

Accepted Answer

Manan Mishra
Manan Mishra on 17 Aug 2017
I think this should work for you:
ffty = fft(y);
P2 = abs(ffty/length(ffty));
P1 = P2(1:ceil(length(y)/2));
P1(2:end-1) = 2*P1(2:end-1);
[amp,locs] = findpeaks(P1);
freqs = (locs-1)/t(end);
signal_1=0;
for n=1:length(freqs)
signal_1 = (signal_1+amp(n)*sin(2*pi*freqs(n)*t));
end
hold on;
plot(smooth(signal_1));
plot(y,'b');
Here, P2 is the two-sided spectrum and P1 is the single-sided spectrum.
A two-sided power spectrum displays half the energy at the positive frequency and half the energy at the negative frequency. Therefore, to convert a two-sided spectrum to a single-sided spectrum, you discard the second half of the array and multiply every point except for DC by two.
Also, while regenerating the signal in the "for" loop, you need to take the amplitude of corresponding frequencies into consideration. Hence, you need the first output "amp" of "findpeaks".
You can also eliminate the "for" loop by using vectorization:
signal_1=sum(amp'.*(sin(2*pi*freqs'*t)));
  3 Comments
Manan Mishra
Manan Mishra on 18 Aug 2017
You should remove the "smooth" function when plotting as it takes a moving average and averages the different sine signals to zero.
Also, while recreating "signal_1", you should start from the starting point of y and not 0.
Try these changes:
plot(signal_1)
instead of
plot(smooth(signal_1));
and
signal_1=y(1);
instead of
signal_1=0;

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!