i have a signal with many frequencies. how to find this frequencies and reconstruct the signal from these frequencies
3 次查看(过去 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');
0 个评论
采纳的回答
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
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 Center 和 File Exchange 中查找有关 Spectral Measurements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!