How to find peak coordinates of a signal within a specific range?

The code below is of two signals. I am trying to take the peak/max value of "signal_1", then create a range: (max_value_x_component - 0.1e+9) to (max_value_x_component + 0.1e+9).
Then for signal_5 I want to find the x and y coordinates of the peak/max value between the rang: (max_value_x_component - 0.1e+9) to (max_value_x_component + 0.1e+9).
I am looking to run this in a loop, so I need to actually find the peak values within the range through coding and not just by looking at a graph.
The code below will produce two figures with two graphs on each figure as seen in image 1 below. The graph that I am interested in analyzing is the second two graphs labeled "Graph of signal Fourier Transform". When looking at the graph you only see two large peaks/spikes one on the left near the origin and one on the far right. You need zoom into the left peak to see the waveform being analyzed as seen in image 2 below.
h = 1.00E-12;
t = 0:h:40E-9;
A = 1;
A2 = 1.1111111;
A3 = 2.2222222;
A4 = 10;
A5 = 20;
f=3E9;
nfft = 2^(nextpow2(length(t))+5);
%Graphed signal_1
signal = cos(2*pi*f*t).*(A.*(heaviside(t)-heaviside(t-39E-9)));
snrdB = 0;
noise = 10^(-snrdB/20)*randn(size(signal));
sn = noise+signal;
y1 = fft(sn,nfft);
m1 = abs(y1);
er1 = (0:length(y1)-1)*(1/h)/length(y1);
figure (1)
subplot(2,1,1)
plot(t,sn)
title('Graph of signal_1')
xlabel('Time') % x-axis label
ylabel('Amplitude') % y-axis label
subplot(2,1,2)
plot(er1,m1)
grid on
title('Graph of signal_1 Fourier Transform')
xlabel('Frequency') % x-axis label
ylabel('Amplitude') % y-axis label
%Graphed signal_5
signal_5 = [cos(2*pi*f*t).*(A5.*(heaviside(t)-heaviside(t-1E-9)))]+[cos(2*pi*f*t).*(A5.*(heaviside(t-4E-9)-heaviside(t-5E-9)))];
snrdB = 0;
noise = 10^(-snrdB/20)*randn(size(signal_5));
s5n = noise+signal_5;
y5 = fft(s5n,nfft);
m5 = abs(y5);
er5 = (0:length(y5)-1)*(1/h)/length(y5);
indexmax = find(max(m5) == m5)
xmax = er5(indexmax)
ymax = m5(indexmax)
figure (5)
subplot(2,1,1)
plot(t,s5n)
title('Graph of signal_5')
xlabel('Time') % x-axis label
ylabel('Amplitude') % y-axis label
subplot(2,1,2)
plot(er5,m5)
grid on
title('Graph of signal_5 Fourier Transform')
xlabel('Frequency') % x-axis label
ylabel('Amplitude') % y-axis label
Image 1. This is the figure that will be produced.
Image 2. This is the zoomed in waveform for the Four Transform graph of signal 3.

댓글 수: 4

Could you elaborate what you are trying to do and what you mean by 'max_value_x_component'? Because your signal1 plot shows an x-axis range of the order of -8.
Same question. it's not clear. Perhaps findpeaks() will help you.
For example this is where I am with my code:
h = 1.00E-12;
t = 0:h:40E-9;
A = 1;
A2 = 1.1111111;
A3 = 2.2222222;
A4 = 5;
A5 = 20;
f=3E9;
nfft = 2^(nextpow2(length(t))+5);
signal = cos(2*pi*f*t).*(A.*(heaviside(t)-heaviside(t-39E-9)));
data1 = zeros(500,1);
index1 = 0;
data1_1 = zeros(16,1);
index1_1 = 0;
for k = 0:1:30
for i = 1:1000
snrdB = k;
noise = 10^(-snrdB/20)*randn(size(signal));
sn = noise+signal;
y1 = fft(sn,nfft);
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);
end
index1 = 0;
V = std(data1);
index1_1 = index1_1 + 1;
data1_1(index1_1, 1:1) = V(1,1);
end
%Graphed signal_5
signal_5 = [cos(2*pi*f*t).*(A5.*(heaviside(t)-heaviside(t-1E-9)))]+[cos(2*pi*f*t).*(A5.*(heaviside(t-4E-9)-heaviside(t-5E-9)))];
data5 = zeros(500,1);
index5 = 0;
data5_2 = zeros(30,1);
index5_2 = 0;
for k = 0:1:30
for i = 1:1000
snrdB = k;
noise5 = 10.^(-snrdB./20).*randn(size(signal_5));
s5n = noise5+signal_5;
y5 = fft(s5n,nfft);
m5 = abs(y5);
er5 = (0:length(y5)-1)*(1/h)/length(y5);
indexmax5 = find(max(m5) == m5);
xmax5 = er5(indexmax5);
ymax5 = m5(indexmax5);
index5 = index5 + 1;
data5(index5, 1:1) = xmax5(1,1);
end
index5 = 0;
V = std(data5);
index5_2 = index5_2 + 1;
data5_2(index5_2, 1:1) = V(1,1);
end
figure(1)
plot (0:1:30, data1_1, 0:1:30, data5_2)
As you can see I am finding the max(m1) and indexing xmax1(1,1). Now I want to take that index value and make it into a boundary for the second signal. Instead of finding the max value of signal 5 I want to find the max value of signal 5 in between the range xmax1(1,1)-5 to xmax1(1,1)+5.
I hope this helps explain more. If you have any questions please don't hesitate to ask.
Something like this, but this doesn't work:
indexmax5 = find(xmax4 - 0.0001E+09: xmax4 + 0.0001E+09, max(m5) == m5);

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Get Started with Signal Processing Toolbox에 대해 자세히 알아보기

질문:

2017년 3월 26일

댓글:

2017년 4월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by