How to filter out the noise to see the general trend

5 views (last 30 days)
Hello !
I want to filter out the noise to see the general trend but when I plot my filter signal, the signal is zero.
This is my first time asking a question on mathworks.
Attached is the sound file.
If anyone has an idea that would be cool :)
% Lecture du fichier audio
% s_t:signal temporel et fs:fréquence d'échantillonnage
[s_t, fs]=audioread("C:\Users\varan\OneDrive\Bureau\Bruit quadrirotor.wav");
ts=1/fs; % On peut donc déterminer la période d'échantillonnage du signal : ts
fs % s
ts % t
% Affichage du signal audio
T_sec=10; % On garde 10 secondes de notre fichier
N=round(T_sec/ts); % On converti la période de 10 secondes en nombre d'échantillon
X=s_t(1:N,1); % On récupère le son
t=linspace(0,T_sec,N);
figure(1);
subplot(211); plot(t,X,'linewidth',2); grid on;
ylabel('Amplitude(V)'); xlabel('Temps(s)');
% Lecture du fichier audio
% sound(X,fs);
% Traitement du signal
fn = fs/2; % Nyquist Frequency
L = numel(t); % Signal Length
sm = X-mean(X); % Subtract Mean To Make Amplitudes At Frequencies>0 More Prominent
FTs = fft(sm)/L; % Fourier Transform
Fv = linspace(0, 1, fix(L/2)+1)*fn; % Frequency Vector
Iv = 1:length(Fv); % Index Vector
Phs = angle(FTs);
figure(2)
plot(Fv, abs(FTs(Iv))*2)
grid
xlabel('Frequency (Days^{-1})')
ylabel('Amplitude')
set(gca, 'XLim',[0 0.05])
Wp = [0.0045]/fn; % Passband Frequencies (Normalised)
Ws = [0.0055]/fn; % Stopband Frequencies (Normalised)
Rp = 10; % Passband Ripple (dB)
Rs = 50; % Stopband Ripple (dB)
[n,Ws] = cheb2ord(Wp,Ws,Rp,Rs); % Filter Order
[z,p,k] = cheby2(n,Rs,Ws); % Filter Design
[sosbp,gbp] = zp2sos(z,p,k); % Convert To Second-Order-Section For Stability
figure(3)
freqz(sosbp, 2^16, fs) % Filter Bode Plot
s_filt = filtfilt(sosbp,gbp, X); % Filter Signal
figure(4)
plot(t, X, '-b')
hold on
plot(t, s_filt, '-r', 'LineWidth',1.5)
hold off
xlabel('Time (Days)')
ylabel('Amplitude')
legend('Original', 'Lowpass Filtered')
  1 Comment
Image Analyst
Image Analyst on 17 Jan 2022
Since it's your first time, here are some tips:
Read this link
so you'll know how to get an answer. In particular, this means attaching your data with the paperclip icon so people can try things with your actual data.
Secondly, it some people give you answers, then you can award them 2 "reputation points" by Accepting their answer, and 2 for clicking the "Vote" icon. However one one answer can be accepted as the official, best answer so know which one you think is best.
If the filter just makes your signal zero then you might try adjusting the filter parameters. Maybe a simpler route is to use the Savitzky-Golay filter, sgolayfilt(), which is essentially a polynomial fit in a sliding window.

Sign in to comment.

Accepted Answer

Cris LaPierre
Cris LaPierre on 17 Jan 2022
I might suggest using the Smooth noise data Live Task. This will allow you to interactively filter your data. Once you have a result you like, you can convert the task to code, or keep the interactive task in your code. Your code will run the same either way.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!