how to make smooth the vertcat of more vectors

3 views (last 30 days)
matteo bottoni on 19 Nov 2020
Commented: matteo bottoni on 19 Nov 2020
If I try to concatenate and plot all my vectros of different size (each one rapresents a big and small wave) the result is that in the image. What I want is that in the blue circles there is no a discontinuity.

matteo bottoni on 19 Nov 2020
Hi Mathieu, thanks a lot for the help. I have to ask u another stuff: i am shame to say you that I didn't understand completly the use of this code. Where and how do i have to insert my data?
Mathieu NOE on 19 Nov 2020
here you are. Don't be ashamed, every body has to start some day
x = 1:numel(y);
N = 30; % nb of samples for averaging
% sliding avg method
out = myslidingavg(y, N);
figure(2),
plot(x,y,'b',x,out,'r');
function out = myslidingavg(in, N)
% OUTPUT_ARRAY = MYSLIDINGAVG(INPUT_ARRAY, N)
%
% The function 'slidingavg' implements a one-dimensional filtering, applying a sliding window to a sequence. Such filtering replaces the center value in
% the window with the average value of all the points within the window. When the sliding window is exceeding the lower or upper boundaries of the input
% vector INPUT_ARRAY, the average is computed among the available points. Indicating with nx the length of the the input sequence, we note that for values
% of N larger or equal to 2*(nx - 1), each value of the output data array are identical and equal to mean(in).
%
% * The input argument INPUT_ARRAY is the numerical data array to be processed.
% * The input argument N is the number of neighboring data points to average over for each point of IN.
%
% * The output argument OUTPUT_ARRAY is the output data array.
if (isempty(in)) | (N<=0) % If the input array is empty or N is non-positive,
disp(sprintf('SlidingAvg: (Error) empty input data or N null.')); % an error is reported to the standard output and the
return; % execution of the routine is stopped.
end % if
if (N==1) % If the number of neighbouring points over which the sliding
out = in; % average will be performed is '1', then no average actually occur and
return; % OUTPUT_ARRAY will be the copy of INPUT_ARRAY and the execution of the routine
end % if % is stopped.
nx = length(in); % The length of the input data structure is acquired to later evaluate the 'mean' over the appropriate boundaries.
if (N>=(2*(nx-1))) % If the number of neighbouring points over which the sliding
out = mean(in)*ones(size(in)); % average will be performed is large enough, then the average actually covers all the points
return; % of INPUT_ARRAY, for each index of OUTPUT_ARRAY and some CPU time can be gained by such an approach.
end % if % The execution of the routine is stopped.
out = zeros(size(in)); % In all the other situations, the initialization of the output data structure is performed.
if rem(N,2)~=1 % When N is even, then we proceed in taking the half of it:
m = N/2; % m = N / 2.
else % Otherwise (N >= 3, N odd), N-1 is even ( N-1 >= 2) and we proceed taking the half of it:
m = (N-1)/2; % m = (N-1) / 2.
end % if
for i=1:nx, % For each element (i-th) contained in the input numerical array, a check must be performed:
dist2start = i-1; % index distance from current index to start index (1)
dist2end = nx-i; % index distance from current index to end index (nx)
if dist2start<m || dist2end<m % if we are close to start / end of data, reduce the mean calculation on centered data vector reduced to available samples
dd = min(dist2start,dist2end); % min of the two distance (start or end)
else
dd = m;
end % if
out(i) = mean(in(i-dd:i+dd)); % mean of centered data , reduced to available samples at both ends of the data vector
end % for i
end
matteo bottoni on 19 Nov 2020
very nice. Thanks you a lot

Star Strider on 19 Nov 2020
Edited: Star Strider on 19 Nov 2020
I am not certain what you want, since the posted file is not the same as the posted plot image.
Try this:
x = 1:numel(y);
Mxv = find(islocalmax(y, 'MinProminence',10, 'MinSeparation',200)); % Indices Of Maxima
for k = 1:numel(Mxv)-1
[minval(k),idx(k)] = min(y(Mxv(k):Mxv(k+1))); % Select Minimum Between Adjacent Maxima
idx(k) = idx(k) + Mxv(k);
end
figure
plot(x,y)
hold on
plot(x(idx), y(idx), 'vr')
plot(x(Mxv), y(Mxv), '^r')
hold off
grid
txtc = sprintfc('x = %4d\ny = %7.3f\n\\downarrow',[x(idx); y(idx)']');
text(x(idx), y(idx)+1, txtc, 'HorizontalAlignment','center', 'VerticalAlignment','bottom')
legend('Data', 'Desired Minima',' Maxima', 'Location','E')
EDIT — (19 Nov 202 at 13:54)
Added text call and plot image. Code otherwise unchanged.
.

Star Strider on 19 Nov 2020
Filter it:
x = 1:numel(y);
Fs = 1;
Fn = Fs/2;
L = numel(y);
FTy = fft(y)/L;
Fv = linspace(0, 1, fix(L/2)+1)*Fn;
Iv = 1:numel(Fv);
figure
plot(Fv, abs(FTy(Iv))*2)
grid
xlim([0 0.1])
yfilt = lowpass(y, 0.005, Fs);
figure
subplot(2,1,1)
plot(x, y)
title('Original Signal')
grid
subplot(2,1,2)
plot(x, yfilt, '-r')
title('Lowpass-Filtered Signal')
grid
producing:
.
matteo bottoni on 19 Nov 2020
thank you a lot
Star Strider on 19 Nov 2020
As always, my pleasure!

Community Treasure Hunt

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

Start Hunting!

Translated by