Hello everyone,
I've this data (3 forces, a power and a current), that I've imported from a .tdms file.
I need to detect the peaks on the lower peaks which represent the contact between a cutting tool and a workpiece. After escluding the initial and the final zone where the engagement it's not constant, using "getcursormode", I've used this part of code:
avg = mean(-Matrix_Data(trim(1,2)+pre_engag:trim(1,3)-post_engag,2)); % -Matrix_Data for detecting only negative peaks
[pks,locs] = findpeaks(-Matrix_Data(trim(1,2)+pre_engag:trim(1,3)-post_engag,2),'MinPeakHeight',avg,'MinPeakProminence',avg/2.5,'MinPeakDistance',19);
Basically my problem is that the detected peaks are not as perfect as I'd like.
I need to pre-filter the signals for having a better waveform to anlyse later. Any suggestions? I haven't the particular need of cutting any frequence but I'd have a filter that would allow me to follow existing data very precisely by eliminating any very close peaks. It's also possible to change the findpeaks parameter but I've already tried all the possible combinations.
Thank you some much for anyone will help me.

4 Commenti

Yazan
Yazan il 9 Ago 2021
The peaks of which column of your data do you need to detect?
riccardo favaro
riccardo favaro il 9 Ago 2021
column 2
Yazan
Yazan il 9 Ago 2021
Can you indicate which peaks we're talking about here?
Star Strider
Star Strider il 9 Ago 2021
The peaks are more apparent in the filtered signnal in Column #3, as I filtered them.

Accedi per commentare.

 Risposta accettata

Star Strider
Star Strider il 9 Ago 2021
Modificato: Star Strider il 9 Ago 2021
First, the data are really noisy, and exhibit broadband noise that will be impossible to eliminate with a frequency-selective filter. The posted code fails because the variables are not provided.
I mamaged to use the Savitzky-Golay filter on the first 3 signals, however it is not doing much for the last 2.
LD = load('data.mat');
Matrix_Data = LD.Matrix_Data;
Ts = mean(diff(Matrix_Data(:,1)));
Tsd = std(diff(Matrix_Data(:,1)));
sm = Matrix_Data(:,2:end) - mean(Matrix_Data(:,2:end));
np = size(Matrix_Data,2)-1;
figure
for k = 1:np
subplot(np,1,k)
plot(Matrix_Data(:,1), sm(:,k))
grid
end
sgtitle('Original Data')
figure
tic;
for k = 1:np
fprintf('\tk = %d\n',k)
subplot(np,1,k)
smfilt = sgolayfilt(sm(:,k), 3, 501);
plot(Matrix_Data(:,1), smfilt)
% plot(Matrix_Data(:,1), sm(:,np))
grid
toc
end
sgtitle('Savitzky-Golay Filtered Data')
L = size(Matrix_Data,1);
Fs = 1/Ts;
Fn = Fs/2;
NFFT = 2^nextpow2(L);
sm = Matrix_Data(:,2:end) - mean(Matrix_Data(:,2:end));
FTs = fft(sm,NFFT)/L;
Fv = linspace(0, 1, NFFT/2+1)*Fn;
Iv = 1:numel(Fv);
np = size(FTs,2);
figure
for k = 1:size(FTs,2)
subplot(np, 1, k)
plot(Fv, 20*log10(abs(FTs(Iv,k))*2))
grid
ylim([-150, 0])
end
sgtitle('Fourier Transforms of Original Data')
I have no idea what peaks need to be detected, however the result of the Savitzky-Golay filtering step should make that a bit easier. I did not save the ‘smfilt’ results to a matrix, so it might be necessary to add that if desired:
smfilt(:,k) = sgolayfilt(sm(:,k), 3, 501);
plot(Matrix_Data(:,1), smfilt(:,k))
The rest of the code is unchanged.
EDIT — (9 Aug 2021 at 16:15)
Added the ‘Savitzky-Golay Filtered Data’ plot this code produced —
.

5 Commenti

riccardo favaro
riccardo favaro il 9 Ago 2021
it already gives me an error in line 3:
"Array indices must be positive integers or logical values.
Error in 'name' (line 3)
Ts = mean(diff(Matrix_Data(:,1)));"
Yazan
Yazan il 9 Ago 2021
Make sure to clear previous variables from the workspace. The code works just fine.
Star Strider
Star Strider il 9 Ago 2021
@riccardo favaro I cannot improve on Yazan’s suggestion.
@Yazan Thank you!
.
riccardo favaro
riccardo favaro il 9 Ago 2021
yeah, now it works. But actually it doesn't solve my entire problem. Nevermind.
Thank you all
Yazan
Yazan il 9 Ago 2021
To get better help or suggestions from the community, you need to improve your description of the problem at hand in my opinion.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by