From: kk KKsingh on 4 Jul 2010 20:54 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
From: TideMan on 4 Jul 2010 21:47 On Jul 5, 12: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) > > is same will be applicable when i am talking in term of radians... > > Thanks 1 Hz means 1 cycle per second. How many radians are there in a cycle? So, can you figure out from this how to convert from Hz to radians per second? Note: you also need to modify the PSD by the same factor.
From: Rick Rosson on 4 Jul 2010 22:34 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
From: Rick Rosson on 4 Jul 2010 22:39 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
From: Rick Rosson on 5 Jul 2010 14:32 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
|
Next
|
Last
Pages: 1 2 Prev: Help with a plot Next: solving a function with serveral known variables |