フィルターのクリア

Hi! can someone help me with this code? I want filter a noise in a wav file using moving average filters

1 回表示 (過去 30 日間)
This what I have done so far
clear all;
clc;
%%=== Reading the file ===
[signal, Fs] = audioread('testSignal.wav');
subplot(211)
plot(signal(1:350));
title('Original Signal')
xlabel('Samples')
ylabel('Amplitude')
grid on;
sound(signal)
% ========================
%%=== Filter ===
order =10000;
h = ones(1,order)/order;
count = 0;
for n = 1:length(signal)-(order-1)
for j = n:n+(order-1)
count = count+1;
x(count) = signal(j);
end
count = 0;
FiltSig(n) = sum(h.*x);
end
% ==============
%%=== Writing the file ===
audiowrite('FiltSignal.wav',FiltSig,Fs)
subplot(212)
plot(FiltSig(1:350));
title('Filtered Signal')
xlabel('Samples')
ylabel('Amplitude')
grid on;
sound(FiltSig)
% ========================

回答 (1 件)

Image Analyst
Image Analyst 2016 年 4 月 7 日
Instead of doing the moving average yourself, simply use conv() or lowess().
windowWidth = 100; % Whatever.
kernel = ones(1, windowWidth)/windowWidth;
smoothedSignal = conv(signal, kernel, 'same');
  2 件のコメント
Anisio Gomes
Anisio Gomes 2016 年 4 月 8 日
Hi Image! How would it be with Lowess() and what is the difference
Image Analyst
Image Analyst 2016 年 4 月 8 日
I don't have that toolbox so you'll just have to read the help. conv() is simply the sum of the products, though you can weight them if you want. You can also use sgolayfilt() which is a Savitzky-Golay filter in the Signal Processing Toolbox. That is a sliding filter too but it fits the data in a sliding window to a polynomial, like a line, quadratic, cubic, or whatever. You might try that if you want. I think there are others like butter() and filtfilt() and filter() but I don't use any of those. I only use conv() and sgolayfilt().

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSmoothing and Denoising についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by