savitzky golay derivation graph plot
7 次查看(过去 30 天)
显示 更早的评论
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)
0 个评论
采纳的回答
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Signal Generation and Preprocessing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!