MATLAB Answers

How do you separate imported data into time and amplitude?

3 ビュー (過去 30 日間)
James Adams
James Adams 2020 年 2 月 19 日
コメント済み: James Adams 2020 年 2 月 20 日
%%i have imported notepad data into matlab, having difficulty seperating the data into seperate arrays. Any help?

  5 件のコメント

表示 2 件の古いコメント
James Adams
James Adams 2020 年 2 月 19 日
Do you also know any information on how to detrend data without using the built in function?
Many Thanks
Jon
Jon 2020 年 2 月 19 日
I don't see any problems with the code you wrote. I also confirmed that it ran OK. I think the pproach you have taken seems fine so far. Now was there something more that you were trying to do which you got stuck on?
James Adams
James Adams 2020 年 2 月 19 日
I now need to remove the trend from the data, without using the 'detrend' function that is on matlab.
Do you have idea on how to approach this? Below is a code that I was told to use, but I am not sure if this is correct.
plot(x,y - mean(y));
Could you confirm if this is true?
Many Thanks Jon

サインイン to comment.

採用された回答

Jon
Jon 2020 年 2 月 19 日
編集済み: Jon 2020 年 2 月 19 日
If by detrend you mean that you want to remove the part of the signal that is growing linearly with time then the expression you have will not work. It will just shift your whole plot horizontally, so that it is centered on the mean value for the whole series.
Instead you can do a little linear regression to find the best straight line (y = mx + b) through the data, and then subtract that off.
To do this in MATLAB you could use:
% make regression matrix, A where
% y = A*c + error
A = [x(:) ones(size(x(:)))]
% Find least squares solution (regression) for constants c that provide best fit for
% y = c(1)*x + c(2) using Matlab \ operator
c = A\y
% remove the linear growth (detrend) the data
yDetrended = y - (c(1)*x + c(2))
% plot the result
plot(x,yDetrended)
Here is a good link to learn more about the linear regression, https://www.mathworks.com/help/matlab/data_analysis/linear-regression.html

  1 件のコメント

James Adams
James Adams 2020 年 2 月 20 日
Thank you very much for you support Jon.
I am now having trouble doing the same technqiue on a slightly different graph. Similar to the first signal, my starting code is below. I must now convert this signal and make it linear. Any ideas on how to achieve this??
A = dlmread('signal_2.txt'); %Reads signal data file
x= A(:,1); %Time Variables
y= A(:,2); %Amplitude variables
Many Thanks

サインイン to comment.

その他の回答 (0 件)

サインイン してこの質問に回答します。


Translated by