How to get magnitude and phase onfo of a given signal (2024)

Discussion:

How to get magnitude and phase onfo of a given signal

(too old to reply)

Ashwini Deshpande

2009-07-06 10:12:01 UTC

Permalink

Hi,

I have sine wave as follows,
t=0:0.01:1;
x=sin(2*pi*4*t);

if i want to know the magnitude and phase of this signal, what do i do ??
It is something like,
[magnitude, phase] = function(x);

Can anyone tell me that, is there any such library function available in matlab which gives me magnitude and phase information of signal given.

Thanks !
Ashwini

Wayne King

2009-07-06 11:18:01 UTC

Permalink

hi Ashwini, please look at the help for fft

Post by Ashwini Deshpande

doc fft

Hope that helps,
wayne

Post by Ashwini Deshpande
Hi,
I have sine wave as follows,
t=0:0.01:1;
x=sin(2*pi*4*t);
if i want to know the magnitude and phase of this signal, what do i do ??
It is something like,
[magnitude, phase] = function(x);
Can anyone tell me that, is there any such library function available in matlab which gives me magnitude and phase information of signal given.
Thanks !
Ashwini

Dave Robinson

2009-07-06 11:23:01 UTC

Permalink

Post by Ashwini Deshpande
Hi,
I have sine wave as follows,
t=0:0.01:1;
x=sin(2*pi*4*t);
if i want to know the magnitude and phase of this signal, what do i do ??
It is something like,
[magnitude, phase] = function(x);
Can anyone tell me that, is there any such library function available in matlab which gives me magnitude and phase information of signal given.
Thanks !
Ashwini

If you know what the frequency of your signal is, as you do in your example, then create a unity amplitude sine wave and a unity amplitude cosine wave of exactly the same frequency but of zero phase. Now take your signal and do a sample by sample multiplication first by the cosine wave you have just synthesized, then accumulate the results - repeat this process for your sine wave. You should get 2 simple numbers out of each multiply accumulate operation. If you do a pythagorean sum on these numbers, it will tell you the amplitude of your signal, and if you take ATAN2 on the Cosine accumulation and the Sine accumulation, this will give you a measure of the phase.

If you don't know the frequency of your signal, then you probably need to resort to using the FFT, if so come back.

Regards

Dave Robinson

Ashwini Deshpande

2009-07-06 12:21:01 UTC

Permalink

Post by Dave Robinson

Post by Ashwini Deshpande
Hi,
I have sine wave as follows,
t=0:0.01:1;
x=sin(2*pi*4*t);
if i want to know the magnitude and phase of this signal, what do i do ??
It is something like,
[magnitude, phase] = function(x);
Can anyone tell me that, is there any such library function available in matlab which gives me magnitude and phase information of signal given.
Thanks !
Ashwini

If you know what the frequency of your signal is, as you do in your example, then create a unity amplitude sine wave and a unity amplitude cosine wave of exactly the same frequency but of zero phase. Now take your signal and do a sample by sample multiplication first by the cosine wave you have just synthesized, then accumulate the results - repeat this process for your sine wave. You should get 2 simple numbers out of each multiply accumulate operation. If you do a pythagorean sum on these numbers, it will tell you the amplitude of your signal, and if you take ATAN2 on the Cosine accumulation and the Sine accumulation, this will give you a measure of the phase.
If you don't know the frequency of your signal, then you probably need to resort to using the FFT, if so come back.
Regards
Dave Robinson

Thanks for ur reply,
can plz clear me that what do u mean by accumulating result. Is it same as calculating the mean.

Thanks !
Ashwini

Dave Robinson

2009-07-06 16:29:03 UTC

Permalink

Post by Ashwini Deshpande
Thanks for ur reply,
can plz clear me that what do u mean by accumulating result. Is it same as calculating the mean.
Thanks !
Ashwini

When you do the sample by sample multiplication (.*) of the two waveforms, you will end up with a vector of the same length as your (Cos)Sine wave and signal. By accumulate I meant add up all the elements in that vector - yes you are right, it is directly proportional to the mean value of that vector.

Regards

Dave Robinson

TideMan

2009-07-06 20:19:55 UTC

Permalink

Post by Dave Robinson

Post by Ashwini Deshpande
Thanks for ur reply,
can plz clear me that what do u mean by accumulating result. Is it same as calculating the mean.
Thanks !
Ashwini

When you do the sample by sample multiplication (.*) of the two waveforms, you will end up with a vector of the same length as your (Cos)Sine wave and signal. By accumulate I meant add up all the elements in that vector - yes you are right, it is directly proportional to the mean value of that vector.
Regards
Dave Robinson

Another way of doing what Dave suggests is using Matlab's \ facility:
wt=2*pi*4*t;
coef=[cos(wt) sin(wt)]\x;
amp=sqrt(coef(1)^2 + coef(2)^2);
phi=atan2(coef(1),coef(2))*180/pi;

In principle, this is the way tidal constituents are calculated from a
tide gauge record, except that there are not one, but up to 600
frequencies involved.

Ashwini Deshpande

2009-07-07 04:49:02 UTC

Permalink

Post by TideMan

Post by Dave Robinson
When you do the sample by sample multiplication (.*) of the two waveforms, you will end up with a vector of the same length as your (Cos)Sine wave and signal. By accumulate I meant add up all the elements in that vector - yes you are right, it is directly proportional to the mean value of that vector.
Regards
Dave Robinson

wt=2*pi*4*t;
coef=[cos(wt) sin(wt)]\x;
amp=sqrt(coef(1)^2 + coef(2)^2);
phi=atan2(coef(1),coef(2))*180/pi;
In principle, this is the way tidal constituents are calculated from a
tide gauge record, except that there are not one, but up to 600
frequencies involved.

Thanks a lot for ur reply,
My code is as follows:

t=0:0.0001:0.02;
ph=0;
x1=sin(2*pi*100*t);
x2=sin(2*pi*100*t+ph);
plot(t,x1,t,x2);
X1_sq=x1.^2;
X2_sq=x2.^2;
s1=mean(X1_sq);
s2=mean(X2_sq);
amp=sqrt(s1^2+s2^2);
phi=atan2(s2,s1)*180/pi;

when i run this code i get phi value around 45 for any value of ph.
But i suppose to get 0 for ph=0 and so on..... what is wrong in this .. ??

Thanks !
Ashwini

Srikanth

2012-04-24 18:41:07 UTC

Permalink

Post by TideMan

Post by Dave Robinson

Post by Ashwini Deshpande
Thanks for ur reply,
can plz clear me that what do u mean by accumulating result. Is it same as calculating the mean.
Thanks !
Ashwini

When you do the sample by sample multiplication (.*) of the two waveforms, you will end up with a vector of the same length as your (Cos)Sine wave and signal. By accumulate I meant add up all the elements in that vector - yes you are right, it is directly proportional to the mean value of that vector.
Regards
Dave Robinson

wt=2*pi*4*t;
coef=[cos(wt) sin(wt)]\x;
amp=sqrt(coef(1)^2 + coef(2)^2);
phi=atan2(coef(1),coef(2))*180/pi;
In principle, this is the way tidal constituents are calculated from a
tide gauge record, except that there are not one, but up to 600
frequencies involved.

Hello,

I saw your comment and wanted to know if you could provide some insight on how to apply this method to a signal that has more than 1 frequency involved (in my case 3). Will this method provide a good result if the estimate of the frequency w is slightly off (due to experimental error)?

Thanks in advance for your help

-Sri

Ihaveideas

2012-05-30 15:34:09 UTC

Permalink

Dear Dave,

What is the name of the algorithm you have suggested in your comment below, where basically in order to find the magnitude and phase of a signal with a known frequency, you would perform a sample by sample multiplication of the signal and two sine waves (a sine and a cosine). I am interested in pursuing this a bit further. In particular, I am interested in finding the error that results in performing such operations.

Best wishes

Post by Dave Robinson

Post by Ashwini Deshpande
Hi,
I have sine wave as follows,
t=0:0.01:1;
x=sin(2*pi*4*t);
if i want to know the magnitude and phase of this signal, what do i do ??
It is something like,
[magnitude, phase] = function(x);
Can anyone tell me that, is there any such library function available in matlab which gives me magnitude and phase information of signal given.
Thanks !
Ashwini

If you know what the frequency of your signal is, as you do in your example, then create a unity amplitude sine wave and a unity amplitude cosine wave of exactly the same frequency but of zero phase. Now take your signal and do a sample by sample multiplication first by the cosine wave you have just synthesized, then accumulate the results - repeat this process for your sine wave. You should get 2 simple numbers out of each multiply accumulate operation. If you do a pythagorean sum on these numbers, it will tell you the amplitude of your signal, and if you take ATAN2 on the Cosine accumulation and the Sine accumulation, this will give you a measure of the phase.
If you don't know the frequency of your signal, then you probably need to resort to using the FFT, if so come back.
Regards
Dave Robinson

Rune Allnor

2009-07-06 11:45:28 UTC

Permalink

Post by Ashwini Deshpande
Hi,
I have sine wave as follows,
t=0:0.01:1;
x=sin(2*pi*4*t);
if i want to know the magnitude and phase of this signal, what do i do ??
It is something like,
[magnitude, phase] = function(x);
Can anyone tell me that, is there any such library function available in matlab which gives me magnitude and phase information of signal given.

There is no such function.

Some people have suggested FFT, but it only works like
you want it to, under very special cisrcumstances.

For instance:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
N = 8;
f1 = 2/16;
x = sin(2*pi*f1*(0:N-1));

X = fft(x);
plot(abs(X)/N)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

In this case you recognize the amplitude from
the model, as expressed by Euler's relation

sin(x) = 1/2(exp(jx)-exp(-jx)).

However, if you change the frequency slightly,

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
N = 8;
f2 = 3/16;
y = sin(2*pi*f2*(0:N-1));

Y = fft(y);
plot(abs(Y)/N)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

you no longer recognize the single sinusodial
in your signal.

Rune

Greg

2009-07-07 04:52:59 UTC

Permalink

Post by Ashwini Deshpande
Hi,
I have sine wave as follows,
t=0:0.01:1;
x=sin(2*pi*4*t);
if i want to know the magnitude and phase of this signal, what do i do ??
It is something like,
[magnitude, phase] = function(x);
Can anyone tell me that, is there any such library function available in matlab which gives me magnitude and phase information of signal given.

Since you know the frequency, find C from

% x = C(1)*cos(2*pi*4*t)+C(2)*sin(2*pi*4*t);

t = (0:0.01:1)';
x = sin(2*pi*4*t);
W = [cos(2*pi*4*t) sin(2*pi*4*t)];
C = W\x
C =
0.0000
1.0000

Hope this helps.

Greg

Ashwini Deshpande

2009-07-20 08:35:19 UTC

Permalink

Post by Greg

Post by Ashwini Deshpande
Hi,
I have sine wave as follows,
t=0:0.01:1;
x=sin(2*pi*4*t);
if i want to know the magnitude and phase of this signal, what do i do ??
It is something like,
[magnitude, phase] = function(x);
Can anyone tell me that, is there any such library function available in matlab which gives me magnitude and phase information of signal given.

Since you know the frequency, find C from
% x = C(1)*cos(2*pi*4*t)+C(2)*sin(2*pi*4*t);
t = (0:0.01:1)';
x = sin(2*pi*4*t);
W = [cos(2*pi*4*t) sin(2*pi*4*t)];
C = W\x
C =
0.0000
1.0000
Hope this helps.
Greg

Thanks a lot Greg ,,

I got my result...
Ashwini !

11 Replies
3 Views
Permalink to this page
Disable enhanced parsing

Thread Navigation

Ashwini Deshpande2009-07-06 10:12:01 UTC
Wayne King2009-07-06 11:18:01 UTC
Dave Robinson2009-07-06 11:23:01 UTC
Ashwini Deshpande2009-07-06 12:21:01 UTC
Dave Robinson2009-07-06 16:29:03 UTC
TideMan2009-07-06 20:19:55 UTC
Ashwini Deshpande2009-07-07 04:49:02 UTC
Srikanth 2012-04-24 18:41:07 UTC
Ihaveideas 2012-05-30 15:34:09 UTC
Rune Allnor2009-07-06 11:45:28 UTC
Greg2009-07-07 04:52:59 UTC
Ashwini Deshpande2009-07-20 08:35:19 UTC
How  to get magnitude and phase onfo of a given signal (2024)

FAQs

How to get the magnitude and phase of a signal? ›

The magnitude is the square root of the sum of the squares of the real and imaginary parts. The phase is relative to the start of the time record or relative to a single-cycle cosine wave starting at the beginning of the time record. Single-channel phase measurements are stable only if the input signal is triggered.

How do you find the magnitude and phase response? ›

A geometric way to obtain approximate magnitude and phase frequency responses is using the effects of zeros and poles on the frequency response of an LTI system. G ( s ) | s = j Ω 0 = K j Ω 0 − z j Ω 0 − p = K Z → ( Ω 0 ) P → ( Ω 0 ) .

How do you determine the phase of a signal? ›

Phase can be measured in distance, time, or degrees. If the peaks of two signals with the same frequency are in exact alignment at the same time, they are said to be in phase. Conversely, if the peaks of two signals with the same frequency are not in exact alignment at the same time, they are said to be out of phase.”

How do you find the phase of a frequency response function? ›

To obtain the phase response, we take the arctan of the numerator, and subtract from it the arctan of the denominator. (Angle of a complex number expressed as a vector is something you may not be familiar with.

What is the magnitude and phase of frequency? ›

The magnitude describes the strength of each frequency in the signal. The phase describes the sine/cosine phase of each frequency. The phase can also be thought of as the relative proportion of sines and cosines in the signal (i.e., a phase of zero contains only cosines and a phase of 90 degrees contains only sines).

What is the formula for phase to frequency? ›

The time interval for 1° of phase is inversely proportional to the frequency. If the frequency of a signal is given by f, then the time tdeg (in seconds) corresponding to 1° of phase is tdeg = 1 / (360f) = T / 360. Therefore, a 1° phase shift on a 5 MHz signal corresponds to a time shift of 555 picoseconds.

How do you find the magnitude and phase of impedance? ›

Impedance in circuits

This is less mathematical and requires an appreciation that a sinusoidal curve can be constructed by a rotating vector arrow (seen in SHM), and a knowledge of Pythagoras. Here Z0​ is the magnitude of Z so Z0​=X2+Y2 ​ and ϕ is the phase of Z which has the value ϕ=arctan(XY​).

What is the formula for the phase of a wave? ›

The phase of a wave is the value representing a fraction of a wave cycle. In a wave, a complete cycle, from crest to crest or trough to trough, is equal to 2π [rad]. Every fraction of that length, therefore, is less than 2π [rad]. Half a cycle is π [rad], while a quarter of a cycle is π/2 [rad].

What is the formula for phase calculation? ›

The phase shift equation is ps = 360 * td / p, where ps is the phase shift in degrees, td is the time difference between waves and p is the wave period. Continuing the example, 360 * -0.001 / 0.01 gives a phase shift of -36 degrees.

How do you find the phase value? ›

In Mathematics, face value is the actual value of the digit in a number. For example, if 567 is a number, then the face value of 6 is 6 only, whereas its place value is tens (i.e. 60). Thus, for any number, having a two-digit, three-digit or 'n' number of digits, every digit will have a place value and a face value.

How do you find the phase of an equation? ›

A phase shift is when a graph is moved horizontally to the left or right a specific number of units. It can be found by using the general formula of transformations y = A f ( B x − C ) + D and identifying the B and C values.

What is the magnitude and phase response of a transfer function? ›

A transfer function, H(ω), has a magnitude response |H(ω)| and a phase response ϕ(ω) such that H(ω) = |H(ω)| e(ω). The only difference between a complex number z and a transfer function H(ω) is z is one complex number whereas H(ω) is an entire function of complex numbers: a complex number for each frequency value ω.

What is the magnitude of the frequency domain? ›

The magnitude tells you the strength of the frequency components relative to other components. The phase tells you how all the frequency components align in time. Plot the magnitude and the phase components of the frequency spectrum of the signal. The magnitude is conveniently plotted in a logarithmic scale (dB).

What is phase response of signal? ›

In signal processing, phase response is the relationship between the phase of a sinusoidal input and the output signal passing through any device that accepts input and produces an output signal, such as an amplifier or a filter.

What is the formula for phase and amplitude? ›

Finding the amplitude, period, and phase shift of a function of the form A × sin(Bx - C) + D or A × cos(Bx - C) + D goes as follows: The amplitude is equal to A ; The period is equal to 2π / B ; and. The phase shift is equal to C / B .

How do you calculate the phase of a circuit? ›

To calculate the phase angle, one typically measures the time difference between corresponding points on the voltage and current waveforms, then converts this time delay into an angle using the formula: phase angle = (time delay / period) * 360 degrees.

Top Articles
Latest Posts
Recommended Articles
Article information

Author: Kareem Mueller DO

Last Updated:

Views: 5957

Rating: 4.6 / 5 (46 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Kareem Mueller DO

Birthday: 1997-01-04

Address: Apt. 156 12935 Runolfsdottir Mission, Greenfort, MN 74384-6749

Phone: +16704982844747

Job: Corporate Administration Planner

Hobby: Mountain biking, Jewelry making, Stone skipping, Lacemaking, Knife making, Scrapbooking, Letterboxing

Introduction: My name is Kareem Mueller DO, I am a vivacious, super, thoughtful, excited, handsome, beautiful, combative person who loves writing and wants to share my knowledge and understanding with you.