How do I linspace this plot?

조회 수: 6 (최근 30일)
Warm Cup
Warm Cup 2019년 6월 14일
편집: KALYAN ACHARJYA 2019년 6월 14일
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에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by