MATLAB: Plotting specific range – amplitude peak

amplitudedatapeakplotrange

Hi, I have this data, and what I am trying to do is plot just the first peak (shown inside the rectangle) of the amplitude plot. I work with different data, so I am looking for a way to do it automatically. Any ideas?
It is more like 'giving a zoom' in that specific range. I am using the following the code to plot the data.
format long g
fid2 = fopen('FarReceiver.csv');
if fid2 > 0
data = textscan(fid2,'%s %s %f %f %f','Delimiter',',','HeaderLines',1);
fclose(fid2);
end
Timestamp2 = strcat(data{:,2});
Timeformat2=datenum(Timestamp2,'HH:MM:SS.FFF');
ConvertTime2 = (Timeformat2 * 86400000);
b = ConvertTime2(1);
TimestampNum2 = (ConvertTime2 - b);
amplitude2 = [data{:,5}]';
Amplitude_max2 = max(abs(amplitude2));
ampfar = (amplitude2/Amplitude_max2);
z = mean(ampfar);
amp2 = (ampfar - z);
plot(TimestampNum2, amp2)
Thank you very much!

Best Answer

If you have the Signal Processing Toolbox, use the findpeaks function.
This is written to be specific to the data you attached, so I don’t know how well it would generalise to your other signals. It is a way to automate your isolation of the first impulse.
This replaces your plot call in your code:
[Pks,Locs] = findpeaks(amp2, 'MinPeakHeight',0.2, 'MinPeakDistance',50);
figure(1)
plot(TimestampNum2, amp2)
hold on
plot(TimestampNum2(Locs(1)), Pks(1), '^r')
hold off
figure(2)
plot(TimestampNum2(Locs(1)-5:Locs(2)-5), amp2(Locs(1)-5:Locs(2)-5))
grid
You may need to experiment with it to get the result you want.