MATLAB Digital Signal Processing
1, the waveform generation function
function | Explanation |
---|---|
square | HoNami |
sawtooth | Sawtooth |
sinc | sinc function |
diric | diric function |
rectpuls | Non-cycle square wave |
tripuls | Aperiodic triangle wave |
pulse transmitter | Pulse sequence |
chirp | FM cosine wave |
-
square function : call as follows:
-
x = square (t): resulting in a period 2pi, the maximum amplitude of a square wave.
-
x = square (t, duty): resulting in a period 2pi, the maximum amplitude of a square wave, duty is the duty cycle.
Generating a periodic square function as a duty ratio were 50% and 30% square wave:
t = 0:0.001:4; y1 = square(2*pi*t); y2 = square(2*pi*t, 30); subplot(1, 2, 1); plot(t, y1); subplot(1, 2, 2); plot(t, y2); axis([0, 4, -1.5, 1.5]);
-
-
sawtooth function: call as follows:
- x = sawtooth (t, width): resulting in a period 2pi, sawtooth 1 peak, width and the abscissa represents the ratio of the cycle position.
Generating a sawtooth periodic sawtooth function and square wave 1:
t = 0:0.001:4; y1 = sawtooth(2*pi*t); y2 = sawtooth(2*pi*t, 0.5); subplot(1, 2, 1); plot(t, y1); subplot(1, 2, 2); plot(t, y2); axis([0, 4, -1, 1]);
-
sinc function: call as follows:
- x = sinc (t): generating a sinc function waveform.
Sinc function waveform is generated by:
t = -5:0.001:5; y = sinc(t); plot(t,y); axis([-5 5 -1 1]);
-
diric function: call as follows:
- x = diric (x, n): when n is an odd number, as a function of cycle 2pi; when n is even, periodic function of 4pi.
Generating waveforms diric functions:
t = -15:0.05:15; y1 = diric(t, 5); y2 = diric(t, 6); subplot(121); plot(t, y1); subplot(122); plot(t, y2); axis([-15 15 -1 1]);
-
rectpuls function: call as follows:
- x = rectpuls (t, w): w is the width of the non-generation period, in the height of the rectangular wave.
Generating rectpuls function with length 1s, a width of the non-periodic rectangular wave 0.7s:
t = 0:0.01:1; y = rectpuls(t, 0.7); plot(t, y); axis([0 1 -0.2 1]);
-
tripuls function: call as follows:
-
x = tripuls (t, width, s): generating a non-periodic unit height, width width, the inclination s of the triangular wave.
Generating tripuls function with length 1s, a width of 0.6s, 0.9 and 0 respectively, the inclination of the non-periodic triangular wave:
t = 0:0.01:1; y1 = tripuls(t, 0.6, 0); subplot(121); plot(t, y1); y2 = tripuls(t, 0.6, 0.9); subplot(122); plot(t, y2); axis([0 1 -0.2 1]);
-
-
pulstran function: call as follows:
- x = pulstran (t, d, 'func'): wherein the parameter value is func gauspuls (Gaussian modulated sinusoidal signal); rectpuls (non-periodic square wave); tripuls (non-periodic triangular wave). This function generates a predetermined shape by d sampling interval of the impulse string func;
- x = pulstran (t, d, 'func', p1, p2): The parameters p1 and p2 to the transfer function func;
- x = pulstran (t, d, p, Fs): vector p represent the original sequence, Fs is the sampling rate. The delay times of the original sequence obtained by adding the output sequence.
Triangular wave generated by an impulse function pulstran string:
t = 0:0.001:1; d= 0:1/3:1; y = pulstran(t, d, 'tripuls'); plot(t, y); axis([0 1 1.3 1.75]);
-
chirp function: call as follows:
- chirp (t, f0, t1, f1): chirp generating a cosine signal. f0 and f1 are the instantaneous frequency at time zero and the time t1.
- chirp (t, f0, t1, f1, method): method parameter specifies different sweep mode, ranging comprising three ways:
Linear linear
quadratic quadratic
logarithmic logarithm
Secondary chirp sweep signal is a function of frequency is depicted in FIG time domain waveform and time:
t = 0:1/400:1; y = chirp(t, 10, 1, 100, 'quadratic'); plot(t, y); spectrogram(y,128,120,128,1000,'yaxis'); axis([0 1 -1 1]);
t = 0:1/400:1;
y = chirp(t, 10, 1, 100, 'quadratic');
plot(t, y);
%spectrogram(y,128,120,128,1000,'yaxis');
axis([0 1 -1 1]);
2, the Fourier transform function
function | Explanation |
---|---|
fft | Fast computing discrete Fourier transform |
fftshift | Fft output order adjusting function, the center position to the zero frequency spectrum |
ifft | Computing inverse discrete Fourier transform |
- fft function: call as follows:
- y = fft (x): a fast Fourier transform calculated signals x y. When the length x of a power of 2, a base 2 algorithm uses a slower or split radix algorithm.
- y = fft (x, n): n calculated point FFT. When the length (x)> n, truncation x, or zeros.
- fftshift function: call as follows:
- y = fftshift (x): If x is a vector, fftshift (x) directly to the left and right two parts exchange x; if x is a matrix (multichannel signals), x is the upper left, lower right and upper right, lower left part of the two four two exchange.
- ifft function: call as follows:
- y = ifft (x): Fourier inverse transform calculated signals x
- y = ifft (x, n): n calculated point IFFT. If the length (x)> n, where n is the length of the truncated to x, or zeros.
3, the filter function is realized and Analysis
Function name | |
---|---|
conv | Convolved |
IMPZ | Impulse response digital filter |
zplane | Pole-zero plot discrete systems |
abs | Amplitude calculation |
angle | Seeking phase angle |
filter | Direct form II filter |
-
conv function: call as follows:
- c = conv (a, b): Returns a vector of a, b convolution c.
-
impz function: call as follows:
- [H, t] = impz (b, a): Molecular b, a, respectively, and the system transfer function denominator coefficient vector. System return impulse (b, a) and the respective axis in response vector h t.
- [H, t] = impz (b, a, n): impulse response return point n.
- [H, t] = impz (b, a, n, Fs): Specifies the interval of impulse response samples 1 / Fs. Fs is the relative frequency, a default value.
Computing impulse linear system (b, a) in response to:
b = [0.2 0.1 0.3 0.1 0.2]; a= [1 -1.1 1.5 -0.7 0.3]; impz(b,a,50);
-
zplane function: call as follows:
- zplane (z, p): pole-zero plot rendering system, "o" represents zero, "x", represents a pole. z, p are zero and pole vector.
- zplane (b, a): b , a transfer system are numerator and maternal functions
of a vector.
Computing linear system (b, a) of zeros and poles:
b = [0.2 0.1 0.3 0.1 0.2]; a= [1 -1.1 1.5 -0.7 0.3]; zplane(b, a);
-
abs function: call as follows:
- y = abs (x): Returns the magnitude of the complex vector y vector x.
It depicts a sinusoidal signal amplitude spectrum of the Fourier transform:
t = (0:99)/100; x = sin(2*pi*40*t); y = fft(x); m = abs(y); f = (0:length(y)-1)/length(y)*100; plot(f,m);
-
angle functions: call as follows:
- p = angle (h): returns the complex vector h of phase vectors p.
Depicts a square wave signal with frequency characteristics:
t = (0:99)/10000; x = sin(2*pi*t); y = fft(x); m = angle(y); f = (0:length(y)-1)/length(y)*100; plot(f,m);
-
filter function: call as follows:
- y = filter (b, a, x): x calculates the input signal through a transfer function numerator and denominator coefficient vector (in descending order) as the output y b, a filter.
- [Y, zf] = filter (b, a, x): returns the final state vector zf.
- [...] = filter (b, a, x, zi): the initial conditions specified filter zi.