从数字信号中获得准确的频率

时间:2015-06-10 10:33:46

标签: matlab signals filtering frequency-domain

我研究数字信号滤波,我有一个包含一些信号数据的文件。我编写了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以下的信号存在于滤波信号中。

0 个答案:

没有答案