Hi! can someone help me with this code? I want filter a noise in a wav file using moving average filters
    2 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
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)
    % ========================
0 comentarios
Respuestas (1)
  Image Analyst
      
      
 el 7 de Abr. de 2016
        windowWidth = 100; % Whatever.
kernel = ones(1, windowWidth)/windowWidth;
smoothedSignal = conv(signal, kernel, 'same');
2 comentarios
  Image Analyst
      
      
 el 8 de Abr. de 2016
				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().
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

