How do I linspace this plot?

4 vues (au cours des 30 derniers jours)
Warm Cup
Warm Cup le 14 Juin 2019
I'm trying to slice a plot into sectors using linspace. This is the code I'm using:
c = 3e+8; % Speed of light [m/sec]
lambda = 1665e-9; % Wavelength [nm]
freq = c/lambda; % Actual Frequency of light [THz]
fsamp = freq*10; % Sampling frequency
fs = 1/fsamp; % Unit time [fs]
Ls = 200; % Length of signal
sig = 8e-15; % Pulse duration
ts = (0:Ls-1)*fs; % Time base
t0 = max(ts)/2; % Used to centering the pulse
Egauss = (exp(-2*log(2)*(ts-t0).^2/(sig)^2)).*cos(-2*pi*freq*(ts-t0));
subplot(2,1,1)
plot(ts/1e-15,real(Egauss),'b');
title(['Gaussian Pulse \sigma=', num2str(sig),'s']);
xlabel('Time (fs)');
ylabel('Amplitude');
ylim([-1 1])
%xlim([30e-15 70e-15])
grid on
NFFT = 2^nextpow2(Ls);
X = fft(Egauss,NFFT)/Ls;
freq = 0.5*fsamp*linspace(0,1,NFFT/2+1); % (full range) Frequency Vector
subplot(2,1,2)
plot(freq/1e+12,2*abs(X(1:NFFT/2+1)))
title('Magnitude of FFT');
xlabel('Frequency (THz)')
ylabel('Magnitude |X(f)|');
xlim([65 300])
grid on
%f = linspace(60*10^12,280*10^12,1000)';
I need to get a 1000 frequency slices from 'freq' plot that starts from 60 to 280 THz. How do I linspace the frequency domain of the gaussian pulse(fft of the time domain)?
  2 commentaires
KALYAN ACHARJYA
KALYAN ACHARJYA le 14 Juin 2019
'm trying to slice a plot into sectors using linspace...slice 2 D Plot?
Warm Cup
Warm Cup le 14 Juin 2019
Yes. I want to make it look like this:1.PNG

Connectez-vous pour commenter.

Réponse acceptée

KALYAN ACHARJYA
KALYAN ACHARJYA le 14 Juin 2019
Modifié(e) : KALYAN ACHARJYA le 14 Juin 2019
stem(freq/1e+12,2*abs(X(1:NFFT/2+1)))
Use stem, instead of plot
  2 commentaires
Warm Cup
Warm Cup le 14 Juin 2019
Thanks. But how do I increase the number of discrete lines in the plot? I'm also trying to get the value of each discrete line, similar to linspace.
KALYAN ACHARJYA
KALYAN ACHARJYA le 14 Juin 2019
Modifié(e) : KALYAN ACHARJYA le 14 Juin 2019
reduce fsamp, like as follows
fsamp = freq*5; % Sampling frequency;
%............^ I hav decresed this value from 10 to 5, check it.
For second question get the value, add the following line at end on the code
disp(2*abs(X(1:NFFT/2+1)));
Run it and check in command window

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by