Bandpass filtering with noise sequence

1 view (last 30 days)
Reelz
Reelz on 29 Jan 2016
Answered: Star Strider on 29 Jan 2016
Hi guys, I am trying to make a filtered noise sequence with a nonzero spectrum between f1 = 100 and f2 = 300 Hz. However, my following code is producing a frequency vs magnitude graph that starts at 450? Here is the graph and the code:
% speccos.m plot the spectrum of a cosine wave
f1=100;
f2=300;
time=2; % length of time
Ts=1/1000; % time interval between samples
x=randn(1,time/Ts); % generate noise signal
freqs=[ 0.2 0.3 0.4 0.5 0.55 0.6];
amps=[0 0 1 1 0 0];
b=firpm(100,freqs,amps); % BP filter
ylp=filter(b,1,x); % do the filtering
figure(1),plotspec(ylp,Ts) % plot the output spectrum

Answers (1)

Star Strider
Star Strider on 29 Jan 2016
I don’t have the toolbox that includes the plotspec function, so I used freqz and redesigned your filter.
See if this does what you want:
f1=100;
f2=300;
time=2; % length of time
Ts=1/1000; % time interval between samples
x=randn(1,time/Ts); % generate noise signal
freqs=[ 0.0 0.2 0.3 0.5 0.6 1];
amps=[0 0 1 1 0 0];
b=firpm(100,freqs,amps); % BP filter
ylp=filter(b,1,x); % do the filtering
% figure(1),plotspec(ylp,Ts) % plot the output spectrum
figure(1)
freqz(b,1,1024,1/Ts) % Filter Bode Plot

Community Treasure Hunt

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

Start Hunting!