0

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.

Mikhail_Sam
  • 10,602
  • 11
  • 66
  • 102
  • 1
    Please add comments and explanations to your code – Dan Jun 10 '15 at 10:54
  • First of all, this is a math question more than a Matlab question. You need to understand how digital filters (and fft) work. Next, please post the results you got and explain why you think the results should be something different. – Carl Witthoft Jun 10 '15 at 11:30
  • thanks you for replay. i have a signal and i want to filter this signal to get frequency between 23 to 27 Hz. there is 2 solution : use IIR Filtering Algorithm like butter-worth and FIR Filtering. in FIR filtering one of methods to filter a signal is : multiply a window vector ( like hamming ) with my desire center frequency and bandwidth in my signal at frequency domain. therefor i use a hamming window and transform it to frequency domain and transform my signal too. then multiply those. and at last use ifft to get my filter signal. – Alireza Izadimehr Jun 10 '15 at 11:59
  • this is my window image : https://www.imageupload.co.uk/image/ZL8D when you get fft from this window left of my center frequency is not zero or small. this image show result of fft (my-window) : https://www.imageupload.co.uk/image/ZL8T and my filter work like lowpass filter : https://www.imageupload.co.uk/image/ZLzM another question is my sample rate is too high ( ~40000 sample per second ) and my frequency is low 23 to 27 hz. what is your idea to get best result? – Alireza Izadimehr Jun 10 '15 at 12:14

0 Answers0