如何在 MATLAB 中计算滤波器的传递函数?
我必须在数字信号处理课程中做一些练习,但遇到一些问题。
我有一个给定的文件(signal.wav 名为信号 x(n)
),其中添加了一些噪声,我要求从中查找一些信息。添加的噪声为η(n) = sin8000πn
。所以我正在处理的信号是 s(n) = x(n) + η(n)
为了消除噪声,我应用了阶数 = 2 的低通巴特沃斯滤波器 截止频率 = 2000hz。
我想从过滤器和 H(z)
函数中找到传递函数 H(s)
。我知道我必须应用双线性变换,但我不知道如何使用 MATLAB 来实现。
谁能帮我解决这个问题吗?
这是我的代码
[y, fs, nbits] = wavread('signal.wav');
% Playing the file
disp('-> Playing at the original sample rate...');
sound(y, fs);
fprintf('------------------------------------------\n');
% Sampling frequency
fprintf('-> Sample frequency is: %f.\n', fs);
% Print the min and max values of the audio data.
fprintf('-> The maximum data value is %f.\n', max(y));
fprintf('-> The minimum data value is %f.\n', min(y));
fprintf('------------------------------------------\n');
order = 2;
sampling_freq = fs;
cut_off_freq = 2000;
[butter_a, butter_b] = butter(order,cut_off_freq/(sampling_freq/2));
%[butter_a, butter_b] = butter(order,cut_off_freq/(sampling_freq));
subplot(211), plot(y);
subplot(212), plot(filter(butter_a,butter_b,y));
sound(filter(butter_a,butter_b,y),fs);
I have to do some exercises in a Digital Signal Processing course and I have some problems.
I have a given file (signal.wav name the signal x(n)
) with some noise added and iIam asked to find some information from it. The noise added is η(n) = sin8000πn
. So the signal I am processing is s(n) = x(n) + η(n)
In order to remove the noise, I apply a low-pass butterworth filter with order = 2
and cutoff frequency = 2000hz.
I want to find the transfer function H(s)
from the filter and the H(z)
function. Well I know that I have to apply bilinear transformation but iIdont know how to do it with MATLAB.
Can anyone help me solve this?
Here is my code
[y, fs, nbits] = wavread('signal.wav');
% Playing the file
disp('-> Playing at the original sample rate...');
sound(y, fs);
fprintf('------------------------------------------\n');
% Sampling frequency
fprintf('-> Sample frequency is: %f.\n', fs);
% Print the min and max values of the audio data.
fprintf('-> The maximum data value is %f.\n', max(y));
fprintf('-> The minimum data value is %f.\n', min(y));
fprintf('------------------------------------------\n');
order = 2;
sampling_freq = fs;
cut_off_freq = 2000;
[butter_a, butter_b] = butter(order,cut_off_freq/(sampling_freq/2));
%[butter_a, butter_b] = butter(order,cut_off_freq/(sampling_freq));
subplot(211), plot(y);
subplot(212), plot(filter(butter_a,butter_b,y));
sound(filter(butter_a,butter_b,y),fs);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该使用
freqs
来计算模拟滤波器的频率响应/传递函数(即H(s)
)。因此,在本例中,类似:将绘制滤波器在 200 个频率点处的频率和相位响应。您还可以提供应计算的点向量(请参阅链接的文档)。
对于数字滤波器的传递函数(即
H(z)
),请使用freqz
.因此,您的语法将类似于:它将再次像以前一样绘制频率和相位响应。再次强调,请确保您阅读链接的文档以正确理解和使用它。
You should use
freqs
to calculate the frequency response/transfer function of your analog filter (i.e.,H(s)
). So in this case, something like:will plot the frequency and phase response for the filter at 200 frequency points. You can also provide a vector of points where it should be calculated (see the linked doc).
For the transfer function of the digital filter (i.e.,
H(z)
), usefreqz
. So your syntax would be something like:which will again plot the frequency and phase responses as before. Again, make sure you read the linked documentation to understand and use it correctly.
由于您知道信号中不需要的分量的频率,因此您只需估计相位和幅度,然后在时域中从信号中减去添加的噪声分量即可得到解决方案。
有多种方法可以估计正弦的相位和幅度。我建议你尝试 Goertzel 算法。
Since you know the frequency of the unwanted component of the signal you need only to estimate the phase and amplitude and then subtract the added noise component from your signal in the time domain to get the solution.
There are many ways of estimating the phase and amplitude of a sine. I suggest you try the Goertzel algorithm for that.