How to make this signal linear

10 views (last 30 days)
James Adams
James Adams on 20 Feb 2020
Commented: Star Strider on 22 Feb 2020
Here is my code so far on how to produce this plot. Any ideas on how to make this plot linear?
A = dlmread('signal_2.txt'); %Reads signal data file
x= A(:,1); %Time Variables
y= A(:,2); %Amplitude variables
Many Thanks

Accepted Answer

Star Strider
Star Strider on 20 Feb 2020
If you want to eliminate the low-frequency parabolic(?) trend, the easiest way is to use a digital filter:
signal_2 = load('signal_2.txt');
t = signal_2(:,1);
signal = signal_2(:,2);
figure
plot(signal_2(:,1), signal_2(:,2))
grid
xlabel('Time')
ylabel('signal')
L = numel(t);
Ts = mean(diff(t));
Fs = 1/Ts;
Fn = Fs/2;
FTsignal = fft(signal)/L;
Fv = linspace(0, 1, fix(L/2)+1)*Fn;
Iv = 1:numel(Fv);
figure
plot(Fv, abs(FTsignal(Iv))*2)
grid
title('Fourier Transform: ‘signal’')
xlabel('Frequency')
ylabel('Amplitude')
Wp = [25 75]/Fn; % Normailsed Passband (Passband = 25 Hz To 75 Hz)
Ws = [20 80]/Fn; % Normailsed Stopband (Passband = 20 Hz To 80 Hz)
Rp = 1; % Passband Ripple/Attenuation
Rs = 50; % Stopband Ripple/Attenuation
[n,Wp] = ellipord(Wp, Ws, Rp, Rs); % Calculate Elliptic Filter Optimum Order
[z,p,k] = ellip(n, Rp, Rs, Wp,'bandpass'); % Elliptic Filter
[sos,g] = zp2sos(z,p,k); % Second-Order-Section For Stability
Filtered_signal = filtfilt(sos,g,signal); % Filter
figure
plot(t, Filtered_signal)
grid
xlabel('Time')
ylabel('Filtered\_signal')
producing:
This filter also eliminates some of the high-frequency noise as well.

More Answers (1)

James Adams
James Adams on 22 Feb 2020
Thanks for the help, this is really detailed and has helped a lot. :)
  1 Comment
Star Strider
Star Strider on 22 Feb 2020
As always, my pleasure!
The filter eliminates low-frequency baseline drift and all baseline offset, regardless of the nature or shape of the wandering baseline.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!