how to isolate harmonic component from figure

3 views (last 30 days)
Dear all ,
If I have a signal with harmonic how can I automatical know the index (the position of each number of the harmonic) . In another way , I need to know when the harmonic happens.
The data are in the attachment file

Accepted Answer

Simon Chan
Simon Chan on 15 Mar 2022
Try the following to see whether this is what you want or not.
clear; clc;
x = 1:length(xx);
% Separate entire signal into 3 sections
upperTh = 0.95*max(xx);
lowerTh = 0.95*min(xx);
index = xx<upperTh & xx>lowerTh;
istart = find(diff(index)==1);
iend = find(diff(index)==-1);
profile = arrayfun(@(r,s) xx(r:s),istart,iend,'uni',0); % 3 separate profiles
% Determine the positions of the turning points
[~,idx1] = cellfun(@(x) min(diff(diff(x)>0)),profile);
[~,idx2] = cellfun(@(x) max(diff(diff(x)>0)),profile);
rangeIdx = sort([idx1, idx2],2) + istart;
% Adding some offset besides turning points to find min/max
offset = 5;
harmonic = arrayfun(@(r,s) xx(r-offset:s+offset),rangeIdx(:,1),rangeIdx(:,2),'uni',0);
[maxValue,maxIdx] = cellfun(@max,harmonic);
[minValue,minIdx] = cellfun(@min,harmonic);
% Plot result only (Can be ignored)
for k = 1:3
title({sprintf('MinValue = %.4f, MinPos = %d',minValue(k),rangeIdx(k,1)-offset+minIdx(k)-1);...
sprintf('MaxValue = %.4f, MaxPos = %d',maxValue(k),rangeIdx(k,1)-offset+maxIdx(k)-1)});
grid on
Simon Chan
Simon Chan on 16 Mar 2022
Use another approach to retrieve the positions of the hystersis loops as follows.
After that, you can use the start and end position index for further actions.
clear; clc;
xx = m3rdr(:,1);
yy = m3rdr(:,2);
% Extract the holes from the polygons
pgon = polyshape(xx,yy); % Build the polyshape, ignore the warning
Warning: Polyshape has duplicate vertices, intersections, or other inconsistencies that may produce inaccurate or unexpected results. Input data has been modified to create a well-defined polyshape.
polyout = holes(pgon); % Extract holes which are the hystersis loops
plot(pgon); % Display original signals
ax1 = gca;
title('Original shape');
xLimit = ax1.XLim;
yLimit = ax1.YLim;
plot(polyout); % Display the extracted holes
ax2 = gca;
title('Extract holes coordinates');
ax2.XLim = xLimit;
ax2.YLim = yLimit;
for k = 1:length(polyout)
% Start position of the extarcted hole
xstart = polyout(k).Vertices(1,1);
% End position of the extarcted hole, the last vertice is not used
xend = polyout(k).Vertices(end-1,1);
startIdx = find(xx == xstart);
endIdx= find(xx == xend);
hold on
grid on
plot(xx(startIdx),yy(startIdx),'g*'); % Start point showing green dot
plot(xx(endIdx+1),yy(endIdx+1),'r*'); % Last point showing red dot
title({sprintf('Start Position = %d',startIdx);...
sprintf('End Position = %d',endIdx+1)});
hold off

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!