Get Exact Frequency From Digital Signal

262 views Asked by At

I studies on Digital Signal Filtering and I have a file includes some signal data. I wrote Matlab Program to get 23 to 27 Hz from original signal. but filtered signal is different. my desire filter is bandpass but my code work like low pass filter. this is my code :

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

is there any idea? best regards.

my datafile uploaded here : http://wikisend.com/download/574638/SignalFile.mat

result Images : https://www.imageupload.co.uk/image/ZLzM if you look at image, you can find under 20hz signal exists in filtered signal yet.

0

There are 0 answers