Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7839225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:22:39+00:00 2026-06-02T15:22:39+00:00

I’m trying to plot the phase of an FFT using MATLAB. I have this

  • 0

I’m trying to plot the phase of an FFT using MATLAB. I have this signal that is actually the current through a light dimmer set to half intensity. Anyway, that really doesn’t matter. Basically, in my code I put together the signal into a vector, i. Then I perform and FFT on i and store it in I. Then I try to get the magnitude and angle of I.

The magnitude spectra seems correct, but the phase/angle one doesn’t and I can’t work out why. Any suggestions? I do realise my code is a little ‘dodgy’ in how part are inefficiently written. I’m not really a pro with MATLAB or anything…

Help would be much appreciated.

Thank you.

%             (  40/240 * sin(2*pi*50*t)      for a < t < T
% waveform = {
%             (  0                            for 0 < t < a

cycles = 2;
a = 90;




clear i  t;
aTime = a/360;
dt = 0.0001;

t = 0;
i = 0;

for n = 0 : cycles - 1;
    T = 1/50;

    t0 = 0 + (n*T) : dt : T*aTime + (n*T) - dt;
    t1 = T*aTime + (n*T) : dt : T/2 + (n*T) - dt;
    t2 = T/2 + (n*T) : dt : T*(aTime + 1/2) + (n*T) - dt;
    t3 = T*(aTime + 1/2) + (n*T) : dt : T + (n*T) - dt;
    t = [t [t0, t1, t2, t3]];

    i = [i zeros(1, length(t0))];
    i = [i 40/240 * sin(2*pi*50*t1)];
    i = [i zeros(1, length(t2))];
    i = [i 40/240 * sin(2*pi*50*t3)];
end

subplot(3,2,[1 2])
hold on;
plot(t, 40/240 * sin(2*pi*50*t), ':r');
plot(t, i);
xlabel('time (sec)')
ylabel('i(t)')
title('Current through a 40W, 240V dimmed light with alpha = 90^o')
grid on;
hold off;
axis([0, T*(n(end) + 1), -0.2, 0.2]);

fs = 1/dt;
N = length(i);
df = fs/N;
f = (-fs/2) : df : (fs/2)-df;
I = fftshift(fft(i)/N);

subplot(3,2,3)
plot(f, abs(I))
axis([-1000,1000,0,0.055]);
xlabel('frequency (Hz)')
ylabel('|i(t)|')
title('Magnitude Spectrum')
grid on;

subplot(3,2,5)
plot(f, mod(unwrap(angle(I)), 2*pi))
axis([-1000, 1000, -pi, 2.5*pi]);
xlabel('Radians')
ylabel('Arg(i(t))')
title('Frequency')
grid on;

subplot(3,2,4)
hold on;
plot(t, i);
plot(t, real(0.1*exp(1i*(2*pi*50*t + 4.139))), 'm');
plot(t, real(2*0.02653*exp(1i*(2*pi*150*t + 6.268))), 'g');
plot(t, real(2*0.008844*exp(1i*(2*pi*250*t + 3.156))), 'r');
axis([0, T*(n(end) + 1), -0.2, 0.2]);
hold off;
xlabel('Time')
ylabel('Value')
title('Fourier Series Components')
grid on;

subplot(3,2,6)
hold on;
plot(t, i);
plot(t, real(0.1*exp(1i*(2*pi*50*t + 4.139))), 'm');
plot(t, real(2*0.008844*exp(1i*(2*pi*250*t + 3.156)) + 2*0.02653*exp(1i*(2*pi*150*t + 6.268)) + 0.1*exp(1i*(2*pi*50*t + 4.139))), 'm');
plot(t, real(2*0.02653*exp(1i*(2*pi*150*t + 6.268)) + 0.1*exp(1i*(2*pi*50*t + 4.139))), 'g');
axis([0, T*(n(end) + 1), -0.2, 0.2]);
hold off;
xlabel('Time')
ylabel('Value')
title('Fourier Series Sum')
grid on;

Edit:
Made it so that fftshift is applied to both the angle and the magnitude.

This is what I get:
plots

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T15:22:39+00:00Added an answer on June 2, 2026 at 3:22 pm

    FFT phase has to be unwrapped to make sense. Otherwise there will be discontinuities of 2pi.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to loop through a bunch of documents I have to put
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to create an if statement in PHP that prevents a single post
I have thousands of HTML files to process using Groovy/Java and I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.