From: Wayne King on
"Rick Rosson" <rrossoNO(a)SPAMathworks.com> wrote in message <i0t8f3$i90$1(a)fred.mathworks.com>...
> One other small typo. I fort the 't' in the functioin 'fftshift' in the line of code the computes the DFT of the signal 'x'. The correct line should be:
>
> X = fftshift(fft(x));
>
> This line is rght after the comment that reads:
>
> % Spectrum:
>
> Sorry!
>
> Rick
>
>
>
> "Rick Rosson" <rrossoNO(a)SPAMathworks.com> wrote in message <i0rgk9$sh0$1(a)fred.mathworks.com>...
> > Ooops! I forgot one key line of code. Insert the following two lines of code:
> >
> > % Carrier frequency (in hertz):
> > Fc = 30
> >
> > before the the line
> >
> > % Signal:
> >
> > Sorry!
> >
> > Rick
> >
> > "Rick Rosson" <rrossoNO(a)SPAMathworks.com> wrote in message <i0rgat$a92$1(a)fred.mathworks.com>...
> > > Please try the MATLAB code below.
> > >
> > > HTH.
> > >
> > > Rick
> > >
> > > %% Signal in the time domain
> > >
> > > % Number of data points:
> > > N = 1000;
> > >
> > > % Sampling rate (in samples per second):
> > > Fs = 100;
> > >
> > > % Time increment (in seconds per sample):
> > > dt = 1/Fs;
> > >
> > > % Time domain (in seconds):
> > > t = dt*(0:N-1).';
> > >
> > > % Signal:
> > > x = sin(2*pi*Fc*t);
> > >
> > >
> > > %% Convert to frequency domain
> > >
> > > % Spectrum:
> > > X = fftshif(fft(x));
> > >
> > > % Frequency increment (in hertz per sample):
> > > dF = Fs/N;
> > >
> > > % Frequency domain:
> > > f = -Fs/2:dF:Fs/2-dF; % in hertz
> > > omega = 2*pi*f % in radians per second
> > > phi = omega/Fs; % in radians per sample
> > >
> > >
> > > %% Plot time domain:
> > >
> > > figure;
> > > plot(t,x);
> > >
> > >
> > > %% Plot frequency domain:
> > >
> > > figure;
> > >
> > > subplot(3,1,1);
> > > plot(f,abs(X)/N);
> > >
> > > subplot(3,1,2);
> > > plot(omega,abs(X)/N);
> > >
> > > subplot(3,1,3);
> > > plot(phi,abs(X)/N);
> > >
> > >
> > > "kk KKsingh" <akikumar1983(a)gmail.com> wrote in message <i0rafd$nm2$1(a)fred.mathworks.com>...
> > > > Hi!
> > > >
> > > > This must be a stupid question ! In signal analysis i have seen few paper where they talk in terms of omega (radian) instead of Hz
> > > >
> > > > They take a signal in time domain and plot its spectra in frequency domain between [-pi,pi]
> > > >
> > > > How can i do the same in matlab
> > > >
> > > > Assuming
> > > > N=1000;
> > > > f=30;
> > > > dt=.01;
> > > > t=0:dt*(N-1)
> > > > omega=2*pi*f;
> > > > S=sin(omega*t);
> > > >
> > > > F=fftshift(fft(S))
> > > >
> > > > Now how should i make frequency axis
> > > >
> > > > I used to do like this when i take in Hz
> > > >
> > > > for even
> > > > 1/dt/N*(-N/2:N/2-1)
> > > > for odd
> > > > 1/dt/N*(-N/2-1:N/2-1)
> > > >
> > > > is same will be applicable when i am talking in term of radians...
> > > >
> > > > Thanks

If you have the Signal Processing Toolbox, you can compute a PSD estimate using a spectral analysis object and the psd() method. This psd method will automatically return the proper vector of frequencies and scale the PSD estimate correctly depending on whether you want angular or cyclical frequency.

Wayne
From: Greg Heath on
On Jul 4, 8:54 pm, "kk KKsingh" <akikumar1...(a)gmail.com> wrote:
> Hi!
>
> This must be a stupid question ! In signal analysis i have seen few paper where they talk in terms of omega (radian) instead of Hz
>
> They take a signal in time domain and plot its spectra in frequency domain between [-pi,pi]
>
> How can i do the same in matlab

> Assuming
> N=1000;
> f=30;
> dt=.01;
> t=0:dt*(N-1)
> omega=2*pi*f;
> S=sin(omega*t);
>
> F=fftshift(fft(S))
>
> Now how should i make frequency axis
>
> I used to do like this when i take in Hz
>
> for even
> 1/dt/N*(-N/2:N/2-1)
> for odd
> 1/dt/N*(-N/2-1:N/2-1)

1/dt/N*(-N/2+1:N/2-1) % N odd does not include Nyquist

> is same will be applicable when i am talking in term of radians...

When using fftshift, the resulting bipolar frequency interval is

fb = (Fs/N)*[-ceil((N-1)/2 : floor((N-1)/2)];

For the rescaling replace Fs with 2*pi

Hope this helps.

Greg