Signal Processing, finding average of specific values only.
조회 수: 4 (최근 30일)
이전 댓글 표시
%% Peak detection Part
% In this part, we have defined a threshold value. So, all peaks above
% threshold value will be detected.
temp_fft = data_filt_ft;
% Normalize the FFT
temp_fft = temp_fft/max(temp_fft);
% threshold
th = 0.02; % i.e. 1% of maximum amplitude
temp_fft(temp_fft < th) = 0; %skip this step by commenting this.
% Plot FFT after thresholding
figure; plot(fr, temp_fft);
xlabel('Frequency(Hz)'); ylabel('Amplitude');
grid on;
% find peaks of the remaining data
[peak_ft, peak_loc] = findpeaks(temp_fft);
%Sort amplitude values into descending order
[peak_ft_sorted_values,peak_ft_sorted_index] = sort(peak_ft,'descend');
% frequency corresponding to peak
[peak_fr] = fr(peak_loc);
% and now sorted according to amplitude
peak_fr_sorted_values = peak_fr(peak_ft_sorted_index);
% this fuction returns the fourier transform of the signal
function [ft, f] = fr_t(x, Fs)
L = length(x);
% NFFT = 2^nextpow2(L); % Next power of 2 from length of y
NFFT = L;
X = fft(x,NFFT)/NFFT;
f = Fs/2*linspace(0,1,floor(NFFT/2+1));
ft = abs(X(1:floor(NFFT/2+1)));
% ft = 20*log10(ft);
% plot(f,ft);
end
In the above code, is there anyway I can get MATLAB to output the averages of the 2nd,3rd and 4th values only(from the workspace) that corresponds to the peak_ft_sorted_values as well as for the peak_fr_sorted_values?
댓글 수: 1
Mathieu NOE
2021년 3월 1일
hello again
I would be useful if you could provide a input data file and a plot showing what data you want to average ...
I guess you have more than 1 point data for each peak (amplitude above threshold) and that is what you intend to average ?
tx
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Parametric Spectral Estimation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!