how to draw a line through points?

hello... I want to plot a line through the points I have plotted.please see the attachment ..I have drawn a line manually just to give u an idea. please let me know if is it possible in Matlab?

 Respuesta aceptada

Star Strider
Star Strider el 21 de Feb. de 2016

0 votos

You will need the Signal Processing Toolbox.
I would first do a fft on your data, to see if your signal can be separated from high-frequency noise. If so, an appropriately-designed lowpass discrete filter would probably work. (My filter design procedure is: How to design a lowpass filter for ocean wave data in Matlab?)
If you have broadband noise that cannot be effectively filtered, with your data, my first approach would be to use the sgolayfilt function to do Savitzky-Golay filtering on it.
All signal processing on actual data requires some experimentation, and the noisier the signal, the more experimentation will be necessary. Be prepared to spend some time processing your data.

8 comentarios

pruth
pruth el 29 de Feb. de 2016
isn't there any one line command... ??? it seems difficult... do u have any idea about running mean or moving average.? please tell me how to use it...thanks for reply.
Star Strider
Star Strider el 29 de Feb. de 2016
There is no one-line command, although you can create your own function comprising all the necessary intermediate commands to create your one-line command.
Analysing data is difficult.
I do not use moving-average filters, since they do not give the specific frequency response characteristics I want from my filters. I would use a low-pass filter, after doing a fft to determine what frequencies are my signals and what are noise, then design the filter to eliminate high-frequency noise (or a bandpass filter if eliminating d-c offset and low-frequency baseline variations are important), with the result being a relatively ‘clean’ signal I can use. I linked to the various functions and procedures in my original Answer, so I will not repeat them here.
pruth
pruth el 29 de Feb. de 2016
ohk sir..thank you for your help and time.
Star Strider
Star Strider el 29 de Feb. de 2016
My pleasure.
If you attach your data file (with time and data vectors, preferably as a .mat file) I will help you design your filter, either a low-pass design or a Savitzky-Golay filter, whichever works best for your signal. (You have to have the Signal Processing Toolbox.)
pruth
pruth el 29 de Feb. de 2016
Editada: pruth el 29 de Feb. de 2016
i don't whether I have this toolbox or not. I am not associated with a license .i have given it by my department.
file attached.please have a look.
You have so many NaN values in your data that I had to remove them and do a linear interpolation to fill them in. I normally avoid that, but doing any signal processing on your data was impossible otherwise.
I was able to do a reasonably decent approximation of the sort of trend curve you want with a low-pass filter. The code is relatively robust, so you can experiment with various values for ‘Wp’ in it without ‘breaking’ it. Please only vary the numerator in ‘Wp’. That is the frequency (in the inverse of whatever units your time vector is in). The denominator ‘Fn’ normalises it to the Nyquist frequency as the Signal Processing Toolbox requires, so please leave that as it is.
I plotted the interpolated data here, but I also plotted the original data, and the approximation looks good with it as well. It’s more difficult to see because of all the NaN values, however.
The code:
D = load('pruth vcdmean.mat');
t = D.vcdmean(:,1);
s = D.vcdmean(:,2);
sm = mean(s, 'omitnan');
tn = t(~isnan(s)); % Remove ‘NaN’ Values
sn = s(~isnan(s));
si = interp1(tn, sn, t, 'linear','extrap'); % Linear Interpolation To Fill ‘NaN’ Values
figure(1)
plot(t, s)
hold on
plot(t, si)
% plot([min(t) max(t)], [1 1]*sm)
hold off
grid
legend('Original Data', 'Interpolated Data')
Ts = mean(diff(t)); % Sampling Interval
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
L = length(t);
fts = fft(si)/L; % Normalised Fourier Transform Of Interpolated Data
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:length(Fv); % Index Vector
figure(2)
semilogy(Fv, abs(fts(Iv))*2) % Plot FFT
grid
axis([0 1 1E+8 1E+12])
Wp = 0.007/Fn; % Passband Frequency
Ws = 2*Wp; % Stopband Frequency
Rp = 1; % Passband Ripple (dB)
Rs = 20; % Stopband Ripple (dB)
[n,Wn] = buttord(Wp,Ws,Rp,Rs); % Optimal Filter Order Calculation
[b,a] = butter(n,Wn); % Calculate Filter Transfer Function Coefficients
[sos,g] = tf2sos(b,a); % Convert To Second-Order-Section For Stability
figure(3)
freqz(sos, 2048, Fs) % Filter Bode Plot To Assess Filter Characteristics & Stability
sif = filtfilt(sos,g,si); % Filter The Signal
figure(4)
plot(t, si) % Plot Original Data
hold on
plot(t, sif, '-r', 'LineWidth',1.5) % Plot Filtered Data
hold off
grid
pruth
pruth el 1 de Mzo. de 2016
omg... hats off to u sir... I didn't know this would be that hard......thank you so much.....to learn this much programming I need to give at least 1 years...anyways answer accepted ..thank you.
Star Strider
Star Strider el 1 de Mzo. de 2016
My pleasure!
I enjoy ‘real world’ data analysis problems, so this was actually fun for me.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 21 de Feb. de 2016

Comentada:

el 1 de Mzo. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by