how to sampling the signal in order to match the two signal?

2 次查看(过去 30 天)
Hi.i am having trouble to set both data (mc & torque) on the same time axis.MC-voltage signal need to sampled at 5 kHz and low-pass filtered with a cutoff frequency 10 Hz in order to match with the torque(maybe).Basically,I need to match the two different time series into one same time series.Hope anyone can help me to figure it out.Thanks in advance

采纳的回答

Star Strider
Star Strider 2021-8-15
The first 2 column in ‘TORQUE’ are missing, so they are removed here.
% C1 = readcell('https://www.mathworks.com/matlabcentral/answers/uploaded_files/711992/TORQUE.txt')
% nrmissing = [nnz(ismissing([C1{:,1}])) nnz(ismissing([C1{:,2}])) size(C1,1)]
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/711992/TORQUE.txt', 'VariableNamingRule','preserve');
T1 = removevars(T1,{'Var1','Var2'})
T1 = 7967×2 table
TIME TORQUE ____ ______ 0 0 10 0.7 20 1.1 30 6.5 40 6.5 50 6.4 60 6.5 70 6.4 80 6.1 90 6.1 100 6.4 110 7.1 120 7.9 130 8.3 140 7.9 150 8
T2 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/712562/MC.txt', 'VariableNamingRule','preserve')
T2 = 90483×2 table
Time MC[v] ________ ______ 0 1.8297 0.000999 1.8289 0.001998 1.8297 0.002997 1.8297 0.003996 1.8305 0.004996 1.8289 0.005996 1.8297 0.006997 1.8313 0.007996 1.8305 0.008995 1.8281 0.009994 1.8297 0.010995 1.8305 0.011994 1.8305 0.012995 1.8297 0.013994 1.8297 0.014993 1.8305
Fs = 100; % Resample To 100 Hz Sampling Frequency
[TORQUEr,T_TIMEr] = resample(T1.TORQUE, T1.TIME, Fs);
[MCvr,V_TIMEr] = resample(T2.('MC[v]')-mean(T2.('MC[v]')), T2.Time, Fs);
MCvr = MCvr + mean(T2.('MC[v]'));
figure
subplot(2,1,1)
plot(T_TIMEr, TORQUEr)
grid
xlabel('t')
ylabel('Torque (Resampled)')
subplot(2,1,2)
plot(V_TIMEr, MCvr)
xlabel('t')
ylabel('MC[v] (Resampled)')
grid
They both have the same 100 Hz sampling frequencies, however they retain significantly different time vectors.
.

更多回答(1 个)

Sulaymon Eshkabilov
% They perfectly match as you can see the plot below.
MC = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/711992/MC.txt');
Torque = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/711992/TORQUE.txt');
plot(MC.TIME, MC.TORQUE, 'bx', Torque.TIME, Torque.TORQUE, 'r'), legend('MC','Torque')
% If you need to resample them then, apply resample()
% See here: https://www.mathworks.com/help/signal/ref/resample.html
  3 个评论
Sulaymon Eshkabilov
Yes, it might be. I've written the code on online here and executed it, rightaway. I have not used a desktop matlab since my matlab license was not activated.
Keshasni Earichappan
hi @Scott MacKenzie & @Sulaymon Eshkabilov....sorry i had attached the wrong MC.txt file jn..here i have attached the updated one..I need to match the two different time series into one same time series(sampling period).Is it possible? :)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by