How to filter noisy signal using built-in buttord function in Matlab?
1 次查看(过去 30 天)
显示 更早的评论
Hi. I want to filter a noisy signal using built-in function, such as buttord, cheby1 and so on.
%generate the noisy signal which will be filtered
x= cos(2*pi*12*[0:0.001:1.23]);
x(end) = [];
[b a] = butter(2,[0.6 0.7],'bandpass');
filtered_noise = filter(b,a,randn(1, length(x)*2));
x = (x + 0.5*filtered_noise(500:500+length(x)-1))/length(x)*2;
figure(1), plot(x);
title('Noisy signal');
xlabel('Samples');
ylabel('Amplitude');
%plot first half of DFT (normalised frequency)
X_mags = abs(fft(x));
num_bins = length(X_mags);
figure(2),
hold on
plot([0:1/(num_bins/2 -1):1], X_mags(1:num_bins/2))
xlabel('Normalised frequency (\pi rads/sample)')
ylabel('Magnitude')
%Use matlabs built-in buttord function to get the optimum order to meet a specification
[N Wn] = buttord(0.1, 0.5, 5, 40)
%use the N and Wn values obtained above to design the filter in the usual way
[b a] = butter(N, Wn, 'low');
%plot the magnitude spectrum
H = freqz(b,a, floor(num_bins/2));
figure(2);
hold on
plot([0:1/(num_bins/2 -1):1], abs(H),'r');
%filter the signal and plot the output of the filter
x_filtered = filter(b,a,x);
figure(3);
plot(x_filtered);
title(['Filtered Signal - Using ' num2str(N) ' th Order Butterworth']);
xlabel('Samples');
ylabel('Amplitude');
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/151723/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/151724/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/151726/image.png)
The problem is I don't really know how to identify the values for this code.
[N Wn] = buttord(0.1, 0.5, 5, 40)
How exactly can I know what values should I used? Can somebody help me please?
0 个评论
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Digital Filter Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!