필터 지우기
필터 지우기

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
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 CenterFile Exchange에서 Smoothing and Denoising에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by