フィルターのクリア

How can I plot the spectrum of two segments from this signal?

2 ビュー (過去 30 日間)
Hannah Oduntan
Hannah Oduntan 2018 年 12 月 30 日
コメント済み: Star Strider 2018 年 12 月 30 日
In the signal attached, how can I get the spectrum for the first segment of the signal (the signal before the major peak) and and the third segment of the signal (the signal after the major peak)? This is the code I have used, but unfortunately the figure comes up blank for some reason.

採用された回答

Star Strider
Star Strider 2018 年 12 月 30 日
Try this:
D = load('signals (1).mat');
Signal = D.Signal; % Get ‘Signal’
N = length(Signal);
t = linspace(0, 1, N) * N; % Create Time Vector
[pk,loc] = findpeaks(Signal, 'MinPeakHeight',1); % Determine Indices Of Various Components
[trofs,trlocs] = findpeaks(-Signal);
ltidx = find(trlocs < loc, 1, 'last');
gtidx = find(trlocs > loc, 1, 'first');
Out{1} = {Signal(1:trlocs(ltidx)); Signal(trlocs(ltidx)+1:trlocs(gtidx)-1); Signal(trlocs(gtidx):end)}; % ‘Signal’ Cell Array
Out{2} = {t(1:trlocs(ltidx)); t(trlocs(ltidx)+1:trlocs(gtidx)-1); t(trlocs(gtidx):N)}; % ‘t’ Cell Array
figure
plot(Out{2}{1}, Out{1}{1}, 'r')
hold on
plot(Out{2}{2}, Out{1}{2}, 'g')
plot(Out{2}{3}, Out{1}{3}, 'b')
hold off
grid
xlim([min(t) max(t)])
figure
subplot(2, 2, 1);
plot(Out{2}{1}, Out{1}{1}, 'r')
grid
subplot(2, 2, 2);
plot(Out{2}{2}, Out{1}{2}, 'g')
grid
subplot(2, 2, 3);
plot(Out{2}{3}, Out{1}{3}, 'b')
grid
FFTN = 2^14;
% Fv = linspace(0, 1, fix(FFTN/2)+1);
for k1 = 1:numel(Out{1})
Ts = mean(diff(Out{2}{k1}));
Fs = 1/Ts;
Fn = Fs/2;
FTSeg{k1} = fft(Out{1}{k1},FFTN);
Fv{k1} = linspace(0, 1, fix(numel(FTSeg{k1})/2)+1)*Fn;
Iv{k1} = 1:numel(Fv{k1});
end
ttlcs = {'Signal Before Peak', 'Peak', 'Signal After Peak'};
figure
for k1 = 1:numel(Out{1})
subplot(numel(Out{1}), 1, k1)
plot(Fv{k1}, abs(FTSeg{k1}(Iv{k1})*2))
xlim([0 0.02])
title(ttlcs(k1))
end
The Plot —
How can I plot the spectrum of two segments from this signal - 2018 12 30.png
  2 件のコメント
Hannah Oduntan
Hannah Oduntan 2018 年 12 月 30 日
That worked fine, thank you so much!
Star Strider
Star Strider 2018 年 12 月 30 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultirate Signal Processing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by