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

조회 수: 1 (최근 30일)
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');

채택된 답변

Manan Mishra
Manan Mishra 2017년 8월 17일
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
Manan Mishra
Manan Mishra 2017년 8월 18일
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;

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by