NEED HELP with fir1
4 views (last 30 days)
Show older comments
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
John D'Errico
on 29 Apr 2022
Edited: John D'Errico
on 29 Apr 2022
When you have a question, is there a good reason why you would post a PICTURE of your code? Instead, all you needed to do was to paste in the text itself, complete with the error message. At least you included that.
But by posting only a picture of your code, we cannot now copy that into MATLAB, to show you what you did wrong. We need to retype it from scratch. In fact though, it is actually easier to just paste in text, so you did this the hard way for yourself, and you decreased the fraction of people who might be willing to help you.
Is there a good, valid reason why you want to make it more difficult for someone to help you?
Answers (1)
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)
N(1,1)
For fir1 to work, the second argument has to be between 0 and 1. It isn't.
25*f2/(fs/2)
%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
on 29 Apr 2022
Note that rand() with a single parameter returns a square matrix, not a vector.
See Also
Categories
Find more on Bartlett in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!