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 cisrc*mstances.

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)

References

Top Articles
What is the significance of Midian in the Bible?
Midian, Midianites - Encyclopedia of The Bible
Dunhams Treestands
Moon Stone Pokemon Heart Gold
Washu Parking
Room Background For Zepeto
Unitedhealthcare Hwp
THE 10 BEST Women's Retreats in Germany for September 2024
Music Archives | Hotel Grand Bach - Hotel GrandBach
Aries Auhsd
Ktbs Payroll Login
Qhc Learning
W303 Tarkov
Kris Carolla Obituary
Moviesda3.Com
Bx11
Commodore Beach Club Live Cam
Water Days For Modesto Ca
Walgreens San Pedro And Hildebrand
Pretend Newlyweds Nikubou Maranoshin
Unity - Manual: Scene view navigation
No Hard Feelings - Stream: Jetzt Film online anschauen
Curver wasmanden kopen? | Lage prijs
Espn Horse Racing Results
The Largest Banks - ​​How to Transfer Money With Only Card Number and CVV (2024)
Garnish For Shrimp Taco Nyt
Home
Www.craigslist.com Austin Tx
Discord Nuker Bot Invite
Watertown Ford Quick Lane
Creed 3 Showtimes Near Island 16 Cinema De Lux
Encore Atlanta Cheer Competition
Santa Barbara Craigs List
Select The Best Reagents For The Reaction Below.
Babydepot Registry
Elanco Rebates.com 2022
Royal Caribbean Luggage Tags Pending
Tenant Vs. Occupant: Is There Really A Difference Between Them?
The 50 Best Albums of 2023
Sunrise Garden Beach Resort - Select Hurghada günstig buchen | billareisen.at
Final Fantasy 7 Remake Nexus
Barstool Sports Gif
Rocky Bfb Asset
60 Days From May 31
Blow Dry Bar Boynton Beach
Mountainstar Mychart Login
Waco.craigslist
What Time Do Papa John's Pizza Close
Game Like Tales Of Androgyny
Strange World Showtimes Near Century Federal Way
Phumikhmer 2022
Texas Lottery Daily 4 Winning Numbers
Latest Posts
Article information

Author: Sen. Ignacio Ratke

Last Updated:

Views: 6214

Rating: 4.6 / 5 (76 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Sen. Ignacio Ratke

Birthday: 1999-05-27

Address: Apt. 171 8116 Bailey Via, Roberthaven, GA 58289

Phone: +2585395768220

Job: Lead Liaison

Hobby: Lockpicking, LARPing, Lego building, Lapidary, Macrame, Book restoration, Bodybuilding

Introduction: My name is Sen. Ignacio Ratke, I am a adventurous, zealous, outstanding, agreeable, precious, excited, gifted person who loves writing and wants to share my knowledge and understanding with you.