B1*B2.Now overlay B2 on to of B1 so the B2 starts at the first point in B1 and multiply the blocks and sum the result. Store it. Just sum the result of B1*B2 and exclude the rest of B1.
clear all;
close all;
clc;
length = 100;
period = 20;
y = CreateMoon(length, 1, 100, period);
Pereborka(y);
function [ y ] = sinus( len, phase, amp, per)
radiansPerDot = ( pi * 2 ) / per;
phase = phase * radiansPerDot;
radians = (0:len-1) * radiansPerDot;
y = amp * sin(radians + phase);
end
function [ ] = Pereborka( y )
B1 = y;
max_MultySum = 0;
max_Pos = 0;
max_Phase = 0;
max_Len = 0;
wb = waitbar(0, 'Working...');
valuesLength = length(y);
% curPosB2 - current position of B2
% curPerB2 - current period of B2
% curAmplB2 - current amplitude of B2
% curPhaseB2 - current phase of B2
curAmplB2 = 1;
%P4
for curPerB2 = 1 : valuesLength
waitbar(curPerB2 / valuesLength, wb);
%P3
for curLenB2 = 1 : valuesLength
%P2
for curPhaseB2 = 1 : valuesLength
%P1
for curPosB2 = 1 : valuesLength
if(curPosB2 + curLenB2 - 1 > valuesLength)
break;
end;
curB2 = sinus( curLenB2, curPhaseB2, curAmplB2, curPerB2);
part_B1 = B1(curPosB2:curPosB2+curLenB2-1);
multySum = sum(curB2.*part_B1);
if(max_MultySum < multySum)
max_MultySum = multySum;
max_Pos = curPosB2;
max_Phase = curPhaseB2;
max_Len = curLenB2;
end;
end;
end;
end;
end;
delete(wb);
disp(['max_MultySum = ', num2str(max_MultySum)]);
disp(['max_Pos = ', num2str(max_Pos)]);
disp(['max_Phase = ', num2str(max_Phase)]);
disp(['max_Len = ', num2str(max_Len)]);
B2 = sinus( max_Len, max_Phase, curAmplB2, curPerB2);
figure()
hold on;
plot(B1);
plot(max_Pos:max_Pos+max_Len-1, B2, 'Color', 'Red');
title(num2str(max_MultySum));
end
I did not change the amplitude, because I could not wait to end the program. But to solve my problem, I must calculate the amplitude.OK I have a manual and the process looks good, I dont beleive that changing amplitude is neceassry, just use a typical level as all it will do is scale the results.
If period = 100 thenYou should store all the multysum results into an array and then look at the array and see where things go wrong
Result:
I did not change the amplitude, because I could not wait to end the program. But to solve my problem, I must calculate the amplitude.
If period = 100 then
sum(B1.*B2) = 50
if period = 20 then
sum(B1.*B2) = 50
In fact, both versions give the same result. But on the chart there is only one. Therefore, such a result is obtained.
I'm working on keeping all sinusoids in the matrix. And to build the surfaces.
function [ ] = Pereborka( y )
B1 = y;
max_MultySum = 0;
max_Pos = 0;
max_Phase = 0;
max_Len = 0;
max_Per = 0;
wb = waitbar(0, 'Working...');
valuesLength = length(y);
% curPosB2 - current position of B2
% curPerB2 - current period of B2
% curAmplB2 - current amplitude of B2
% curPhaseB2 - current phase of B2
curAmplB2 = 1;
%P4
for curPerB2 = 1 : valuesLength
waitbar(curPerB2 / valuesLength, wb);
%P3
for curLenB2 = 1 : valuesLength
%P2
for curPhaseB2 = 1 : valuesLength
%P1
for curPosB2 = 1 : valuesLength
if(curPosB2 + curLenB2 - 1 > valuesLength)
break;
end;
curB2 = sinus( curLenB2, curPhaseB2, curAmplB2, curPerB2);
part_B1 = B1(curPosB2:curPosB2+curLenB2-1);
multySum = sum(abs(curB2.*part_B1));
if(max_MultySum < multySum || (max_MultySum == multySum && max_Len < curLenB2))
max_MultySum = multySum;
max_Pos = curPosB2;
max_Phase = curPhaseB2;
max_Len = curLenB2;
max_Per = curPerB2;
end;
end;
end;
end;
end;
delete(wb);
disp(['max_MultySum = ', num2str(max_MultySum)]);
disp(['max_Pos = ', num2str(max_Pos)]);
disp(['max_Phase = ', num2str(max_Phase)]);
disp(['max_Len = ', num2str(max_Len)]);
B2 = sinus( max_Len, max_Phase, curAmplB2, max_Per);
figure()
hold on;
plot(B1);
plot(max_Pos:max_Pos+max_Len-1, B2, 'Color', 'Red');
title(num2str(max_MultySum));
end
function [ ] = bruteforce( y )
B1 = y;
max_MultySum = 0;
max_Pos = 0;
max_Phase = 0;
max_Len = 0;
max_Per = 0;
wb = waitbar(0, 'Working...');
valuesLength = length(y);
% curPosB2 - current position of B2
% curPerB2 - current period of B2
% curAmplB2 - current amplitude of B2
% curPhaseB2 - current phase of B2
curAmplB2 = 1;
%P4
for curPerB2 = 1 : valuesLength
waitbar(curPerB2 / valuesLength, wb);
%P3
for curLenB2 = 1 : valuesLength
%P2
for curPhaseB2 = 1 : valuesLength
%P1
for curPosB2 = 1 : valuesLength
if(curPosB2 + curLenB2 - 1 > valuesLength)
break;
end;
curB2 = sinus( curLenB2, curPhaseB2, curAmplB2, curPerB2);
part_B1 = B1(curPosB2:curPosB2+curLenB2-1);
multySum = sum(curB2.*part_B1);
if(max_MultySum < multySum || (max_MultySum == multySum && max_Len < curLenB2))
max_MultySum = multySum;
max_Pos = curPosB2;
max_Phase = curPhaseB2;
max_Len = curLenB2;
max_Per = curPerB2;
end;
end;
end;
end;
end;
delete(wb);
disp(['max_MultySum = ', num2str(max_MultySum)]);
disp(['max_Pos = ', num2str(max_Pos)]);
disp(['max_Phase = ', num2str(max_Phase)]);
disp(['max_Len = ', num2str(max_Len)]);
disp(['max_Per = ', num2str(max_Per)]);
B2 = sinus( max_Len, max_Phase, curAmplB2, max_Per);
figure()
hold on;
plot(B1);
plot(max_Pos:max_Pos+max_Len-1, B2, 'Color', 'Red');
title(num2str(max_MultySum));
end
clear all;
close all;
clc;
y = CreateMoon(70, 1, 100, 35);
y = CreateMoon(70, 1, 100, 10);
bruteforce(y);
max_MultySum = 36.5255
max_Pos = 1
max_Phase = 4
max_Len = 70
max_Per = 38
Why? The program has found incorrect sinusoid. And if I subtract it from the original signal and run the program again, I get a second incorrect sinusoid.Now subtract the signal from moon and do the process again to find the second frequency.
Could you tell me about these tweaks?The method is very exact but does require some manipulation and code tweaks to make it work well
I think that we need the maximum peak. And it usually a single.Cant understand why but you calculate one maxsum whilst I store the whole array and look at the peaks so I see all the peaks and you only get one
But how do I calculate the phase of the length and position?Next I would put the results into a matrix Result(position,Length) and you could use two matices for the frequency and the phase or combine it as a complex number.
I do not understand how anyone can build a graph, where one of the axes - a complex number.A(x,y,z) where x is the position, y is the length and z is the complex representation of B1 for those parameters.
x = [1, 2, 3, 4, 5, 6, 7, 8, 9]
y = x;
plot(x, y);
x = [1 + 1j, 2 + 1j, 3 + 1j, 4 + 1j, 5 + 1j, 6 + 1j, 7 + 1j, 8 + 1j, 9 + 1j]
y = x;
plot(x, y);
Warning: Imaginary parts of complex X and/or Y arguments ignored
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
y = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
A = [];
for xi =1:length(x)
for yi =1:length(y)
A(xi, yi) = x(xi) + y(yi);
end;
end;
mesh(A);
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?