フィルターのクリア

savitzky golay derivation graph plot

19 ビュー (過去 30 日間)
Alexai
Alexai 2022 年 12 月 15 日
コメント済み: Alexai 2022 年 12 月 29 日
I want to draw a first differential graph and a second differential graph using savitzky golay in the Matlab plot, which code should I use?
Here's an example of a code. x1=[1 2 3 4 5]; x2=[1 5 2 9 4]; x3=[3 2 1 6 4]; y=[500 505 510 515 520]; %this is wavelength plot (y, x1) hold on plot (y, x2) hold on plot (y, x3) I'm going to plot three graphs(x1,x2,x3)

採用された回答

Sai Kiran
Sai Kiran 2022 年 12 月 23 日
Hi,
I understand that you want to calculate the first & second differential using the Savitzky-Golay filter. This can be calculated by the 'sgolayfilt' function.
sgolayfilt(x,order,framelen) where x is an array on which we perform the differential and framelen is the size of the x.
Please refer to the below documentation for more information on sgolayfilt function.
% Load the signal to be filtered
x1 = [1 2 3 4 5];
x2 = [1 5 2 9 4];
x3 = [3 2 1 6 4];
y = [500 505 510 515 520]; % this is the wavelength
% Compute the first derivative of each signal using the Savitzky-Golay filter
dx1 = sgolayfilt(x1, 1, 5);
dx2 = sgolayfilt(x2, 1, 5);
dx3 = sgolayfilt(x3, 1, 5);
% Plot the first derivative of each signal
figure;
plot(y, dx1);
hold on;
plot(y, dx2);
plot(y, dx3);
xlabel('Wavelength');
ylabel('First derivative');
legend('x1', 'x2', 'x3');
% Compute the second derivative of each signal using the Savitzky-Golay filter
ddx1 = sgolayfilt(x1, 2, 5);
ddx2 = sgolayfilt(x2, 2, 5 );
ddx3 = sgolayfilt(x3, 2, 5);
% Plot the second derivative of each signal
figure;
plot(y, ddx1);
hold on;
plot(y, ddx2);
plot(y, ddx3);
xlabel('Wavelength');
ylabel('Second derivative');
legend('x1', 'x2', 'x3');
I hope it resolves your query!! Let me know if you have any questions.
Regards,
Sai Kiran Ratna
  1 件のコメント
Alexai
Alexai 2022 年 12 月 29 日
Thank you so much

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSignal Generation and Preprocessing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by