savitzky golay derivation graph plot

11 Ansichten (letzte 30 Tage)
Alexai
Alexai am 15 Dez. 2022
Kommentiert: Alexai am 29 Dez. 2022
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)

Akzeptierte Antwort

Sai Kiran
Sai Kiran am 23 Dez. 2022
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

Weitere Antworten (0)

Kategorien

Mehr zu Signal Generation and Preprocessing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by