# Finding peak value of distorted sine wave signal with varying phase shift of harmonics

10 views (last 30 days)

Show older comments

Haroon Zafar
on 18 Mar 2022

Answered: David Goodmanson
on 20 Mar 2022

I am trying to simulate effect of phase angle variation of harmonic on peak value of the fundamental signal.

My harmonics are ranging from fundamental to 21storder. At the moment I am studying impact of each harmonic order individually. For each harmonic order , I am varying phase angle form 0 degree to 359 degree and reading the peak of the signal ( as can be seen in code) and storing the angle corresponding to maximum and minimum peak values. Code is for 5th harmonic only but I want to extend it to do same thing for all 21 harmoics and storeresults in a table.

clear all

clc

f=50; %frequency [Hz]

a1=10; %amplitude fundamental

phi1=0; %phase fundamental

a2=1; %amplitude of harmonic [V]

phi2=0:1:360; %phase harmonic

t=0:1/1e6:0.02;

y_fund=a1*sin(2*pi*f*t+phi1);

for i= 1:length(phi2)

y_5h=a2.*sin(2*pi*5*f*t+phi2(i)*pi/180);

Total_sig= y_fund+y_5h; %Total signal generation

hold on

plot(t,y_fund,t,y_5h,t,Total_sig)

peak_Total_signal(i) = max(Total_sig); % saving peak values to array

end

max_val = max(peak_Total_signal); % finding maximum of all peak values

min_val = min(peak_Total_signal); % finding min. of all peak values

idx_max = find(peak_Total_signal==max_val);

idx_min = find(peak_Total_signal==min_val);

phase_max= phi2(idx_max); % finding phase angle corresponding to max peak value

phase_min= phi2(idx_min); % finding phase angle corresponding to min peak value

array= table(max_val,phase_max, min_val,phase_min)

My problems are:

Q1: Though I am able to find peaks in waveform, But I alos want to find the valley point in the waveform as shown in figure ( only shown for 5thharmonic 180 degree pahse) below for each of the 0:360 angles.

Q2: I want to find the phase angle at which maximum shift in Zero crossing from the fundamental point (0.01 sec in figure) occurs, as shown by double arrows in figure. I have to do it for 21 harmonic signals.

Q3: I have to do it for 21 harmonics, considering all together at the same time. But it would be very inefficient to use for loops as there would be 21 nested for loops each varying from 0 to 360 degrees.

Is there any other approach to find the combination of phase angles for all 21 harmonics at which maximum and minimum peak is obtained and max. positive and max negative shift in zero-crossing occurs.

Help on any of the above questions would be precious for me.

Thanks

##### 0 Comments

### Accepted Answer

David Goodmanson
on 20 Mar 2022

Hello Haroon,

This answer addresses the first part, getting a maximum or "minimum-at-maximum" value. It's a lot easier to do this problem in terms of cosines instead of sines. If you have an answer in terms of cosine, then you can find the answer for sine with

cos(2*pi*f*n+t + phi_n) = sin(2*pi*f*n+t + [phi_n + pi/2] )

so <phi_n for sine> is just <phi_n for cos> + 90 degrees.

Cos maxes out at t = 0 and it's clear that you can get a max for the sum of all the terms simply by putting the value 1 for each of the cosines to be at the origin. For cos(2*pi*f*n+t + phi_n) that happens when phi_n is zero, so the phase angle for each of the 21 harmonics is zero. The sum of the whole works is Sum {n=1,21} a_n. For "minimum-at-maximum", set the phases of all the harmonics (not the fundamental) to pi = 180 degrees. Then the cosine for each of the harmonics has value -1 at t = 0 and the sum is a_1 - Sum {n=2,21} a_n.

The zero crossing part is definitely harder.

##### 0 Comments

### More Answers (1)

Image Analyst
on 19 Mar 2022

So just put that in a loop over all 21 harmonics.

##### 2 Comments

Image Analyst
on 20 Mar 2022

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!