Im trying to extract the frequency peaks of an FFT in order to synthesis the original using additive synthesis.

조회 수: 4 (최근 30일)
Ive tried using the findpeaks function and using the location values however these do not seem to be in Hz how would i go about converting
Here is my code
p = 2^nextpow2(N);
x = fft(y,nfft)/p; % performs fft of clip
forx = fs/2*linspace(0,1,nfft/2+1);
X = 2*(abs(x(1:nfft/2+1)));
[peakval, locval] = findpeaks(X,fs,'minpeakheight',1.8*10^-5);
%% add synth
Freqs = locval;
Xs = zeros(length(Freqs),length(time));
for i=1:length(Freqs)
%Xs(i,:) = singen(Freqs(i),fs,time);
Xs(i,:) = sin(2*pi*Freqs(i)*time);
end
x = sum(Xs);
x = x./max(abs(x));
soundsc(x)

채택된 답변

Ridwan Alam
Ridwan Alam 2019년 12월 3일
편집: Ridwan Alam 2019년 12월 3일
findpeaks() returns the indices of the input signal where the peaks were found. you have to use the frequency range to convert those locations to Hz.
x = fft(y,nfft)/p; % performs fft of clip
freq_range = fs*(0:(nfft/2))/nfft;
X = abs(x(1:nfft/2+1));
X(2:end-1) = 2*X(2:end-1);
[peakval, locval] = findpeaks(X,'minpeakheight',1.8*10^-5);
Freqs = freq_range(locval);
...
Hope this helps.

추가 답변 (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