Digital signal processing (MATLAB) [number of sampling points, spectrum leakage, FIR filter design]

topic

As shown in Figure 1, by x ( t ) x(t)x ( t ) signalx 1 ( t ) x_1(t)x1( t ) , signalx 2 ( t ) x_2(t)x2( t ) and signalx 3 ( t ) x_3(t)x3( t ) and composition. Forx ( t ) x(t)x ( t ) is uniformly sampled (the sampling period isT s = 0.25 ms T_s=0.25msTs=0.25 m s ), get its sample signalx ( n T s ) x(nT_s)x(nTs)
insert image description here
其中, x i ( t ) = A i c o s ( 2 π f i t ) x_i(t)=A_icos(2\pi f_it) xi(t)=Aicos(2πfit ) , parameterA i A_iAisum fi f_ifias shown in the table below

i= 1 i= 2 i= 3
A i A_i Ai 0.2 2 0.4
f i f_i fi 0.99kHz 0.98kHz 1.6kHz

question

(for reference)

Fourier transform

(1) Find x ( t ) x(t)Fourier transform of x ( t ) , and draw its amplitude-frequency response curve.

Solution: Since x ( t ) x(t)x ( t ) by the signalx 1 ( t ) x_1(t)x1( t ) , signalx 2 ( t ) x_2(t)x2( t ) and signalx 3 ( t ) x_3(t)x3( t ) and composition. Thusx ( t ) x(t)x ( t ) is expressed as:

x ( t ) = ∑ i = 1 3 x i ( t ) = ∑ i = 1 3 A i cos ⁡ ( 2 π f i t ) x(t)= \sum\limits_{i = 1}^3 { {x_i}\left( t \right)} {\rm{ = }}\sum\limits_{i = 1}^3 { {A_i}\cos ( {2\pi {f_i}t} )} x(t)=i=13xi(t)=i=13Aicos(2πfit)

From the Fourier transform formula X ( j ω ) = ∫ − ∞ + ∞ x ( t ) e − j ω tdt X(j\omega ) = \int_{ - \infty }^{ + \infty } {x(t )} {e^{ - j\omega t}}dtX()=+x(t)et dt

F [ x ( t ) ] = F [ ∑ i = 1 3 xi ( t ) ] = ∑ i = 1 3 A and π [ δ ( ω − 2 π fi ) + δ ( ω + 2 π fi ) ] = π [ δ ( ω − 2 ∗ 990 π ) + δ ( ω + 2 ∗ 990 π ) ] + 2 π [ δ ( ω − 2 ∗ 980 π ) + δ ( ω + 2 ∗ 980 π ) ] + 0.4 π δ ( ω − 2 ∗ 1600 π ) + δ ( ω + 2 ∗ 1600 π ) ] { \cal F}\left[ {x\left( t \right)} \right] = {\cal F}\left[ {\sum\limits_{i = 1}^3 { {x_i}\left( t \right)} } \right]\ = \sum\limits_{i = 1}^3 { { A_i}\pi \left[ {\delta(\omega - 2\pi {f_i}) + \delta(\omega + 2\pi{f_i})} \right]} \\ = 0.2\pi \left[ {\delta(\omega - *990\pi ) + \delta (\omega + 2*990\pi )} \right] + \\ 2\pi \left[ {\delta (\omega - 2*980\pi ) + \delta (\omega + 2*980\pi )} \right] + \\ 0.4\pi \left[ {\delta (\omega - 2*1600\pi ) + \delta (\omega + 2*1600\pi )} \right]F[x(t)]=F[i=13xi(t)] =i=13AiPi[ d ( o2πfi)+d ( o+2πfi)]=0.2 p[ d ( o2990 p )+d ( o+2990 p ) ]+2 p.m[ d ( o2980 p )+d ( o+2980 p ) ]+0.4 p[ d ( o21600 p )+d ( o+21600 BC ) ]

%傅里叶变换
clc;
clear;
syms t;
x1=0.2*cos(2*pi*1280*t);
x2=2*cos(2*pi*1290*t);
x3=0.4*cos(2*pi*1800*t);
x=x1+x2+x3; %x(t)信号由x1、x2、x3的和组成。
F=fourier(x)
%幅频响应曲线
close all;
clear;
clc;
Ts=0.00025;              %采样周期,以0.25ms的周期均匀采样
Fs=1/Ts;				 %采样频率
t=0:Ts:1-Ts;             %采样间隔时长
x1=0.2*cos(2*pi*990*t);  %三分量信号
x2=2*cos(2*pi*980*t);
x3=0.4*cos(2*pi*1600*t);
x=x1+x2+x3; %x(t)信号由x1、x2、x3的和组成。
figure(1);
subplot(2,1,1);
plot(t,x);
xlabel('时间/s');ylabel('幅值');
title("original signal");%绘制原始信号图
%频域
N=(1-Ts)/Ts+1;%采样点数
n=0:N-1;
fft_x=n*Fs/N-Fs/2;
x_fft=fft(x);
shift_f=abs(fftshift(x_fft));
y2=2*shift_f/N;
subplot(2,1,2);
plot(fft_x,y2);
xlabel('频率/Hz');ylabel('幅值');
title('FFT');  %0频率分量位于坐标中心
grid on;

x 3 ( t ) x_3(t) x3( t ) signal:
insert image description here
spectrogram:
insert image description here

Minimum number of sampling points

(2) If you want to obtain the sample signal x ( n T s ) x(nT_s)x(nTs) , the signal x 1 ( t ) x_1(t)can be effectively distinguished by DFTx1(t) x 2 ( t ) x_2(t) x2( t ) andx 3 ( t ) x_3(t)x3( t ) , try to find the minimum number of sampling points N required, and draw the sample signalx ( n T s ) x(nT_s)x(nTs) Spectrogram of the principal value interval of the discrete Fourier transform (DFT) of (2), marking the digital frequency and its corresponding analog frequency.
Solution: Analysis shows that the original time-domain analog signal is
x ( t ) = ∑ i = 1 3 xi ( t ) = ∑ i = 1 3 A i cos ⁡ ( 2 π fit ) = 0.2 cos ⁡ ( 2 π × 990 t ) + 2 cos ⁡ ( 2 π × 980 t ) + 0.4 cos ⁡ ( 2 π × 1600 t ) x\left( t \right) = \sum\limits_{i = 1}^3 { {x_i}\left( t \right)} {\rm{ = }}\sum\limits_{i = 1}^3 { {A_i}\cos \left( {2\pi {f_i}t} \right)} = 0.2\cos \left ( {2\pi \times 990t} \right) + 2\cos \left( {2\pi \times 980t} \right) + 0.4\cos \left( {2\pi \times 1600t} \right)x(t)=i=13xi(t)=i=13Aicos(2πfit)=0.2cos( 2 p×990 t )+2cos( 2 p×980 t )+0.4cos( 2 p×1600 t )
, that is, the three frequency components of the signal aref 1 = 990 H z f_1=990Hzf1=990Hz, f 2 = 980 H z f_2=980Hz f2=980Hz, f 3 = 1600 H z f_3=1600Hz f3=
The sampling period of 1600 Hz is T s = 0.25 ms T_s=0.25msTs=0.25 m s , according to the relationship between sampling interval and sampling frequency, fs = 1 T s = 1 0.25 ms = 4000 H z {f_s} = \frac{1}{ { { T_s}}} = \frac{1}{ { 0.25ms}} = 4000Hzfs=Ts1=0.25ms1=
The discrete sequence obtained after 4000 Hz sampling is x ( n ) = xa ( t ) ∣ t = n T s = 0.2 cos ⁡ ( 99 π 200 n ) + 2 cos ⁡ ( 49 π 100 n ) + 0.4 cos ⁡ ( 4 π 5 n ) x(n) = {x_a}(t){|_{t = n{T_s}}} = 0.2\cos (\frac{ {99\pi }}{ {200}} n ) + 2 \cos (\frac{ {49\pi }}{ {100}}n) + 0.4\cos (\frac{ {4\pi }}{5}n)x(n)=xa(t)t=nTs=0.2cos(20099 pn)+2cos(10049 BCn)+0.4cos(54 p.mn )
Specify a smooth surface
2 π ω 1 = 2 π × 200 99 π = 400 99 2 π ω 2 = 2 π × 100 49 π = 200 49 2 π ω 1 = 2 π × 5 4 π = 5 2 \begin{array}{l} \frac{ {2\pi}}{ { {\omega_1}}} = 2\times \frac{ {200}}{ {99\pi}} = \frac{ {400}}{ {99}}\\\frac{ {2\pi}}{ { {\omega_2}}} = 2\pi\frac{ {100}}{ {49\pi}} = \frac{ {200}}{ {49}}\\\frac{ {2\pi}}{ { {\omega_1}}} = 2\pi \times \frac{5}{ {4\pi}} = \frac{5}{2}\end{array}oh12 p.m=2 p.m×99 p200=99400oh22 p.m=2 p.m×49 p100=49200oh12 p.m=2 p.m×4 p.m5=25
It can be seen that the least common multiple is N=400, so the period of x(n) is N=400.
The data length of one cycle is T 0 = NT s = 400 × 0.25 ms = 0.1 s {T_0} = N{T_s} = 400 \times 0.25ms = 0.1sT0=NTs=400×0.25ms=0.1 s
When the number of sampling points is an integer multiple of the period, there will be no spectrum leakage.
Since the smallest frequency interval in the signal is( f 1 − f 2 = 10 H z ) ({f_1} - {f_2} = 10Hz)(f1f2=10 Hz ) soF 0 = 10 Hz F_0=10HzF0=10 Hz , the required data length for this isT 0 = 1 F 0 = 1 10 H z = 0.1 s {T_0} = \frac{1}{ { { F_0}}} = \frac{1}{ {10Hz }} = 0.1sT0=F01=10Hz1=0.1 s
is the same as the data length of one cycle, and the number of sampling pointsN ≥ fsf 1 − f 2 = 400 N \ge \frac{ { { {\rm{f}}_{\rm{s}}}}}{ { {f_1} - {f_2}}} = 400Nf1f2fs=400 , so the minimum number of sampling points N required is 400.
Digital angular frequencyω = 2 π ff S \omega = \frac{ {2\pi f}}{ { {f_S}}}oh=fS2πf, the digital frequencies are ω 1 = 0.154 , ω 2 = 0.156 , ω 3 = 0.251 {\omega _1} = 0.154,{\omega _2} = 0.156,{\omega _3} = 0.251oh1=0.154,oh2=0.156,oh3=0.251 .
Using MATLAB method to do spectrum analysis, the results are shown in the figure.
insert image description here
insert image description here
insert image description here

clear all;
clc;
Ts=0.00025;     %采样间隔为0.25ms
fs=1/Ts;
N=400;         %抽样点N取400,抽样频率fs取4000
n=[0:1:N-1];k=[0:1:N-1];
xn=0.2*cos(99*(pi/200)*n)+2*cos(49*(pi/100)*n)+0.4*cos(4*(pi/5)*n);%信号离散序列
WN=exp(-j*2*pi/N);
nk=n'*k;
WNnk=WN.^nk;
Xk=xn*WNnk;  %根据定义求信号DFT
X=abs(Xk);
figure(1);
stem(k,X,'*');
grid on;
xlabel('k');
title('幅频特性曲线(K=400,fs=4000Hz)');
ylabel('|X(k)|');
figure(2);
stem(2*pi/fs*k,X,'*');
grid on;
xlabel('数字频率');
title('数字频率(K=400,fs=4000Hz)');
ylabel('|X(k)|');
figure(3);
stem(fs/N*k,X,'*');
grid on;
xlabel('模拟频率');
title('模拟频率(K=400,fs=4000Hz)');
ylabel('|X(k)|');

spectrum leakage

(3) If the number of sampling points N=512, the sample signal x ( n T s ) x(nT_s)x(nTs) in the DFT of ), is there any spectrum leakage? If so, please analyze the cause of the spectrum leakage, the possible impact, and possible ways to alleviate it?

Solution: Analysis shows that when the number of sampling points N is 512, when the frequency spectrum k = 125, f 1 = k N × fs = 125 512 × 4000 = 976.6 H z ; when k = 126, f 1 = k N × fs = 126 512 × 4000 = 984.4 H zk = 125, {f_1} = \frac{k}{N} \times {f_s} = \frac{ {125}}{ {512}} \times 4000 = 976.6Hz; When k = 126, {f_1} = \frac{k}{N} \times {f_s} = \frac{ {126}}{ {512}} \times 4000 = 984.4Hzk=125 hours ,f1=Nk×fs=512125×4000=976.6Hz;k=126 hours ,f1=Nk×fs=512126×4000=984.4 Hz At this time, the frequency component of 980 Hz is between these two frequencies.
When k = 126, f 1 = k N × fs = 126 512 × 4000 = 984.4 H z ; when k = 127, f 1 = k N × fs = 127 512 × 4000 = 992.2 H When zk = 126, {f_1} = \frac{k}{N} \times {f_s} = \frac{ {126}}{ {512}} \times 4000 = 984.4Hz; when k = 127, {f_1} = \frac{k}{N } \times {f_s} = \frac{ {127}}{ {512}} \times 4000 = 992.2Hzk=126 , f1=Nk×fs=512126×4000=984.4Hz;k=127 , f1=Nk×fs=512127×4000=992.2 Hz At this time, the frequency component of 990 Hz is between these two frequencies.
When k = 204, f 1 = k N × fs = 204 512 × 4000 = 1593.8 H z ; when k = 205, f 1 = k N × fs = 205 512 × 4000 = 1601.6 H When zk = 204, {f_1} = \frac{k}{N} \times {f_s} = \frac{ {204}}{ {512}} \times 4000 = 1593.8Hz; when k = 205, {f_1} = \frac{k}{N } \times {f_s} = \frac{ {205}}{ {512}} \times 4000 = 1601.6Hzk=204 hours, f1=Nk×fs=512204×4000=1593.8 Hz ;k=205 o'clock, f1=Nk×fs=512205×4000=1601.6 Hz At this time, the frequency component of 1600 Hz is between these two frequencies.
The frequency resolution at this timeF 0 = fs N = 7.8 < 10 H z {F_0} = \frac{ { {f_s}}}{N} = 7.8 < 10HzF0=Nfs=7.8<10 Hz can meet the resolution requirement, but there will be a small amount of spectral leakage.
Causes of spectrum leakage: The number of sequence points taken is not an integer multiple of the sequence period. The occurrence of spectrum leakage is related to the length of signal time domain truncation, because in digital signal processing, the signal length cannot be infinitely long, the longer the signal length, the higher the resolution and the less spectrum leakage. Because truncating the time-domain signal is essentially multiplying a rectangular window, which is equivalent to convolution in the frequency domain.
Possible impact: The direct impact of spectrum leakage is that the frequency amplitude cannot be obtained accurately, because the signal amplitude at a certain frequency is equally divided by the surrounding frequency values. The truncated signal cannot accurately represent the original signal, and the spectrum analysis produces errors, and there are frequency components that should not exist, which leads to inaccurate analysis of the spectrum. The generated more side lobes may also cause interspectral interference and aliasing distortion. The original spectral line is broadened, adding unnecessary frequency components. Reduced frequency resolution (half the width of the main lobe of the rectangular window). Interspectral interference, where the side lobes of a strong signal affect the main lobe of a weak signal (drowning the signal).
Slow spectrum leakage method:
1. For periodic signals - the number of sampling and analysis points is an integral multiple of the period;
2. Reduce the width of the main lobe, which is inversely proportional to the interception length N, that is, increase the length of x(n);
3. Reduce the width of the side lobe, add a suitable window function, and truncate slowly;
4. Truncate the entire period - the interception is exactly one or an integer number of periods of the sequence. It can represent the original sequence without spectrum leakage.
Use MATLAB for spectrum analysis when sampling point N=512, as shown in the figure, spectrum leakage occurs.
insert image description here

clear all;
clc;
Ts=0.00025;     %采样间隔为0.25ms
fs=1/Ts;
N=512;         %抽样点N取512,抽样频率fs取4000
n=[0:1:N-1];k=[0:1:N-1];
xn=0.2*cos(99*(pi/200)*n)+2*cos(49*(pi/100)*n)+0.4*cos(4*(pi/5)*n);%信号离散序列
WN=exp(-j*2*pi/N);
nk=n'*k;
WNnk=WN.^nk;
Xk=xn*WNnk;  %根据定义求信号DFT
X=abs(Xk);
subplot(2,1,1);
stem(k,X,'*');
grid on;
xlabel('k');
title('幅频特性曲线(K=512,fs=4000Hz)');
ylabel('|X(k)|');
x=fs/N*k;
subplot(2,1,2);
stem(x,X,'*');
grid on;
xlabel('模拟频率');
title('模拟频率(K=512,fs=4000Hz)');
ylabel('|X(k)|');

FIR digital filter design

(4) If you want to sample x ( n T s ) x(nT_s)x(nTs) , the FIR digital filter effectively suppressesx 3 ( t ) x_3(t)x3( t ) of the spectral components, making it attenuated by more than 50dB. Try to design the digital filter (the method is not limited), give the design index and design scheme, and simulate the designed filter to analyze its performance.
Solution: From the meaning of the question, the signalx 1 ( t ) x_1(t)x1(t) x 2 ( t ) x_2(t) x2( t ) andx 3 ( t ) x_3(t)x3The frequencies of ( t ) are 0.99kHz, 0.98kHz and 1.6kHz respectively, which are the effective suppressionx 3 ( t ) x_3(t)x3( t ) of the spectral components, making it attenuated by more than 50dB. Combined with the signal frequency,fp = 1.1 k H z , fst = 1.5 k H z , A s = 50 d B {f_p} = 1.1kHz, {f_{st}} = 1.5kHz, {A_s} = 50dBfp=1.1kHz , _ _fst=1.5 kHz , _As=50dB

Consider using the window function design method.
The design steps of linear phase FIR DF by window function method are as follows:
1. Determine the performance index requirements of the required filter.
2. According to the expressions of four kinds of ideal linear phase DF (low-pass, band-pass, band-stop, high-pass), the cut-off frequency (or upper and lower cut-off frequencies) of the ideal filter is determined as the arithmetic center frequency of the transition band.
3. Get the unit impulse response of the ideal filter hd ( n ) h_d(n)hd( n ) .
4. Select the type and length of the window function N. The type of window function is determined by the minimum attenuation As(dB) of the stopband of a given filter. The length of the window, N, is determined by the transition bandwidth of the filter.
5. Find the unit impulse response of the actual filter after windowingh ( n ) = hd ( n ) ω ( n ) h(n) = {h_d}(n)\omega (n)h(n)=hd( n ) ω ( n ) .
6. TestH ( ej ω ) = DTFT [ h ( n ) ] H({e^{j\omega }}) = DTFT[h(n)]H(e )=Whether D TFT [ h ( n )] meets the performance requirements of the filter.

Specifically, the average voltage is: ω p = 2 π fp / fs = 0.55 π ω st = 2 π fst / fs = 0.75 π \begin{array}{l}{\omega _p} = 2\pi{f_p}; /{f_s} = 0.55\pi \\ {\omega _{st}} = 2\pi {f_{st}}/{f_s} = 0.75\pi \end{array}ohp=2πfp/fs=0.55 pohst=2πfst/fs=0.75 p
Frequency response of ideal low-pass filter H d ( ej ω ) {H_d}\left( { {e^{j\omega }}} \right)Hd(e )and the unit sampling responsehd ( n ) {h_d}(n)hd( n ) is:
insert image description here
insert image description here
whereτ = ( N − 1 ) / 2 \tau = (N - 1)/2t=(N1 ) /2 ,ω c = 0.5 ω p + ω st = 0.65 π {\omega _c} = 0.5{\omega _p} + {\omega _{st}} = 0.65\piohc=0.5 op+ohst=0.65 π .
The required stopband attenuation exceedsA s = 50dB {A_s} = 50dBAs=50 dB , since the minimum attenuation of the stop band of the Hamming window is 53dB, the type of the window function is selected as the Hamming window.
Transition bandwidthΔ ω = ω st − ω p = 0.75 π − 0.55 π = 0.2 π \Delta \omega = {\omega _{st}} - {\omega _p} = 0.75\pi - 0.55\pi = 0.2\piD o=ohstohp=0.75 p0.55 p=0.2 π . By looking up the table, the Hamming window transition zone isΔ ω = 6.6 π / N \Delta \omega = 6.6\pi /ND o=6.6 π / N
so thatN = 6.6 π D ω = 6.6 π 0.2 π = 33 N = \frac{ { 6.6\pi }}{ {\Delta \omega }} = \frac{ {6.6\pi }}{ { 0.2\pi }} = 33N=D o6.6 p=0.2 p6.6 p=33
Hence the group delayτ \tauτ :τ = N − 1 2 = 16 \tau = \frac{ {N - 1}}{2} = 16t=2N1=16
Therefore, the Hamming windowω ( n ) \omega (n)ω ( n ) one: ω ( n ) = [ 0.54 − 0.46 cos ⁡ ( 2 π n N − 1 ) ] RN ( n ) = [ 0.54 − 0.46 cos ⁡ π n 16 ] R 33 ( n ) \omega (n ) = \left[{0.54 - 0.46\cos(\frac{ {2\pi n}}{ {N-1}})}\right]{R_N}(n){\rm{=}}\left[ {0.54 - 0.46\cos\frac{ {\pi n}}{ {16}}}\right]{R_{33}}(n)ω ( n )=[0.540.46cos(N12πn)]RN(n)=[0.540.46cos16πn]R33(n)
则线性相位FIR低通滤波器的h(n)为
insert image description here
接下来验证 H ( e j ω ) = Σ n = 0 32 h ( n ) e − j ω n H\left( { {e^{j\omega }}} \right) = \mathop \Sigma \limits_{n = 0}^{32} h(n){e^{ - j\omega n}} H(e)=n=0Σ32h(n)ejωn。此处采用MATLAB工具画出滤波器幅度响应如图。
insert image description here

It can be seen that the stopband attenuation has not yet reached the requirement of 50dB. So consider choosing the Hamming window of N=35 for verification.
ω ( n ) = [ 0.54 − 0.46 cos ⁡ ( 2 π n N − 1 ) ] RN ( n ) = [ 0.54 − 0.46 cos ⁡ π n 17 ] R 35 ( n ) \omega (n) = \left[ { 0.54 - 0.46\cos (\frac{ {2\pi n}}{ {N - 1}})} \right]{R_N}(n){\rm{ = }}\left[ {0.54 - 0.46\cos \frac{ {\pi n}}{ {17}}} \right]{R_{35}}(n)ω ( n )=[0.540.46cos(N12πn)]RN(n)=[0.540.46cos17pn]R35( n )
insert image description here
Draw h(n) and filter amplitude response and phase response as shown in the figure.
insert image description here
insert image description here

According to the judgment of the minimum attenuation of the stop band in the program, the minimum value of As is 53.22dB, which meets the requirement that the attenuation exceeds 50dB. Can effectively suppress x 3 ( t ) {x_3}(t)x3( t ) Spectrum components.
insert image description here
insert image description here

clc;
clear all;
fp=1100;fst=1500;%设置通带和阻带频率
Ts=0.00025;     %采样间隔为0.25ms
Fs=1/Ts;        %采样频率
wp=2*pi*fp/Fs;ws=2*pi*fst/Fs;%数字角频率
deltaw=ws-wp;   %求过度带宽
N0=ceil(6.6*pi/deltaw);%计算海明窗长
N=N0+mod(N0+1,2);%取N为奇数
n=[0:N-1];
wd=(hamming(N))';%求海明函数
wc=(ws+wp)/2;%理想低通滤波器截至频率
hd=ideallp(wc,N);%理想低通的单位冲击响应,调用ideallp将其放于相同路径下
h=hd.*wd;
[db,mag,pha,grd,w] = freqz_m( h,[1]);%检查设计结果的各项指标(“dB”是负值),调用freqz_m将其放于相同路径下
dw=2*pi/1000;
Rp=-min(db(1:wp/dw +1));%检查通带最大衰减是否满足要求
As=-max(db(ws/dw+1:501));%检查阻带最小衰减是否满足要求
figure(1);  %绘制海明窗
plot(n,wd,'linewidth',2);grid;
title('海明窗'); xlabel( 'n'); ylabel( 'w(n) ');
axis([0,N,0,1]);
figure(2);%绘制幅度响应曲线
plot(w/pi,db,'linewidth',2)
title('幅度响应(db) ' );xlabel('\omega/\pi');ylabel('20log|H(e^j^\omega)|(dB)');
axis([0,1,-80,5]);grid;
set(gca,'xtickmode','manual','xtick',[ 0,0.55,0.75,1.0]);%横坐标设置,观察感兴趣的位置,此处选取通带和阻带位置
figure(3);%绘制相位响应曲线
plot(w/pi,pha,'linewidth',2);axis([0,1,-4,4]);grid
title('相位响应');xlabel ( '\omega/\pi'); ylabel ( 'arg20log[H(e^j^\omega)]');

The ideallp and freqz_m functions called are as follows (put them in the same working directory to call):

function hd = ideallp(wc,N);
% 理想低通滤波器的脉冲响应子程序
% hd = ideallp(wc,N)
% hd =0 到 N-1之间的理想脉冲响应
% wc = 截止频率(弧度)
% N = 理想滤波器的长度
%
tao = (N-1)/2;              % 理想脉冲响应的对称中心位置
n = [0:(N-1)];             % 设定脉冲响应长度
m = n-tao+eps;          % 加一个小数以避免零作除数
hd =sin(wc*m) ./ (pi*m);   % 理想脉冲响应
function [db,mag,pha,grd,w]=freqz_m(b,a)
%求取系统的绝对幅度响应、相对的db值幅度响应、相位响应和群延时响应的函数
%db为相对振幅(dB)
%mag为绝对振幅
%pha为相位响应
%grd为群延时
%w为频率样本点向量
%b为Ha(z)分子多项式系数(对FIR而言,b=h)
%a为Hz(z)分母多项式系数(对FIR而言,a=1)
% [H,w]=freqz(b,a,1000,'whole');
%freqz显示数字滤波器频域中的图形
%[H,W] = FREQZ(B,A,N,'whole') uses N points around the whole unit circle.
[H,w] = freqz(b,a,1000,'whole');
    H = (H(1:1:501))'; w = (w(1:1:501))';
  mag = abs(H);
   db = 20*log10((mag+eps)/max(mag));
  pha = angle(H);
%  pha = unwrap(angle(H));
  grd = grpdelay(b,a,w);

reference article

Digital Signal Processing Tutorial Fourth Edition_Cheng Peiqing P210 (Example 3.20) P545 P560 (Example 8.1 Example 8.7)
Link: Digital Signal Processing and MATLAB Implementation
Link: Matlab Quick Start (5) Fourier Transform

Guess you like

Origin blog.csdn.net/weixin_48412658/article/details/128586297