MATLAB Signal Processing Simulation Introductory Experiment

MATLAB Signal Processing Simulation Introductory Experiment (Reference Experiment)

DFT analysis of sinusoidal signals

The purpose of this simulation is to configure the amplitude-frequency characteristic parameters and analysis parameters of the signal, and then observe the windowed amplitude spectrum of the signal after the two sinusoidal signals are synthesized. These parameters include:
[1] The amplitude and frequency of the two sine waves
[2] The number of quantized bits of the signal (usually 8-16)
[3] The sampling rate of the signal
[4] The beta value of the Kaiser window, note that beta=0 When , the equivalent rectangular window, the larger the beta, the wider the main lobe and the lower the side lobes.
[5] The sampling length of the signal, that is, the length of the DFT spectral analysis.
By modifying these simulation parameters, under what circumstances can the two sinusoidal spectral peaks overlap into one spectral peak, which is not easy to distinguish?
If the frequencies of the two signals are relatively close, but the specific frequencies are not known, but the approximate range is known, how to adjust other parameters (parameters other than frequency and amplitude) to help distinguish the spectral peaks of the two sinusoidal signals .
Supplement:
1. Use column vectors as much as possible. Inside matlab, vectors are stored in columns.
2. a = [1;2;3;4] defines a column vector. The square brackets are used to splicing scalars into vectors, and vectors can also be spliced ​​into larger vectors, but note that the spliced ​​should be row vectors or both Column vector
3, b = a(1:3) Take out the 1st to 3rd components of the vector a and save them to the b vector. The parentheses are used for component addressing, and the colon is used to specify the range. The expression 1:3 A row vector is generated, [1 2 3], and this row vector is used as the addressing parameter to fetch the components of the a vector.
4. Conjugate transpose and ordinary transpose, a = [1+j, 2+j, 3+j] ; b = a'; c=a.'; b is the conjugate transpose of a, c is a Ordinary transpose of . Confusion of these two transposes can lead to very subtle bugs.

%///////////////////////////////////////////////////////////
% DFT analyse of sampled sine signal
%///////////////////////////////////////////////////////////
close all;
clear;
clc;
% generate 2 sampled sine signals with different frequency(生成2个不同频率的采样正弦信号)
freq_x1         = 20.0E3        ;  % frequency of signal x1
amp_x1          = 10            ;  % amptitude of signal x1
freq_x2         = 30.0E3        ;  % frequency of signal x2
amp_x2          = 10            ;  % amptitude of signal x2
data_len        = 512           ;  % signal data length
fs              = 512E3         ;  % sample rate(采样率)
quant_bits      = 12            ;  % signal quant bits(信号量化比特数)
kaiser_beta     = 8             ;  % beta of kaiser win

idx_n           = [0:data_len-1];  % n index
idx_n           = idx_n .'      ;  % we need column vector(列向量)
idx_t           = idx_n/fs      ;  % time index
idx_phase_x1    = 2*pi*idx_n*freq_x1/fs;  % x1 phase  index(x1相位指数)
idx_phase_x2    = 2*pi*idx_n*freq_x2/fs;  % x2 phase  index
x1              = amp_x1*sin(idx_phase_x1);
x2              = amp_x2*sin(idx_phase_x2);
% signal x is consisted of x1 and x2;
x = x1 + x2;
max_abs_x = max(abs(x));    %   abs-求数值的绝对值与复数的幅值  %  normalize x to (-1,1)
x = x / max_abs_x;           % quant signal, the range is (-max_q, +max_q)
max_q = 2^(quant_bits-1);
x_quant = fix(x * max_q);   % plot them, use time label
figure;
set(gca,'fontsize',16);     % get window function data(获取窗口函数数据)(set-设置对象属性)
win = kaiser(data_len, kaiser_beta);    % windowing the data
win_x       =  win .* x;
win_x_quant =  win .* x_quant;

h_t1 = subplot(4,1,1);plot(idx_t, x1   );grid on;
h_t2 = subplot(4,1,2);plot(idx_t, x2   );grid on;
h_t3 = subplot(4,1,3);plot(idx_t, x    );grid on;
h_t4 = subplot(4,1,4);plot(idx_t, win_x);grid on;
title(h_t1, 'x1'        , 'fontsize', 14);
title(h_t2, 'x2'        , 'fontsize', 14);
title(h_t3, 'x=x1+x2'   , 'fontsize', 14);
title(h_t4, 'windowed x', 'fontsize', 14);

% perform fft
x_q_fft         =  fft(win_x_quant)    ;    % get frequency index(指数)
idx_freq        = -fs/2 + idx_n .* (fs / data_len);
% shift zero frequency to the data center
x_q_fft         =  fftshift(x_q_fft);
% map to amptitude dB scale
x_q_fft_abs     =  abs(x_q_fft);
x_q_fft_abs_dB  =  20*log10(x_q_fft_abs + 1E-8);
% normalize the spectrum from 0 dB;
max_dB = max(x_q_fft_abs_dB);
norm_spectrum   =  x_q_fft_abs_dB - max_dB;
figure; plot(idx_freq, norm_spectrum);grid on;
title('Normlized Spectrum ', 'fontsize', 14);

Using function wrappers, multi-tone sine and spectral analysis

Matlab is a scripted programming language, and in a sense, it is also a part of computer science. In the software industry, reuse is a very important idea. Use functions (process-oriented) or classes ( Object-oriented) encapsulate it, leaving the data type definition of the interface, which can be easily used again in the future.
For multi-tone signals, we have different requirements when generating such signals, such as what is the sampling rate of the signal; how many frequency components are there in the signal; what is the vector length of the signal; and the quantization of the signal What is the precision. Well, for novice students in digital signal processing, please always think about the sampling rate and quantization accuracy of discrete signals. Only equipped with these parameters, a discrete sequence is truly endowed with the meaning of "digital signal". Since these signal configuration parameters need to be specified when generating the signal, these parameters are used as the entry parameters of the function of generating the multi-tone signal.
Similarly, for the spectral analysis function, the sampling rate of the input signal needs to be configured. If the input signal is used as a vector of a single frame, the analysis length is usually the value of the nth power of 2 that is closest to the vector. For example, if the input data is 150 points, then The analysis length is chosen to be 128, because matlab's radix-2-FFT algorithm is the fastest, and other special point algorithms are slower. In addition, since the frequency components of the signal to be analyzed are unknown, that is to say, we do not know how many spectral peaks there may be and their distances. Therefore, the shape of the window function needs to be dynamically specified, so the Kaiser window is a very useful thing. , because it digitizes the shape of the window function, we no longer need to record a bunch of cumbersome window function names.

Sample-based model of FIR filter

FIR filter features:
[1] (generalized) linear phase, that is to say, any frequency component of the signal passes through this filter, the delay is the same (the group delay is constant), this property is more important for the communication system, for the human ear Not very important, because the human ear is not phase sensitive.
[2] The shape of the amplitude-frequency response can be set more accurately. In contrast, IIR or analog filters use zero-pole points to control the frequency response, which is relatively inflexible. fir can set an amplitude-frequency curve, and then The tap coefficients are generated by an algorithm. Of course, the more accurate, the more tap coefficients are required, and the greater the amount of computation.
[3] Compared with IIR with feedback loop, FIR does not self-oscillate because it has no feedback data loop, while IIR does not. The data loop means that there is a pole, and it is very sensitive to the quantization noise of the coefficients. The pole position offset caused by the error can easily cause the filter to self-oscillate, while the FIR has only zero points, and the quantization error of the coefficient and data will only increase the noise of the output data without self-oscillation.
Disadvantages of FIR filter: FIR is much more computationally intensive than IIR.

Interpolating FIR filter

One of the important branches in the field of software radio - digital up-conversion and down-conversion, in terms of digital up-conversion, the key technologies are interpolation filtering and DDS technology. Interpolation filtering technique, also known as upsampling, or sampling rate boosting.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324472165&siteId=291194637