当前位置:网站首页>Matlab 信号处理【问答笔记-1】
Matlab 信号处理【问答笔记-1】
2022-07-02 22:44:00 【鹅毛在路上了】
1. 关于matlab frezq fir1函数
问:输入信号x为频率0.1 Hz和0.3 Hz的等幅正弦波之和,利用fir1函数设计滤波器h,去除0.3 Hz的正弦信号,得到输出信号y。用freqz函数观察滤波器h的频率响应。显示输入信号x和输出信号y的波形。用fft函数对信号做快速傅里叶变换,并显示输入输出信号的幅频曲线。
答:具体步骤如下,精度自行调整;由于0.1Hz与0.3Hz频率差距太小,容易产生频谱泄漏:
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;
%时域信号
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
%滤波器设计
wn = 0.2; %截止频率wn为0.2pi(0.2Hz),wn = 2pi*f/fs
N = 60; %阶数选择
hn = fir1(N-1,wn,boxcar(N)); %10阶FIR低通滤波器
figure(2)
freqz(hn,1);
figure(3)
y = fftfilt(hn,x3); %经过FIR滤波器后得到的信号
plot(t,y,"LineWidth",1.5)
grid on
%频谱分析
Y = fft(y); %输出信号的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. 用MATLAB完成傅里叶变换并绘制出变换后的波形
问:
用MATLAB求出傅里叶变换并绘制图像
用什么函数工具,怎么得出图像呀?
答:连续非周期的符号函数sign(t)求傅里叶变换的结果如下:
图像:
在Matlab里绘制的图像实际上都是转成离散时间信号处理后的结果(计算机里没有真正的模拟量),对连续时间信号(模拟信号)采样逼近得到的,这里得出的频谱(DFT得到的频域离散谱是对连续谱的N点等间隔采样)取连续包络就是sign(t)经连续时间傅里叶变换FT后的图像,就不再补充从FS、FT到DFS、DTFT、DFT(FFT)的过程和关系了,具体推导自行看书研究,写在这里会写到吐血的。
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
%时域
y = sign(t);
figure(1)
plot(t,y)
ylim([-2 2])
grid on
title('Time-domain')
%fft近似表示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)|')
%基于 P2 和信号长度 L 计算单侧频谱 P1
subplot(212)
plot(P1)
title('Frequency-domain')
xlabel('w')
ylabel('|P1(f)|')

3. 该怎么设计butter worth带阻滤波器的各系数
问:
噪音是7000hz,非噪音是0-5000hz,只看左半边,我该怎么设计呢?参见如下设计:
答:
你想要通过带阻滤波器进行滤波,那噪声信号的频率必须在阻带范围内;有用信号为0~5000Hz,因此通带截止频率fp1可以设置为5500Hz,阻带起始频率fs1必小于7000Hz,可以设为6000Hz,阻带截止频率fs2必须大于7000Hz,可以设为8000Hz,通带起始频率fp2可设置为8500Hz,为了保证奈奎斯特条件,采样频率Fs可以设为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π约等于7000Hz,可见噪声频率落在阻带范围内。
边栏推荐
- JDBC practice cases
- Talk about memory model and memory order
- [live broadcast appointment] database obcp certification comprehensive upgrade open class
- Leetcode DP three step problem
- (stinger) use pystinger Socks4 to go online and not go out of the network host
- 【STL源码剖析】仿函数(待补充)
- Returns the maximum distance between two nodes of a binary tree
- Which common ports should the server open
- Speech recognition Series 1: speech recognition overview
- 程序分析与优化 - 9 附录 XLA的缓冲区指派
猜你喜欢
JDBC practice cases
RuntimeError: no valid convolution algorithms available in CuDNN
[error record] the flutter reports an error (could not resolve io.flutter:flutter_embedding_debug:1.0.0.)
Go basic constant definition and use
Getting started with golang: for Range an alternative method of modifying the values of elements in slices
Maybe you read a fake Tianlong eight
LINQ usage collection in C #
Interface switching based on pyqt5 toolbar button -1
流媒体技术优化
购买完域名之后能干什么事儿?
随机推荐
How does win11 turn on visual control? Win11 method of turning on visual control
程序分析与优化 - 9 附录 XLA的缓冲区指派
Ideal car × Oceanbase: when the new forces of car building meet the new forces of database
Agnosticism and practice makes perfect
What is the official website address of e-mail? Explanation of the login entry of the official website address of enterprise e-mail
一文掌握基于深度学习的人脸表情识别开发(基于PaddlePaddle)
2022年最新最全软件测试面试题大全
Win11启用粘滞键关闭不了怎么办?粘滞键取消了但不管用怎么解决
Use of cocospods
Detailed explanation of 'viewpager' in compose | developer said · dtalk
RuntimeError: no valid convolution algorithms available in CuDNN
RuntimeError: no valid convolution algorithms available in CuDNN
Solution to boost library link error
php 获取真实ip
LINQ usage collection in C #
Mapper代理开发
Bean load control
富滇银行完成数字化升级|OceanBase数据库助力布局分布式架构中台
How difficult is it to be high? AI rolls into the mathematics circle, and the accuracy rate of advanced mathematics examination is 81%!
Why does RTOS system use MPU?