How to Calculate Relative Power Using Fourier Coefficients in Matlab?

In summary, the sums of power in harmonics 1-3, 1-9, and 1-29 for signal x1 are calculated by evaluating the Fourier coefficients, and the relative power in these harmonics is determined by dividing the sum of power by the total power in the original signal x1.
  • #1
Kipster1203
9
0
I have the following code

Matlab:
dt = 0.01;                                % Set the time increment to 0.02 second.

t = (0:1:199)*dt;                      % Create a time array.

x1 = 0.5*square(pi*t);               % Use MATLAB to create the signal

                                              % amplitude +/- 0.5 and period 2.

subplot(2,1,1),plot(t,x1), axis([0,2.1,-0.6,0.6]);

x2 = zeros(1,length(x1));            % Define an empty column vector for the

                                              % triangle function.

                                              % Use a discrete approximation to the integral of the square

                                              % wave to create the triangular signal.

x2(1) = -0.25;

for i = 2:200; x2(i) = x2(i-1) + x1(i)*dt; end

subplot(2,1,2),plot(t,x2), axis([0,2.1,-0.6,0.6]);

I need to calculate the sums of the power (by evaluating the Fourier coefficients) in harmonics 1 - 3, 1 - 9, and 1 - 29 for signal x1 relative to the total power in the original signal x1.
Can anyone help me out??
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
The sum of the power in harmonics 1-3 is given by:P1_3 = (1/length(x1))*sum((abs(fft(x1)).^2).*(abs(fft(x1))>0.5));The sum of the power in harmonics 1-9 is given by:P1_9 = (1/length(x1))*sum((abs(fft(x1)).^2).*(abs(fft(x1))>1.5));The sum of the power in harmonics 1-29 is given by:P1_29 = (1/length(x1))*sum((abs(fft(x1)).^2).*(abs(fft(x1))>4.5));The total power in the original signal x1 is given by:Ptotal = (1/length(x1))*sum(abs(fft(x1)).^2);The relative power in harmonics 1-3, 1-9 and 1-29 is then given by: RelP1_3 = P1_3/Ptotal;RelP1_9 = P1_9/Ptotal;RelP1_29 = P1_29/Ptotal;
 
  • #3


Sure, I can help you out with calculating the relative power using Matlab. First, let's define the Fourier coefficients for the signal x1. We can use the fft function in Matlab to calculate the discrete Fourier transform:

X1 = fft(x1);

Next, we need to calculate the power for each harmonic using the formula P = |c|^2, where c is the Fourier coefficient for that harmonic. We can do this using a for loop:

% Initialize an empty vector for storing the power values
power = zeros(1,29);

% Loop through each harmonic
for n = 1:29
% Calculate the power for the nth harmonic
power(n) = abs(X1(n))^2;
end

Now, we can calculate the total power in the original signal x1 by summing up all the power values:

total_power = sum(power);

To calculate the relative power for each harmonic, we can divide the power value for that harmonic by the total power:

% Initialize an empty vector for storing the relative power values
relative_power = zeros(1,29);

% Loop through each harmonic
for n = 1:29
% Calculate the relative power for the nth harmonic
relative_power(n) = power(n) / total_power;
end

To calculate the sums of the power for harmonics 1-3, 1-9, and 1-29, we can simply sum up the corresponding values in the relative_power vector:

% Sum of the power for harmonics 1-3
sum_power_1_3 = sum(relative_power(1:3));

% Sum of the power for harmonics 1-9
sum_power_1_9 = sum(relative_power(1:9));

% Sum of the power for harmonics 1-29
sum_power_1_29 = sum(relative_power(1:29));

I hope this helps! Let me know if you have any further questions.
 

1. What is Relative Power in Matlab?

Relative Power is a measure of the strength or magnitude of a signal in comparison to a reference signal. In Matlab, it is calculated using the Power Spectral Density (PSD) function, which takes into account both the amplitude and frequency of a signal.

2. How is Relative Power used in data analysis?

Relative Power is commonly used in data analysis to compare different signals or frequency bands within a single signal. It can also be used to identify changes in the power of a signal over time, which can be useful in studying trends or patterns in data.

3. What is the advantage of using Matlab for Relative Power analysis?

Matlab has a built-in PSD function that makes calculating Relative Power quick and easy. It also has a variety of tools and functions for data visualization and analysis, which can aid in interpreting and understanding the results of Relative Power analysis.

4. Can Relative Power be used for non-electrical signals?

Yes, Relative Power can be used for any type of signal that can be represented in a frequency domain. This includes not only electrical signals, but also biological signals such as EEG or ECG, as well as signals from other types of data such as stock market trends or weather patterns.

5. How can Relative Power be used in signal processing applications?

Relative Power can be used in signal processing applications to filter out noise or unwanted frequencies from a signal. By comparing the power of different frequency bands, a specific frequency range can be isolated and extracted from a signal, allowing for more accurate analysis and interpretation of the data.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
997
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
745
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
Back
Top