Clear Filters
Clear Filters

how to use findpeaks in fft (with for,if,else)

4 views (last 30 days)
I did this code on the matlab function simulink with the input is a sine signal with a frequency of 49 and 98, and it was converted into a frequency domain with fast fourier transform with a sampling frequency of 1000 so that the magnitude amplitude value could be up to 1000 more, I used findpeaks to get the peak value and the location of the peaks that appear at frequencies 49 and 98, but in fact there are many small peaks that are read by findpeaks, therefore I use for if and else to only read above the value of 1000, but still not successful with a written error
Simulink does not have enough information to determine output sizes for this block. If you think the errors below are inaccurate, try specifying types for the block inputs and / or sizes for the block outputs.
is it possible that anyone can help where the error lies, thanks
function [dist,locs1,locs2] = fcn(u)
for i = -500:500
x = u(1,i);
[pks,locs] = findpeaks(x);
a = locs(4)- locs(3);
b = locs(3);
c = locs(4);
dist = a;
locs1 = b;
locs2 = c;

Answers (1)

Chaitanya Mallela
Chaitanya Mallela on 30 Dec 2020
Edited: Chaitanya Mallela on 30 Dec 2020
You can try findpeaks function with Name Value pairs such as 'MinPeaksHeight', 'MinPeakDistance' and 'NPeaks'


Community Treasure Hunt

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

Start Hunting!