How to find peak coordinates of a signal within a specific range?
2 views (last 30 days)
Show older comments
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 Comments
Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!