plot a inear sweep & stepped sweep

조회 수: 7 (최근 30일)
ting po chun
ting po chun 2023년 7월 1일
댓글: ting po chun 2023년 7월 2일
Hello,
I am try to plot a linear sweep & stepped sweep. (The attached picture)
condition:
Freauency range from 20Hz-20kHz
Time from 0-100ms
How the code can do it ? Tnanks!
  댓글 수: 4
Image Analyst
Image Analyst 2023년 7월 2일
Would the built-in chirp function help you?
help chirp
CHIRP Swept-frequency cosine generator. Y = CHIRP(T) generates samples of a swept-frequency signal at the time instances defined in array T. By default, the instantaneous frequency at time 0 is 0, and the instantaneous frequency one second later is 100 Hz. Y = CHIRP(T,F0,T1,F1) generates samples of a linear swept-frequency signal at the time instances defined in array T. The instantaneous frequency at time 0 is F0 Hz. The instantaneous frequency F1 is achieved at time T1. Y = CHIRP(T,F0,T1,F1,method) specifies alternate sweep methods. Available methods are 'linear', 'quadratic', and 'logarithmic'; the default is 'linear'. For a logarithmic-sweep, F0 must be greater than or equal to 1e-6 Hz, which is also the default value. Y = CHIRP(T,F0,T1,F1,method,PHI) specifies an initial phase PHI in degrees. By default, PHI = 0. Y = CHIRP(T,FO,T1,F1,'quadratic',PHI,'concave') generates samples of a quadratic swept-frequency chirp signal whose spectrogram is a parabola with its concavity in the positive frequency axis. Y = CHIRP(T,FO,T1,F1,'quadratic',PHI,'convex') generates samples of a quadratic swept-frequency signal whose spectrogram is a parabola with its convexity in the positive frequency axis. Y = CHIRP(...,sigtype) specifies sigtype as 'real' or 'complex'; the default is 'real'. When sigtype is set to 'real', CHIRP generates real chirp signals. When set to 'complex', CHIRP generates complex chirp signals. EXAMPLE 1: Compute the spectrogram of a linear chirp. t = 0:0.001:2; % 2 s at 1 kHz sample rate y = chirp(t,0,1,150); % Start at DC, cross 150 Hz at % t = 1 s spectrogram(y,256,250,256,1E3); % Display the spectrogram EXAMPLE 2: Compute the spectrogram of a quadratic chirp. t = -2:0.001:2; % +/-2 s at 1 kHz sample rate y = chirp(t,100,1,200,'q'); % Start at 100 Hz, cross 200 Hz at % t = 1 s spectrogram(y,128,120,128,1E3); % Display the spectrogram EXAMPLE 3: Compute the spectrogram of a convex quadratic chirp t = 0:0.001:1; % 1 s at 1 kHz sample rate fo = 25; % Start at 25 Hz, f1 = 100; % go up to 100 Hz y = chirp(t,fo,1,f1,'q',[],'convex'); spectrogram(y,256,200,256,1000); % Display the spectrogram. EXAMPLE 4: Compute the spectrogram of a concave quadratic chirp t = 0:0.001:1; % 1 s at 1 kHz sample rate fo = 100; % Start at 100 Hz, f1 = 25; % go down to 25 Hz y = chirp(t,fo,1,f1,'q',[],'concave'); spectrogram(y,256,200,256,1000); % Display the spectrogram. EXAMPLE 5: Compute the spectrogram of a logarithmic chirp t = 0:0.001:10; % 10 s at 1 kHz sample rate fo = 10; % Start at 10 Hz, f1 = 400; % go up to 400 Hz y = chirp(t,fo,10,f1,'logarithmic'); spectrogram(y,256,200,256,1000); % Display the spectrogram EXAMPLE 6: Compute a complex-valued linear chirp t = 0:0.001:2; % 2 s at 1 kHz sample rate fo = -50; % Start at -50 Hz, t1 = 1; f1 = 200; % cross 200 Hz at t = 1 s y = chirp(t,fo,t1,f1,'complex'); spectrogram(y,256,200,256,1000,'centered'); % Display the spectrogram See also GAUSPULS, SAWTOOTH, SINC, SQUARE. Documentation for chirp doc chirp
ting po chun
ting po chun 2023년 7월 2일
Thanks for your help. But i want to plot like the picture. one line is linear other one is stepped.

댓글을 달려면 로그인하십시오.

답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2023년 7월 2일
편집: KALYAN ACHARJYA 2023년 7월 2일
t=0:8:100;
f=linspace(20,2000,length(t));
stairs(t,f);
xlabel('Time');
ylabel('Frequency');
hold on
plot(0:100,linspace(20,2000,101))
hold off
If the use of the inbuilt stair function is not allowed, modify the code according to the requirements, finding alternative methods such as the step function or other approaches can be done.
  댓글 수: 2
ting po chun
ting po chun 2023년 7월 2일
Thank so much & thank all of your help
ting po chun
ting po chun 2023년 7월 2일
Now i have the other queston.
I want to plot a stepped frequency singal (like the picture)
(Time during 0 to 1 sec)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Simulation, Tuning, and Visualization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by