# 从MATLAB帮助文档上学习 chirp

【 MATLAB 】适合初学者的 chirp 理解与推导

MATLAB 中称 chirp 为 Swept-frequency cosine，也即扫频余弦波。

MATLAB 中给出了 chirp 如下的语法结构：

y = chirp(t,f0,t1,f1) 在阵列t中定义的时间实例中产生线性扫频余弦信号的样本，f0为时间为0时刻的瞬时频率，f1为时刻t1时的瞬时频率，二者单位都是赫兹。如果未指定，则对于logarithmic chirp，f0为10^-6;对于其他的chirp，f0都为0,t1为1，f1为100.

y = chirp(t,f0,t1,f1,'method') 指定可选择的扫频方法，扫频方法介绍如下：

y = chirp(t,f0,t1,f1,'method',phi) allows an initial phase phi to be specified in degrees. If unspecified, phi is 0. Default values are substituted for empty or omitted trailing input arguments.

y = chirp(t,f0,t1,f1,'quadratic',phi,'shape') specifies the shape of the quadratic swept-frequency signal's spectrogram. shape is either concave or convex, which describes the shape of the parabola in the positive frequency axis. If shape is omitted, the default is convex for downsweep (f0 > f1) and is concave for upsweep (f0 < f1).

y = chirp（t，f0，t1，f1，'quadratic'，phi，'shape'）指定二次扫频信号的频谱图的形状。 形状是凹形或凸形，它描述了正频率轴上抛物线的形状。 如果省略形状，则默认为下扫频（f0> f1）为凸，而上扫频（f0 <f1）为凹。

### Linear chirp

Generate a chirp with linear instantaneous frequency deviation. The chirp is sampled at 1 kHz for 2 seconds. The instantaneous frequency is 0 at t = 0 and crosses 250 Hz at t = 1 second.

% Generate a chirp with linear instantaneous frequency deviation.
% The chirp is sampled at 1 kHz for 2 seconds.
% The instantaneous frequency is 0 at t = 0 and crosses 250 Hz at t = 1 second.

clc
clear
close all

t = 0:1/1e3:2;
y = chirp(t,0,1,250);
subplot(2,1,1)
plot(t,y)
subplot(2,1,2)
spectrogram(y,256,250,256,1e3,'yaxis')

Generate a chirp with quadratic instantaneous frequency deviation. The chirp is sampled at 1 kHz for 2 seconds. The instantaneous frequency is 100 Hz at t = 0 and crosses 200 Hz at t = 1 second.

% Generate a chirp with quadratic instantaneous frequency deviation.
% The chirp is sampled at 1 kHz for 2 seconds.
% The instantaneous frequency is 100 Hz at t = 0 and crosses 200 Hz at t = 1 second.

clc
clear
close all

t = 0:1/1e3:2;
subplot(2,1,1)
plot(t,y)

% Compute and plot the spectrogram of the chirp.
% Specify 128 DFT points, a Hamming window of the same length, and 120 samples of overlap.

subplot(2,1,2)
spectrogram(y,256,250,256,1e3,'yaxis')

### Logarithmic Chirp

% Generate a logarithmic chirp sampled at 1 kHz for 10 seconds.
% The instantaneous frequency is 10 Hz initially and 400 Hz at the end.

clc
clear
close all

t = 0:1/1e3:10;
fo = 10;
f1 = 400;
y = chirp(t,fo,10,f1,'logarithmic');
subplot(2,1,1)
plot(t,y)

% Compute and plot the spectrogram of the chirp.
% Specify 256 DFT points, a Hamming window of the same length, and 200 samples of overlap.

subplot(2,1,2)
spectrogram(y,256,200,256,1e3,'yaxis')