I am working with sensor signals and finding some problems with signal manipulation .(Any idea /hint /suggestion are welcome as i need something to move forward .
I have chnaged the qurey and added some new and more details to make the question easy to understand.
I have 2 signals.
⦁ Light Pink is the original Signal (refernce signal)with Red dots showing Local maxima’s.
⦁ Blue is a signal which is found after having test from another sensor that looks like refernce sensor but have some faults in it as it is made by us.
⦁ These signals are plotted against time on x-axis.
I have attached some plausible / some part of values of signal here so if anyone can help me with the logic along with MATLAB code it will be of great help.
⦁ Please open the attached link .
⦁ Copy the code written in MATLAB and run after saving it .
⦁ You will see 2 signals as shown in figure and when u will zoom it you will clearly see the difference.
(How to make my Original signal Pink signal Straight as like blue signal in plots)
Question:
⦁ I want to make my original signal (pink) to look alike blue signal interms of flat portion only.
Common behaviour to observe the logic:
⦁ The common behavior that I have seen in my measured signal is that it gets flat where it finds local maxima (either on positive side or negative side).
⦁ At every point in local maxima I see that my blue signal gets flat.
Everything I have to do is with Original signal (Pink signal) to formulate some results.
Is there any way, I can make my original signal flat just like blue signal.
Can someone suggest me the best way to do that? And some one provide me an example MATLAB code then it would be great help .
Please have a look at the picture to get a glimpse about my idea.
Thanks a lot in adavance for help.
I have tried few techniques.
The results of those Techniques are as follows but speaking truly nothing is working for me uptill now.
I have find local maxima values and using nlfilter applied neighborhood rule and tried to make the peaks and neighborhood area flat but unfortunately it is not working as window size is fixed but in my case window size varies and it also depends upon position of local maxima and most important constant window size changes the shape of the signal.
I have also tried to apply varying window but its not working for me may be i have not good concept of how to apply varying size window. I do not know how it will work for my signal.
Cut the long story short what I have done up till now is not working so I need help in that.
It will be really nice if someone provides me how to solve this issue and If i will get some MATLAB so it will great for me.
Thanks a lot in advance for your time ,expertise and help.
Code for running the variables of data in the attached Link:
load originalflatenninrough t original_signal_data measured_Signal_data
[p l] = findpeaks(original_signal_data);
[pn ln] = findpeaks(-original_signal_data);
figure(1)
hold on
plot(t,original_signal_data,'m')
plot(t,measured_Signal_data,'b')
plot(t(l),p,'ko','MarkerFaceColor','r');
plot(t(ln),-pn,'ko','MarkerFaceColor','r');
legend ('originalsignal', 'measureddatasignal')
hold off
Code on Test data example data for NL filter (Which is applied on original signal)
n = 10; % number of values to replace in the neighborhood of a local max
t= 0:0.001:10;
A = sin(2*pi*t);
[pks,locs] = findpeaks(A);
% [pks,locs] = findpeaks(-A);
locs = (locs) ;
locations = zeros(size(A));
locations(locs) = true;
locations = conv(locations, ones(1, 2*n+1), 'same') > 0;
X = -inf(size(A)); % create temporary
X(locs) = A(locs); % copy the local maxima
X = nlfilter(X, [1 2*n+1 ], @(x) max(x)); %replace all values with it local maxima
X(locs) = A(locs); % ensure local maxima are not changed
A(locations) = X(locations); % copy filtered temporary to output
figure()
hold on
plot(t,A,'b')
A = sin(2*pi*t);
plot(t,A,'g')
https://www.mediafire.com/folder/7720j3w7b8pj4/Internet_files