How do you transfer this signal into linear form?

3 views (last 30 days)
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
Many Thanks!

Accepted Answer

Jon
Jon on 20 Feb 2020
Edited: Jon on 20 Feb 2020
The approach in the earlier post to to remove the linear trend the data was:
% 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)
Looking at your new dataset signal_2.txt, it looks like the data now has a parabolic (quadratic) trend to remove.
You could modify the previous approach to instead fit a quadratic curve to the data and then subtract it off.
% make regression matrix, A where
% y = A*c + error
A = [x(:).^2 x(:) ones(size(x(:)))]
% Find least squares solution (regression) for constants c that provide best fit for
% y = c(1)*x^2 + c(2)*x + c(3) using Matlab \ operator
c = A\y
% remove the quadratic trend from the data
yDetrended = y - A*c % note A*c = (c(1)*x.^2 + c(2)*x + c(3))
figure
% plot the result
plot(x,yDetrended)
p.s. If you have a signal_3.txt that has a cubic trend, I think you can figure out what to do from here :)
  1 Comment
James Adams
James Adams on 20 Feb 2020
Your updated version has helped me very much. Thank you so much. Have a great day :)

Sign in to comment.

More Answers (1)

James Adams
James Adams on 20 Feb 2020
similar to the first task, I must remove the trend from the data file. I'm not sure if there is a trend to remove from signal_2.txt nor do i have any indication of how the graph should look like. I thought to my understanding I must make signal_2.txt be in the same layout as signal_1.txt. Maybe for this task there isn't a trend
what are your thoughts?
I appreciate your time and continued support

Community Treasure Hunt

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

Start Hunting!