How to analyze part of a signal?

2 次查看(过去 30 天)
Anonymous45
Anonymous45 2017-3-22
回答: AJ Woodson 2020-11-3
Hello, I have created a sinusoidal signal, but I only want to find a peak value between 'x' to 'y' seconds of the signal. How would I set a limit so that only the data of the sinusoidal signal is analyzed in MATLAB between 'x' to 'y' seconds?
I have tried to use the function "xlim", but I think that is only for setting limits on a graph.
I hope this is not to broad of a question, but any help would be greatly appreciated.

回答(2 个)

dpb
dpb 2017-3-22
Index into the result vector based on values of time; if you have a fixed timestep then it's simply T/dt intervals past T0 or the delta is (Tend-Tstart)/dt points.
Then, "Use the colon, Luke!"
ymax=max(y(idxStart:idxEnd));
where you've just computed the two indices above.
Alternatively, there is (beginning R2015a, anyway) a timeseries class that has the ability to retrieve data by time and methods to manipulate data that potentially could be simpler coding. I've not 'spearminted with it to date so no real firsthand data with to really recommend for/against the implementation; just know it exists.
  5 个评论
dpb
dpb 2017-3-23
I'm not sure who x is here; the abscissa or ordinate for the time series? Where does m1 come from in the above; why are you searching for a specific value?
You may want to study
doc findpeaks % it has many options for peak-finding with conditions
Anonymous45
Anonymous45 2017-3-23
I am sorry for not being more clear and perhaps I should have just started this forum with my code to begin. This is the code that I am work with and the two signals I am using. 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.
%
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

请先登录,再进行评论。


AJ Woodson
AJ Woodson 2020-11-3
If I have signal X for say the if want to take a portion of that signal you could do something like b = X(beginPoint:DesiredEnd)

类别

Help CenterFile Exchange 中查找有关 Get Started with Signal Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by