MATLAB Answers

FIltered signal not matching with the original signal.

조회 수: 5(최근 30일)
indigo fgo
indigo fgo 2021년 7월 13일
댓글: Mathieu NOE 2021년 7월 15일
Hello, im new to filter design, as you can probably tell. I have a signal from a wave guage measuring depth with time, The signal has very high low end frequencies so i am trying to apply a short low pass filter to smooth the signal, im not sure if it is my kernal or order choice but when i plot the original signal with the filtered signal, the filtered signal has lost magnitude. Its was originally intended to be a band stop filter so might not be consistant the whole way through. At this stage im completely stuck and any healp would greatly apreciated.
Thank you so much for your time,
srate = 128;%Hz Sample Rate
nyquist = srate/2;
coff = [7];%Cut off or range
transw = .1;% randomly set
shape = [1 1 0 0];
frex = [1 coff(1)-coff(1)*transw coff(1) nyquist]/nyquist;
hz = linspace(0,srate,8321);%8321 is the number of samples in the data
% Loop for best matching order
order1 = (.2*srate/coff(1))/(srate/1000);%randomly set as I was trying different orders
order2 = (.3*srate/coff(1))/(srate/1000);
orders = round(linspace(order1,order2,2));%step count
fkernx = zeros(length(orders),8321);
for k = 1:length(orders);
fkern = firls(orders(k),frex,shape);
n(k) = length(fkern);
fkernx(k,:) = abs(fft(fkern,8321)).^2;
hold on
hold on
xlim([0 64])
% % Loop for best matching transwidth
transwidth = linspace(.1,.4,4);
fkerxx = zeros(length(transwidth),8321);
orderl = round(order1);
for t = 1:length(transwidth);
frex2 = [1 coff(1)-coff(1)*transwidth(t) coff coff(2)+coff(2)*transwidth(t) nyquist]/nyquist;
fkern2 = firls(2,frex2,shape);
n(t) = length(fkern2);
fkernxx(t,:) = abs(fft(fkern2,8321).^2);
hold on
hold on
%Final Filter Design
orderx = round((.3*srate/coff(1))-(srate/1000));%Use best matchig order here
transwidthx = 0.1;
frex3 = [1 coff(1)-coff(1)*transw coff nyquist]/nyquist;
filt28 = firls(orderx,frex3,shape);
%Apply filter design to signal (PDg1)
PDg1s = filtfilt(filt28,1,PDg1);
detfftp1 = detrend(PDg1s);
fftp1 = abs(fft(detfftp1));
%Frequency domain after filter
semilogy(hz, fftp1)
hold on
plot(PT5, PDg1,'r');
plot(PT5, PDg1s,'b')%plot smoothed data
xlabel('TIme (s)')
ylabel('Depth (m)')
title('Depth Against Time')

채택된 답변

Mathieu NOE
Mathieu NOE 2021년 7월 13일
I see that you are doing a detrend action on your data. This will remove the dc (mean) value of the signal , so no surprise that the output is shifted.
My suggestion :
T = csvread('ExampleData PDg1 and time.txt');
y = T(:,1);
Fs = 128;
dt = 1/Fs;
samples = length(y);
t = (0:samples-1)*dt;
%%% filter data %%%
N = 250;
y_LP = smoothdata(y, 'gaussian' , N); % low pass filtered data
%%% plot data %%%
plot(t,y,t,y_LP);legend('Raw','low pass filtered');
title(['Data samples at Fs = ' num2str(Fs) ' Hz / filtered with smoothdata' ]);
xlabel('Time (hours) ')
ylabel('Depth (m) ')
  댓글 수: 5
Mathieu NOE
Mathieu NOE 2021년 7월 15일
if my answer has helped you, do you consider accepting it ?

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by