What is wrong with my filter?
Show older comments
Why is it filtering the wrong frequencies in the middle bands?
%Sample frequency
fs = 64000; %Hz
%Sample time
T=1/fs;
%Number of samples
Length = 300;
%Time samples
t=(0:Length-1)*T;
%Signal formation
Signal=2*sin(2*pi*1000*t)+0.5*sin(2*pi*3000*t)+2*sin(2*pi*5000*t)+0.5*sin(2*pi*7000*t)+2*sin(2*pi*9000*t)+0.5*sin(2*pi*11000*t)+2*sin(2*pi*13000*t);
%Plot signal
figure(1);
plot(t, Signal);
xlabel('Time (Length / Fs) , s');
ylabel('Amplitude');
title('Sum of 1 kHz and 15 kHz')
%Spectrum
Y=fft(Signal);
%Separate sides
P2 = abs(Y/Length);
P1 = P2(1:Length/4+1);
P1(2:end-1) = 2*P1(2:end-1);
%Plot spectrum
f = fs*(0:(Length/4))/Length;
figure(2);
plot(f,P1)
title('Single-Sided Amplitude Spectrum')
xlabel('f, Hz')
ylabel('P')
% All frequency values are in kHz.
Fs = 28; % Sampling Frequency
N = 48; % Order
F = [0 2 2.1 3.9 4 6 6.1 7.9 8 10 10.1 11.9 12 14]; % Frequency Vector
A = [4 4 0 0 4 4 0 0 4 4 0 0 4 4]; % Amplitude Vector
W = [1 100 1 100 1 100 1]; % Weight Vector
% Calculate the coefficients using the FIRPM function.
b = firpm(N, F/(Fs/2), A, W);
Hd = dfilt.dffir(b);
%Filter the signal
Signal_filtered = filter(b,1,Signal);
%Plot filtered signal
figure(3);
plot(t, Signal_filtered);
xlabel('Time (Length / Fs) , s');
ylabel('Amplitude');
title('Filtered signal (Cutoff Frequency 5 kHz)')
%Spectrum of filtered signal
Y=fft(Signal_filtered);
%Separate sides
P2 = abs(Y/Length);
P1 = P2(1:Length/4+1);
P1(2:end-1) = 2*P1(2:end-1);
%Plot spectrum of filtered signal
f = fs*(0:(Length/4))/Length;
figure(4);
plot(f,P1)
title('Single-Sided Amplitude Spectrum of the filtered signal (Cutoff Frequency 5 kHz)')
xlabel('f, Hz')
ylabel('P')
Accepted Answer
More Answers (0)
Categories
Find more on Digital Filter Design in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!