graphing a fourier transform function

12 views (last 30 days)
I have a function: f=gaussmf(x,[3,10]), and wanting to plot the magnitude if its fourier transform. I am defining the frequency, s, to be s= x*(1/N). x is my independent variable vector for the original function and goes from 0:250. N is my number of x points being input into the original function, which in this case is 251. I am wanting to plot the magnitude of my FT as a function of s.
When I do this I am using the fftshift(FT(f)) but I want to be able to see my plot in its original location along s, not shifted along the s-axis, where the peak is not in the 'correct' location along the s-axis.
What I am trying to say is when I plot fft(FT(f)), I am only seeing the tails of the FT plot. I simply want to 'shift' the plot so I can see the entire curve along its original location, however I don't want to shift the function along the s-axis.

Accepted Answer

Matt J
Matt J on 22 Sep 2013
Edited: Matt J on 22 Sep 2013
I don't quite understand what you want, but if you are using f=gaussmf(0:250,[3,10]) to construct f,then the left tail of the Gaussian looks like it would be highly under-sampled. That may be why the shape of the FFT is not as you expect.
If f is centered at 10, you probably want to sample symmetrically around 10
f=gaussmf(10+(-126:126), [3,10])
although why you don't simply just center the gaussian at zero is unclear to me.
f=gaussmf(-126:126, [3,0])
Since you only want the magnitude spectrum, shifting the peak to x=10 has no effect and just complicates things.
  2 Comments
richard
richard on 22 Sep 2013
The function f is basically zero everywhere except around x=10. So I can plug in basically x=0:20 to plot out my f just fine.
But are you saying the x=0:20 wont cut it for my Fourier transform plot? I am using frequency,s, for my FT plot, which involves using x.
The left tail of my f looks ok, but are you referring to the FT plot when you say 'left tail'?
I think you're instructions are getting the results I want, but I'm a little confused on what you meant by undersampling. Are you saying my f is undersampled or my FT is undersampled?
Matt J
Matt J on 22 Sep 2013
Edited: Matt J on 22 Sep 2013
Never mind what I said about undersampling, although I do think sampling x more finely gives a noticeably smoother plot of gaussmf(x,[3,10]). But anyway, when I run the code below, I get a nice Gaussian-looking magnitude spectrum centered at s=0 ... all as expected. If this is not what you're after, you can use this is as basis for explaining what you're doing differently.
%Axes
x=linspace(0,250,501); %x-axis
N=length(x);
dx=x(2)-x(1);
ds=1/N/dx;
s=( (0:N-1) -ceil((N-1)/2) )*ds; %freq axis
%Signals
G=@(x,sig,c)exp(-(x-c).^2/2/sig^2);
f=G(x,3,10);
F=fftshift(abs(fft(f)*dx));
%Plots
figure(1);
plot(x,f);
figure(2);
plot(s,F)

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!