Matlab code help - Gaussian Function

In summary, to obtain a chirped Gaussian pulse in MATLAB, you need to generate the frequency axis using the <code>fftfreq</code> function, adjust the chirp coefficient, and scale the frequency axis to GHz.
  • #1
BeeGee
8
0
Hello,

I am new to this forum so please kindly let me know if my question needs to be posted in another area.
I am trying to write a MATLAB code to show a chirped Gaussian function and I am having some trouble with it. I am trying to obtain a chirped Gaussian pulse by modulating a chirped sinusoid by a Gaussian envelope. The modulation frequency is 50GHz.

When I implement the Gaussian code, I don't believe I am getting the right results.

Any help that can be rendered is much appreciated.

My code is below:

c = 3e8*1e-12; % (m/ps; set time unit to ps)

N = 2^16; % Number of time points
tmin = 0; % time aperture (window) start time
tmax = 1e3; % time aperture stop time (ps);
t0 = (tmax-tmin)/2; % center the pulse in the time window (ps)
dt = (tmax - tmin)/(N-1); % time step
t = (tmin:dt:tmax)'; % Time scale

lambda = 1550e-9; % Wavelength of launched pulse (m)
bandwidth = 20e-9; % starting bandwidth (nm)
P0 = 100; % peak power (W)
A = sqrt(P0); % A is the amplitude of the wave to be propagated

T0 = 0.44*lambda^2/(c*bandwidth); % FWHM of Guassian

chirp = -1;
w = 2*pi*50e9;
cp = A*exp(i*w*t).*exp((-(t-t0).^2/2*T0^2)*(1-i*chirp*T0^2)) % Chirped Gaussian function
cpf = fft(cp);

figure;
plot(t(N/2-400:N/2+400), abs(cp(N/2-400:N/2+400)), 'linewidth', 2); %time domain plot
figure;

plot(f, (cpf), 'linewidth', 2); %frequency domain plot

Thank you
 
Physics news on Phys.org
  • #2
!</code>Thanks for your help,You need to make a few modifications and additions to your code to get the desired chirped Gaussian pulse. First, you need to generate the frequency axis, which you can do using the <code>fftfreq</code> function. You can add the following line to your code:<code>f = fftfreq(N,dt); % Generate frequency axis</code>Second, you need to adjust the chirp coefficient in your expression for the chirped Gaussian pulse. The chirp coefficient is given by c_chirp = -1/T0^2, where T0 is the temporal width of the Gaussian envelope. So, you need to replace your line:<code>chirp = -1;</code>with<code>chirp = -1/(T0^2);</code>Thirdly, you need to adjust the scaling of the frequency axis. The frequency axis should be scaled such that it corresponds to frequencies in GHz. You can do this by multiplying the frequency axis by an appropriate scaling factor. You can add the following line to your code:<code>f = f*1e-9; % Scale frequency axis to GHz</code>After making these modifications and additions to your code, you should be able to obtain the desired chirped Gaussian pulse.I hope this helps.
 

1. What is a Gaussian function in Matlab?

A Gaussian function in Matlab is a mathematical function that represents a bell-shaped curve. It is commonly used in many scientific fields to model a wide range of phenomena, such as probability distributions, signal processing, and data analysis.

2. How do I write a Gaussian function in Matlab?

To write a Gaussian function in Matlab, you can use the built-in gaussmf function, which takes in the input variable, the mean, and the standard deviation as parameters. Alternatively, you can also define your own custom Gaussian function using the formula f(x) = (1 / (sigma * sqrt(2 * pi))) * exp(-(x - mu)^2 / (2 * sigma^2)), where mu is the mean and sigma is the standard deviation.

3. How do I plot a Gaussian function in Matlab?

To plot a Gaussian function in Matlab, you can use the plot function to create a line plot of the function. First, define the range of values for the x-axis, then calculate the corresponding y-values using your chosen Gaussian function, and finally use the plot function to plot the x and y values.

4. Can I customize the appearance of my Gaussian function plot in Matlab?

Yes, you can customize the appearance of your Gaussian function plot in Matlab by using various optional parameters in the plot function, such as line color, style, and width. You can also add a title, x and y labels, and a legend to your plot to make it more visually appealing and informative.

5. Are there other useful functions in Matlab for working with Gaussian functions?

Yes, there are several other functions in Matlab that can be helpful for working with Gaussian functions. Some examples include normpdf (for calculating the probability density function of a Gaussian distribution), normcdf (for calculating the cumulative distribution function of a Gaussian distribution), and norminv (for calculating the inverse of the cumulative distribution function of a Gaussian distribution).

Similar threads

  • Advanced Physics Homework Help
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
9K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
825
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Advanced Physics Homework Help
Replies
6
Views
1K
  • Introductory Physics Homework Help
Replies
27
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
954
  • Introductory Physics Homework Help
Replies
12
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
939
Back
Top