当前位置:网站首页>MATLAB signal processing [Q & a notes-1]
MATLAB signal processing [Q & a notes-1]
2022-07-02 23:50:00 【Goose feather is on the way】
1. About matlab frezq fir1 function
ask : Input signal x Is frequency 0.1 Hz and 0.3 Hz Sum of equal amplitude sine waves , utilize fir1 Function design filter h, Remove 0.3 Hz The sine signal of , Get the output signal y. use freqz Function observation filter h Frequency response of . Display the input signal x And output signal y Waveform of . use fft Function to do fast Fourier transform on the signal , And display the amplitude frequency curve of input and output signals .
answer : The specific steps are as follows , The accuracy can be adjusted by itself ; because 0.1Hz And 0.3Hz The frequency difference is too small , Prone to spectrum leakage :
clc,clear,close all;
t = -100:1:100;
L = length(t);
fs = 2;
x1 = sin(2*pi*0.1.*t/fs);
x2 = sin(2*pi*0.3.*t/fs);
x3 = x1 + x2;
% Time domain signal
figure(1)
subplot(311)
plot(t,x1,"LineWidth",1.5)
grid on
subplot(312)
plot(t,x2,"LineWidth",1.5)
grid on
subplot(313)
plot(t,x3,"LineWidth",1.5)
grid on
% Filter design
wn = 0.2; % Cut off frequency wn by 0.2pi(0.2Hz),wn = 2pi*f/fs
N = 60; % Order selection
hn = fir1(N-1,wn,boxcar(N)); %10 rank FIR low pass filter
figure(2)
freqz(hn,1);
figure(3)
y = fftfilt(hn,x3); % after FIR The signal obtained after the filter
plot(t,y,"LineWidth",1.5)
grid on
% Spectrum analysis
Y = fft(y); % Of the output signal fft
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = fs*(0:(L/2))/L;
plot(f,P1,"LineWidth",1.5)
title('Single-Sided Amplitude Spectrum of X(t)')
xlabel('f (Hz)')
ylabel('|P1(f)|')
2. use MATLAB Complete the Fourier transform and draw the transformed waveform
ask :
use MATLAB Calculate the Fourier transform and draw the image
What function tools are used , How to get the image ?
answer : Continuous aperiodic symbolic function sign(t) The result of Fourier transform is as follows :
Images :
stay Matlab The images drawn in are actually the result of discrete-time signal processing ( There is no real analog quantity in the computer ), For continuous time signals ( analog signal ) Obtained by sampling approximation , The spectrum obtained here (DFT The obtained discrete spectrum in frequency domain is for continuous spectrum N Point equally spaced sampling ) Taking the continuous envelope is sign(t) After continuous time Fourier transform FT The image after , No longer add from FS、FT To DFS、DTFT、DFT(FFT) The process and relationship , Specific derivation, self reading and research , If you write here, you will spit blood .
clc,clear,close all;
Fs = 1000; % Sampling frequency
T = 1/Fs; % Sampling period
L = 1500; % Length of signal
t = (-1/2*L:1/2*L-1)*T; % Time vector
% Time domain
y = sign(t);
figure(1)
plot(t,y)
ylim([-2 2])
grid on
title('Time-domain')
%fft Approximate representation ft
Y = fft(y);
P2 = abs(Y/L);
P0 = fftshift(P2);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
figure(2)
subplot(211)
plot(P0)
title('Frequency-domain')
xlabel('w')
ylabel('|P2(f)|')
% be based on P2 And signal length L Calculate the unilateral spectrum P1
subplot(212)
plot(P1)
title('Frequency-domain')
xlabel('w')
ylabel('|P1(f)|')

3. How to design butter worth Coefficients of band stop filter
ask :
The noise is 7000hz, Non noise yes 0-5000hz, Just look at the left half , How should I design it ? See the following design :
answer :
You want to filter through the band stop filter , The frequency of the noise signal must be within the stopband ; Useful signals are 0~5000Hz, Therefore, the passband cut-off frequency fp1 It can be set to 5500Hz, Stopband starting frequency fs1 Must be less than 7000Hz, Can be set as 6000Hz, Stopband cut-off frequency fs2 Must be greater than 7000Hz, Can be set as 8000Hz, Passband starting frequency fp2 Can be set to 8500Hz, In order to guarantee the Nyquist condition , sampling frequency Fs Can be set as 44100Hz.
clc,clear,close all;
Fs = 44100;
fp1 = 5500;fp2 = 8500;
fs1 = 6000;fs2 = 8000;
wp1 = fp1/Fs*2*pi;
wp2 = fp2/Fs*2*pi;
wp = [wp1,wp2];
ws1 = fs1/Fs*2*pi;
ws2 = fs2/Fs*2*pi;
ws = [ws1,ws2];
Rp = 1;As = 30;
[n,wc] = buttord(wp/pi,ws/pi,Rp,As);
[b,a] = butter(n,wc,'stop');
freqz(b,a);
0.32π*44100/2π About equal to 7000Hz, It can be seen that the noise frequency falls within the stopband range .
边栏推荐
- How much do you know about synchronized?
- JDBC practice cases
- 富滇银行完成数字化升级|OceanBase数据库助力布局分布式架构中台
- How much do you know about synchronized?
- [proteus simulation] 51 MCU +lcd12864 push box game
- YOLOX加强特征提取网络Panet分析
- Print out mode of go
- (stinger) use pystinger Socks4 to go online and not go out of the network host
- 理想汽车×OceanBase:当造车新势力遇上数据库新势力
- 开源了 | 文心大模型ERNIE-Tiny轻量化技术,又准又快,效果全开
猜你喜欢
随机推荐
公司里只有一个测试是什么体验?听听他们怎么说吧
简述中台的常识
CADD course learning (4) -- obtaining proteins without crystal structure (Swiss model)
RuntimeError: no valid convolution algorithms available in CuDNN
Solution: exceptiole 'xxxxx QRTZ_ Locks' doesn't exist and MySQL's my CNF file append lower_ case_ table_ Error message after names startup
ArrayList analysis 2: pits in ITR, listiterator, and sublist
基于Pyqt5工具栏按钮可实现界面切换-1
yolov5train. py
Golang common settings - modify background
[OJ] intersection of two arrays (set, hash mapping...)
判断二叉树是否为满二叉树
基于OpenCV实现口罩识别
Brief introduction to common sense of Zhongtai
MFC 获取当前时间
php 获取真实ip
JDBC教程
C MVC creates a view to get rid of the influence of layout
返回二叉树中最大的二叉搜索子树的根节点
The privatization deployment of SaaS services is the most efficient | cloud efficiency engineer points north
Agnosticism and practice makes perfect