Clear Filters
Clear Filters

How do I find a max value of a signal defined within a range?

1 view (last 30 days)
Hello, I am looking for some help please. I have two signals and I am taking the max peak of signal 1, which is for example 3.019 Hz and then I want to create a range by subtracting .05 and adding .05 to 3.019 to create a range of 2.969 Hz to 3.069 Hz. Then I want to use that range to find signal 2's peak between 2.969 Hz to 3.069 Hz. Therefore, I just want to find the peak for signal 2 within that range.
if true
signal = cos(2*pi*f*t).*(A.*(heaviside(t)-heaviside(t-39E-9)));
data1 = zeros(1,1);
index1 = 0;
y1 = fft(signal);
m1 = abs(y1);
er1 = (0:length(y1)-1)*(1/h)/length(y1);
indexmax1 = find(max(m1) == m1);
xmax1 = er1(indexmax1);
ymax1 = m1(indexmax1);
index1 = index1 + 1;
data1(index1, 1:1) = xmax1(1,1);
%Graphed signal_4
signal_4 = [cos(2*pi*f*t).*(A4.*(heaviside(t)-heaviside(t-4E-9)))]+[cos(2*pi*f*t).*(A4.*(heaviside(t-7E-9)-heaviside(t-11E-9)))];
data4 = zeros(1,1);
index4 = 0;
y4 = fft(signal);
m4 = abs(y4);
er4 = (0:length(y4)-1)*(1/h)/length(y4);
indexmax4 = find(max(m4) == m4);
xmax4 = er4(indexmax4);
ymax4 = m4(indexmax4);
index4 = index4 + 1;
data4(index4, 1:1) = xmax4(1,1);
end
This is just the skeleton of my code and therefore will not run, but is just to convey what tools I am using to find the peaks.
Basically as I generate more signals the peaks of the other signals get more narrow, but as a result more peak appear some higher then the peaks I want, so that's why I am using signal 1's peak to narrow down signal 2's peak.
Hope this all made sense. Please any help would be greatly appreciated.

Answers (0)

Community Treasure Hunt

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

Start Hunting!