3 views (last 30 days)

Show older comments

Muhammad Hamza on 16 Mar 2023

Commented: Muhammad Hamza on 4 Apr 2023

Accepted Answer: Muhammad Hamza

Hello,

I am using fft to find amplitude of current and amplitude of voltage seperately.And then using angle command to determine angles of them respectively.But now I want to find Angle of Impedence as well,For that I am dividing the voltage amplitude by current amplitude and fortunately getting the correct impedence as well.But after that when i try to find the angle of Impedence I am not getting the correct angle.Could some body tell me why I am not getting the correct angle?.What is the problem or what should i need to do?. Thanks in advance.

For Example.

Impedence=(AmplitudeV/AmplitudeI);

Theta=angle(Impedence);

Is it the correct way to find Impedence using fft?

Please note that I am a new user of MATLAB,So apologies in advance if you feel that question is very basic.

##### 7 Comments Show 5 older commentsHide 5 older comments

Show 5 older commentsHide 5 older comments

Mathieu NOE on 16 Mar 2023

#### Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/1929955-how-to-find-angle-of-impedence#comment_2664510

Edited: Mathieu NOE on 16 Mar 2023

hello

doing a impedance measurement (or simulation) is basically making a transfer function estimate between your current and voltage

you can use the matlab function tfestimate for that (Signal Processing Toolbox required)

Transfer function estimate - MATLAB tfestimate - MathWorks France

the test signal must cover the entire frequency range of interest (chirp or random signals are the two most common used)

the result is a complex FRF (frequency response function) , you will take the amplitude and phase of it (with abs and angle functions)

Muhammad Hamza on 20 Mar 2023

#### Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/1929955-how-to-find-angle-of-impedence#comment_2668915

- Angle.PNG

Hello Mathieu, Thank you for your explanation,I implemented this but unfortunately the same result,I got the amplitude correct but not the angle,Now I have analized the data and I noticed that I always got 0 or 180 angle in degrees Because of the real and non real values of my angle.Please see the attachment.

May be this is the reason that when I am trying to find the angle I get 0 or 180(depends on the data) at the point of my desired Impedence value.Else all the other values of my data are giving the correct angle.It is happening might be due to the fact that for Impedence it is dividing the peak voltage amplitude by peak current amplitude of all my 129 sample values and gives the correct angle and it gives angle 0 or 180 where i got the exact required Impedence value which is actually the division of peak values of both.

OR May be I should try to do signal reconstruction and try to find angle and impedence,If fft doesnot work for me in that case? Or else I come to know what i am doing wrong actually. Thanks in advance.

Mathieu NOE on 20 Mar 2023

#### Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/1929955-how-to-find-angle-of-impedence#comment_2668935

hello

I am still unsure what your are doing and how you do the phase computation

are you doing it by using angle(fft(Voltage)./fft(current)) ?

Muhammad Hamza on 20 Mar 2023

#### Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/1929955-how-to-find-angle-of-impedence#comment_2669170

Hi Mathieu,

Impedence=(VoltageAmplitude./CurrentAmplitude)

Theta=angle(FFTvoltage./FFTCurrent)

AND WITH tfestimate I am doing like this below

estimatetesting=tfestimate(MEANCURRENTWITHDELAY,MEANVOLTAGEWITHDELAY)

itsangle=angle(estimatetesting);

itsangleinDegrees=rad2deg(itsangle)

itsamplitude=abs(estimatetesting)

Mathieu NOE on 20 Mar 2023

#### Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/1929955-how-to-find-angle-of-impedence#comment_2669420

ok

and you get now the right angle ?

Muhammad Hamza on 20 Mar 2023

#### Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/1929955-how-to-find-angle-of-impedence#comment_2669500

No still not getting the correct angle.Tried both methods but same result,Getting the desired impedence but not the desired angle,Please see my above detailed explanation again. Thanks

Star Strider on 20 Mar 2023

#### Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/1929955-how-to-find-angle-of-impedence#comment_2669580

Open in MATLAB Online

@Muhammad Hamza —

I am not certain what you are actually doing.

Consider something like this —

Fs = 1000; % Sampling Frequency (Hz)

t = linspace(0,10*Fs-1,10*Fs).'/Fs; % Assume Column Vectors

% Check = 1/(t(2)-t(1))

Fr = 250; % Signal Frequency

I = sin(2*pi*Fr*t); % Current Signal

V = 10*cos(2*pi*Fr*t); % Voltage Signal

Fn = Fs/2; % Nyquist Frequency (Hz)

L = numel(t); % Signal Length

NFFT = 2^nextpow2(L); % For Efficiency

FT_V = fft(V.*hann(L), NFFT)/L; % Voltage Fourier Transform (Windowed)

FT_I = fft(I.*hann(L), NFFT)/L; % Current Fourier Transform (Windowed)

Fv = linspace(0, 1, NFFT/2+1)*Fn; % Frequency Vector (One-Sided Fourier Transfomr)

Iv = 1:numel(Fv); % Index Vector (For Convenience)

figure

subplot(2,1,1)

plot(Fv, abs(FT_V(Iv))*2)

grid

ylabel('Magnitude')

subplot(2,1,2)

plot(Fv, rad2deg(angle(FT_V(Iv))))

grid

ylabel('Phase (°)')

sgtitle('Voltage')

figure

subplot(2,1,1)

plot(Fv, abs(FT_I(Iv))*2)

grid

ylabel('Magnitude')

subplot(2,1,2)

plot(Fv, rad2deg(angle(FT_I(Iv))))

grid

ylabel('Phase (°)')

sgtitle('Current')

FT_Z = FT_V ./ FT_I;

figure

subplot(2,1,1)

plot(Fv, abs(FT_Z(Iv))*2)

grid

ylabel('Magnitude')

subplot(2,1,2)

plot(Fv, rad2deg(angle(FT_Z(Iv))))

grid

ylabel('Phase (°)')

sgtitle('Impedence')

Windowing the Fourier transform reduces the amplitude of the resulting peaks by ½.

.

Sign in to comment.

Sign in to answer this question.

### Accepted Answer

Muhammad Hamza on 4 Apr 2023

Hello Everyone,

My problem was solved sorry for informing late.

Many thanks to @Mathieu NOE @Star Strider @Swaraj

Best Regards,

Muhammad Hamza.

##### 3 Comments Show 1 older commentHide 1 older comment

Show 1 older commentHide 1 older comment

Mathieu NOE on 4 Apr 2023

#### Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/1929955-how-to-find-angle-of-impedence#comment_2689764

Good news !!

Star Strider on 4 Apr 2023

#### Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/1929955-how-to-find-angle-of-impedence#comment_2689949

What was the solution?

Muhammad Hamza on 4 Apr 2023

#### Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/1929955-how-to-find-angle-of-impedence#comment_2690109

There wee two things which I corrected,

1)The reference data I was working on was not accurate enough especially with floating numbers,Matlab by default showed me 4 digits after decimal so I have to change it to long g to get more precise results.

2)Another problem was solved by subtracting my angle values from 180,I guess the reason I found is that Matlab was returning me pi when I have negative real numbers and 0 when I have non negative real numbers.

Sign in to comment.

### More Answers (1)

Swaraj on 4 Apr 2023

You should take into consideration that there can be phase difference between the voltage and the current signals. One way is to use the complex Impedance Formula. It can be calculated as the ratio of the complex Voltage to Complex Current.

Z = V/I

Here V and I are Complex Numbers.

Then try using the angle function as “angle(Z)”.

Phase angle - MATLAB angle (mathworks.com)

##### 0 Comments Show -2 older commentsHide -2 older comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

### See Also

### Categories

Signal ProcessingSignal Processing ToolboxSpectral AnalysisSpectral Measurements

Find more on **Spectral Measurements** in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

**An Error Occurred**

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

- América Latina (Español)
- Canada (English)
- United States (English)

Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français

- United Kingdom(English)

Asia Pacific

- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)

Contact your local office