%% 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; %you can 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); % frequency corresponding to peak [peak_fr] = fr(peak_loc); %Sort amplitude values into descending order DescendAmp = sort(peak_ft,'descend'); % 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
To view the corresponding frequency values in descending order of amplitude, you can sort the indices of the amplitude values (peak_ft
) and use those indices to reorder the corresponding frequency values (peak_fr
). This can be done by sorting the indices based on the amplitude and then using those indices to reorder the frequency values.
Here’s how you can do it:
% Sort amplitude values into descending order and get the corresponding frequency [DescendAmp, sortIdx] = sort(peak_ft, 'descend'); % Sort amplitudes and get sorting indices % Reorder the frequencies using the sorted indices DescendFreq = peak_fr(sortIdx); % Now DescendAmp contains the sorted amplitudes, and DescendFreq contains the corresponding frequencies % You can plot the results or display them % Plot the corresponding frequency vs. amplitude in descending order figure; plot(DescendFreq, DescendAmp, 'o-'); xlabel('Frequency (Hz)'); ylabel('Amplitude'); title('Sorted Frequency vs. Amplitude'); grid on;
Sorting Amplitude and Getting Indices:
[DescendAmp, sortIdx] = sort(peak_ft, 'descend');
sortIdx
, which tell you how to reorder the original data.Reordering the Frequencies:
DescendFreq = peak_fr(sortIdx);
sortIdx
, we reorder the frequencies (peak_fr
) to match the sorted amplitudes.Plotting the Results:
plot(DescendFreq, DescendAmp, 'o-');
DescendAmp
: Amplitudes sorted in descending order.DescendFreq
: Frequencies corresponding to the sorted amplitudes.Now, you can directly view the frequencies corresponding to the peaks in descending order of their amplitudes.
Matlabsolutions.com provides guaranteed satisfaction with a
commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain
experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support
to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been
empanelled after extensive research and quality check.
Matlabsolutions.com provides undivided attention to each Matlab
assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services
include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work
done at the best price in industry.