Azzera filtri
Azzera filtri

Graphing the Fourier Transform of a Square pulse: Problems with filled in sinc function, frequency axis, and amplitude.

14 visualizzazioni (ultimi 30 giorni)
I am attempting to show the graph of the Fourier transform of a square pulse function but I am having a few issues. The first one, is that the sinc function itself is filled in instead of being empty. I was wondering if there was a way to fix that or if there was something I did wrong in my code that makes it filled instead of just an outline of a sinc function.Another problem is that the first zero crossing spot on the frequency axis is supposed to be the actual width of the square pulse (which is 1 nanosecond in my case) but when I graph a marker to show where the first zero should be, it appears my function is a little squeezed and it crosses the axis a couple times before the actual marker. I am pretty sure my math is right, it is just a problem trying to set up the axis correctly for the situation. My final problem is that the Fourier Transform of the square pulse is supposed to be ATsinc(fT), but the highest point of the sinc in the graph shows that the period is 50 nanoseconds (instead of 1 nanosecond) and my amplitude is assumed to be 1. I was wondering what I might have done wrong in my code or perhaps assumed wrong in my math to arrive at this problem.
Thanks for your help
David
clear all;close all;clc;
fs = 1e9; %sampling freqency
tfin = 10e-9; %beggining and end of time for samples of square pulse
N = 1025;% number of steps in linspace, odd to make centered at zero
width = 1e-9; % actual width of square pulse, 1 nanosecond
t = linspace(-tfin,tfin,N);
%my attempt at making the f axis but turns out to be wrong.
f = linspace(-10*(1/width),10*(1/width),N);
y = rectpuls(t,width);%makes the actual square pulse
plot(t,y)
Y = width*fft(y); %fourier transform of square pulse: ATsinc(fT)
%where f is a frequency variable. A is the amplitude of the pulse,
%assumed to be 1.
Yplot = fftshift(Y);
%fftshift changes the axis so zero is at the center
%and have negative and positive frequencies on both sides of the axis.
figure;
plot(f,Yplot)
hold on;
%this plots a red circle on where the first zero occurs on a graph of the
%sinc function. It should be exactly the width of the square pulse
% which is 1 nanosecond.
plot(1/width,width*sinc((1/width)*width),'ro');

Risposta accettata

Teja Muppirala
Teja Muppirala il 9 Mar 2012
Two things.
1. As you noticed, you are defining your f incorrectly. The resolution of f is equal to 1/T, where T is equal to the period (length) of the time signal.
dt = t(2) - t(1);
T = t(end)-t(1) + dt;
f = 1/T * (-(N-1)/2 : (N-1)/2); % This is 1/T * (-512 : 512)
2. Your code is only plotting the real part of Y. Plot the magnitude instead.
plot(f,abs(Yplot)).
Then you see that the first crossing occurs at 1/width. The final result:
clear;
fs = 1e9; %sampling freqency
tfin = 10e-9; %beggining and end of time for samples of square pulse
N = 1025;% number of steps in linspace, odd to make centered at zero
width = 1e-9; % actual width of square pulse, 1 nanosecond
t = linspace(-tfin,tfin,N);
% The correct way to make f.
dt = t(2)-t(1);
T = t(end)-t(1) + (t(2)-t(1));
f = 1/T * (-(N-1)/2 : (N-1)/2);
y = rectpuls(t,width);%makes the actual square pulse
plot(t,y)
Y = width*fft(y); %fourier transform of square pulse: ATsinc(fT)
%where f is a frequency variable. A is the amplitude of the pulse,
%assumed to be 1.
Yplot = fftshift(Y);
%fftshift changes the axis so zero is at the center
%and have negative and positive frequencies on both sides of the axis.
figure;
plot(f,abs(Yplot))
hold on;
%this plots a red circle on where the first zero occurs on a graph of the
%sinc function. It should be exactly the width of the square pulse
% which is 1 nanosecond.
plot(1/width,width*sinc((1/width)*width),'ro');
  1 Commento
David
David il 9 Mar 2012
Thanks Teja it helped tremendously! I was wondering if there is any way to have the positive and negative y values to not be filled in, or is the only way to fix this by plotting the magnitude?
Also I figured something out, the maximum on the graph is supposed to be equal to AT but it wasn't, I found out that multiplying fft(y) by dt instead of width fixes this.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Mathematics in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by