How do I linspace this plot?

4 次查看(过去 30 天)
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 个评论
KALYAN ACHARJYA
KALYAN ACHARJYA 2019-6-14
'm trying to slice a plot into sectors using linspace...slice 2 D Plot?
Warm Cup
Warm Cup 2019-6-14
Yes. I want to make it look like this:1.PNG

请先登录,再进行评论。

采纳的回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2019-6-14
编辑:KALYAN ACHARJYA 2019-6-14
stem(freq/1e+12,2*abs(X(1:NFFT/2+1)))
Use stem, instead of plot
  2 个评论
Warm Cup
Warm Cup 2019-6-14
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 2019-6-14
编辑:KALYAN ACHARJYA 2019-6-14
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by