Eglė Ged
Eglė Ged

Reputation: 27

How to filter high freq signals?

So I have a task to do for university to filter High frequency signals in MATLAB. I wrote code for it but it doesn't filter correctly. This is my code:

A1 = 7;
A2 = 10;
A3 = 2;
f1 = 934;
f2 = 232;
f3 = 844;
th1 = 5*pi/4;
th2 = pi/4;
th3 = 5*pi/8;
M = 21;
T = 0.7823;
T1 = 0.0331;
T2 = 0.08;
fd = 6395;
K = 3;

Td = 1/fd; % diskretizavimo periodas
N = fix(T/Td); %modeliuojamo signalo reiksmiu skaicius
t = (0:N-1)*Td;

y = A1*sin(2*pi*f1*t + th1)+A2*sin(2*pi*f2*t + th2);

df = 1/T;
Nf=fd/df;


frib=(f1+f2)/2;
Wn = frib/fd;

b = fir1(M, Wn, 'high');
N2=Nf/2; 
fasis = (0:Nf-1)*df;

filt_y = filter(b,1, y);
FILT_Y = abs(fft(filt_y, Nf));
figure(17)
subplot(2,1,1)
plot(t(1:T1*2/Td),filt_y(1:T1*2/Td));box('off'); axis tight;
set(gca, 'fontsize', 12); title('Filtruotas sinusu sumos signalas')
subplot(2,1,2)
stem(fasis(1:N2),FILT_Y(1:N2),'.');box('off'); axis tight;
set(gca, 'fontsize', 12); title('Filtruoto sinusu sumos signalo spektras')

frib is the cut-off frequency

And these are my diagrams: enter image description here

Can you please tell me what can I do to make only one visible in the second diagram (near 1000 freq)? I don't know what I could do more

Upvotes: 0

Views: 67

Answers (1)

Ander Biguri
Ander Biguri

Reputation: 35525

If you see the Fourier components of your signal before and after, you can clearly see how the first main frequency gets hugely reduced:

noFILT_Y = abs(fft(y, Nf));

subplot(2,1,2)
stem(fasis(1:N2),FILT_Y(1:N2),'.');box('off'); axis tight;
subplot(2,1,1)
stem(fasis(1:N2),noFILT_Y(1:N2),'.');box('off'); axis tight;

enter image description here

But if you follow @irreducible's suggestion:

Wn = frib/(fd/2);

enter image description here

Upvotes: 2

Related Questions