How to find and plot the Fourier Transform of signal = cos(2*pi*f*t).*(A.*(heaviside(t)-heaviside(t-39E-9)))
25 views (last 30 days)
Show older comments
The full code that I am using is:
t = 0:1.66E-12:40E-9;
A = 1;
A2 = 2;
f=3E9;
signal = cos(2*pi*f*t).*(A.*(heaviside(t)-heaviside(t-39E-9)));
signal_2 = [cos(2*pi*f*t).*(A2.*(heaviside(t)-heaviside(t-19E-9)))]+[cos(2*pi*f*t).*(A2.*(heaviside(t-21E-9)-heaviside(t-39E-9)))];
I am trying to calculate the Fourier Transform of the two signals and plot the Fourier Transform of them. It should be a 'sinc' function when it is Fourier Transformed, but I can't seem to get it to plot right using "fft".
Here is some code I found online (I am not certain where, so I can't cite it), but tried and couldn't get it to work I don't really know what "er" is?
signal = cos(2*pi*f*t).*(A.*(heaviside(t)-heaviside(t-39E-9)));
y2 = fft(signal);
m2 = abs(y2);
p2 = angle(y2);
er2 = (0:length(y2)-1)*1.66E-12/length(y2);
figure (3)
subplot(2,1,1)
plot(er2,m2)
2 Comments
David Goodmanson
on 27 Feb 2017
Edited: David Goodmanson
on 27 Feb 2017
Hi '56, There are a couple of things going on here. [1] The sinc function is the the fourier transform of a single rectangular pulse. You can approximate that with an fft, but only if you make the pulse width fairly narrow compared to the total width in the time domain. [2] You are multiplying by a cosine function, which affects the result in the frequency domain.
If you temporarily make f = 0 (so that the cosine function is a constant), go to a narrower rectangle
signal = cos(2*pi*f*t).*(A.*(heaviside(t-10e-9)-heaviside(t-12e-9)));
and plot abs(y) as before, you will see a sinc function, almost. (It's not exactly sinc and looks different anyway because the effect of abs puts all of its oscillations above the x axis). If you then change f back to its original value you will get a pair of waveforms in the frequency domain, each of which looks somewhat sinc-like.
MD Rasel Basunia
on 8 Apr 2022
Step: 1. Express the signsl in symbolic expression. 2.use fourier function to calculate fourier transform 3.define new frequency range for creating vectors and to use plot command 4.use subs command to substitute old frequency by new defined frequency range for plot
Answers (1)
Walter Roberson
on 27 Feb 2017
syms t w
Pi = sym('pi');
A = sym(1);
A2 = sym(2);
f = sym(3) * 10^9;
c1 = sym(39)/10^9;
c2 = sym(19)/10^9;
c3 = sym(21)/10^9;
c4 = sym(39)/10^9;
signal = cos(2*Pi*f*t) * (A *(heaviside(t)-heaviside(t-c1)));
signal_2 = [cos(2*Pi*f*t) * (A2 * (heaviside(t)-heaviside(t-c2)))] + [cos(2*Pi*f*t) * (A2 * (heaviside(t-c3)-heaviside(t-c4)))];
f1 = simplify( fourier(signal, t, w), 'steps', 20);
f2 = simplify( fourier(signal_2, t, w), 'steps', 20);
Now you can plot the symbolic expressions f1 and f2.
Just be careful you do not substitute in your time signal for w -- w should be frequency, not time.
0 Comments
See Also
Categories
Find more on Symbolic Math Toolbox 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!