NEED HELP with fir1

2 views (last 30 days)
Justin tran
Justin tran on 29 Apr 2022
Commented: Walter Roberson on 29 Apr 2022
clc;
clear all;
f1 = 100;
f2 = 300;
f3 = 800;
fs = 5000;
m = (0.3*f1)/(f2/2);
M = rand(8/m);
N = M-1;
b = fir1(N,25*f2/(fs/2));
fig(1)
[h,f]= freqz(b,1,512);
plot(f*fs /(2*pi), 20*log10(abs(h)))
xlabel('frequency/Hz'); ylabel('/db');
title('Gain response of band pass filter');
axis [0 0.1 -22];
subplot [3 1 2];
Fs = fft (s,4096);
Afs=abs(Fs);
f = (0:255)*fs/4096;
plot(f,Afs(1:256));
xlabel('Frequency/Hz');ylabel('Amplitude')
title('Frequency domain diagram before filtering')
figure(3)
sF =fft(s,4096);
sf =filter(b,1,5);
subplot [3 1 3];
plot(t,sf)
xlabel('/s');
ylabel('Amplitude')
Afsf = abs(Fsf);
f=(0:255)*fs/4096;
plot(Afsf(1:256))
xlabel('Frequency/Hz');
ylabel('Amplitude')
need help with fir1
  2 Comments
Justin tran
Justin tran on 29 Apr 2022
Sorry about that. I pasted the code in text for you to use. My apologies

Sign in to comment.

Answers (1)

Paul
Paul on 29 Apr 2022
Edited: Paul on 29 Apr 2022
Hi Justin,
Executing the top part of the code ...
f1 = 100;
f2 = 300;
f3 = 800;
fs = 5000;
m = (0.3*f1)/(f2/2);
M = rand(8/m);
N = M-1;
For fir1 to work, N must be an integer scalar. It's not a scalar, and the elements of N are not integers.
size(N)
ans = 1×2
40 40
N(1,1)
ans = -0.5760
For fir1 to work, the second argument has to be between 0 and 1. It isn't.
25*f2/(fs/2)
ans = 3
%b = fir1(N,25*f2/(fs/2));
Can you provide more insight into what you're trying to accomplish with this code?
  1 Comment
Walter Roberson
Walter Roberson on 29 Apr 2022
Note that rand() with a single parameter returns a square matrix, not a vector.

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!