0

我研究数字信号滤波,我有一个包含一些信号数据的文件。我编写了 Matlab 程序以从原始信号中获得 23 到 27 Hz。但滤波后的信号不同。我想要的滤波器是带通的,但我的代码像低通滤波器一样工作。这是我的代码:

clc;
clear all;
load('SignalFile.mat');
%number of sample
SampleNumber = 60000;  

%create hamming window 
hamm = hamming((SampleNumber))';   %'

% there is 4 data in SignalFile.mat
for pl=1:4

% get name of data in signalFile.mat    
data  = eval(['mydata' num2str(pl)]);
[n,c] = size(data);
nk=SampleNumber;

% there is 2 signal in each data. but main signal exists on data(1:nk,1);
% nk is Sample Number.
mydata = data(1:nk,1) ;
encodedata = data(1:nk,2);


% Sample Rate my this file equal to data length / 4 ->>   ~ 39000 sample
% per second.
fs = floor(n/4);  % Sampling rate [Hz]
noSamples = nk;   % Number of samples

f = 0 : fs/noSamples : fs - fs/noSamples; % Frequency vector

figure;
subplot(2,2,1);
plot(mydata);
x_fft = abs(fft(mydata));
subplot(2,2,2);
plot(f,x_fft);
xlim([1 100]);

centerf = 25;      % 25 Hz Center 
bw=2;              %Bandwisth
fc=pi*centerf;     %Center Frequency
L = nk;            %sample number;
%Compute Filter
hsuup=(-(L-1)/2:(L-1)/2);
hideal1=hamm.*(2*(fc+bw)*(sin(2*(fc+bw)*hsuup/fs)./(2*(2*fc+bw)*hsuup/fs)));
hideal2=hamm.*(2*(fc-bw)*(sin(2*(fc-bw)*hsuup/fs)./(2*(2*fc+bw)*hsuup/fs)));
h_bpf=(hideal1-hideal2);

% transform mydata to Ferequency Domain
comp_sig_fft=fft(mydata)';    %'
% transform Filter Windows to Ferequency Domain
h_bpf_fft=fft(h_bpf);
% Filter Signal
s_fft=comp_sig_fft.*h_bpf_fft;
%
band_passed_signal=real(ifft(s_fft));

subplot(2,2,3);
plot(band_passed_signal);


x_fft = abs(fft(band_passed_signal));
subplot(2,2,4);
plot(f,x_fft);
xlim([1 100]);


end

有什么想法吗?此致。

我在这里上传的数据文件: http ://wikisend.com/download/574638/SignalFile.mat

结果图像: https ://www.imageupload.co.uk/image/ZLzM 如果您查看图像,您会发现过滤后的信号中还存在 20hz 以下的信号。

4

0 回答 0