Hi there, I have a 1024 coef FIR filter bank, which I use to filter a cosine signal. I have calculated the stop-band supression to be -35dBs but this sounds really high to me. The filters turning point is at 0.1f, where f is the sampling frequency. For example, if I feed the FIR with a frequency of 0.25f, I get a signal out with amplitude 1*10^-6. Does this sound correct? Is there a function in matlab I could use to plot the spectrum resulting from my FIR? Thanks, Aine. My Coefs- 0.000029f,-0.000000f,-0.000029f,-0.000048f,-0.000048f,0.000030f,0.000000f, 0.000030f,0.000049f,0.000049f,0.000030f,0.000000f,-0.000031f,-0.000050f, -0.000050f,-0.000031f,-0.000000f,0.000031f,0.000051f,0.000051f,0.000032f, -0.000000f,-0.000032f,-0.000053f,-0.000053f,-0.000033f,0.000000f,0.000034f, 0.000055f,0.000055f,0.000034f,-0.000000f,-0.000035f,-0.000057f,-0.000057f, -0.000036f,0.000000f,0.000036f,0.000060f,0.000060f,0.000038f,0.000000f, -0.000038f,-0.000063f,-0.000063f,-0.000039f,0.000000f,0.000040f,0.000066f, 0.000066f,0.000042f,-0.000000f,-0.000042f,-0.000069f,-0.000070f,-0.000044f, 0.000000f,0.000045f,0.000073f,0.000074f,0.000046f,-0.000000f,-0.000047f, -0.000078f,-0.000079f,-0.000049f,-0.000000f,0.000050f,0.000082f,0.000083f, 0.000052f,-0.000000f,-0.000053f,-0.000088f,-0.000089f,-0.000055f,0.000000f, 0.000057f,0.000093f,0.000094f,0.000059f,-0.000000f,-0.000060f,-0.000099f, -0.000100f,-0.000063f,0.000000f,0.000064f,0.000105f,0.000106f,0.000067f, 0.000000f,-0.000068f,-0.000112f,-0.000113f,-0.000071f,-0.000000f,0.000073f, 0.000119f,0.000120f,0.000075f,-0.000000f,-0.000077f,-0.000127f,-0.000128f, -0.000080f,0.000000f,0.000082f,0.000135f,0.000136f,0.000085f,-0.000000f, -0.000087f,-0.000143f,-0.000145f,-0.000091f,-0.000000f,0.000093f,0.000152f, 0.000154f,0.000096f,-0.000000f,-0.000099f,-0.000161f,-0.000163f,-0.000102f, 0.000000f,0.000105f,0.000171f,0.000173f,0.000108f,-0.000000f,-0.000111f, -0.000182f,-0.000184f,-0.000115f,0.000000f,0.000118f,0.000193f,0.000195f, 0.000122f,-0.000000f,-0.000125f,-0.000204f,-0.000207f,-0.000129f,0.000000f, 0.000132f,0.000216f,0.000219f,0.000137f,-0.000000f,-0.000140f,-0.000229f, -0.000231f,-0.000145f,-0.000000f,0.000148f,0.000242f,0.000245f,0.000153f, -0.000000f,-0.000156f,-0.000256f,-0.000258f,-0.000162f,0.000000f,0.000165f, 0.000270f,0.000273f,0.000171f,0.000000f,-0.000174f,-0.000285f,-0.000288f, -0.000180f,0.000000f,0.000184f,0.000301f,0.000304f,0.000190f,-0.000000f, -0.000194f,-0.000317f,-0.000320f,-0.000200f,0.000000f,0.000204f,0.000334f, 0.000337f,0.000211f,-0.000000f,-0.000215f,-0.000351f,-0.000355f,-0.000222f, -0.000000f,0.000226f,0.000370f,0.000374f,0.000233f,-0.000000f,-0.000238f, -0.000389f,-0.000393f,-0.000245f,0.000000f,0.000250f,0.000409f,0.000413f, 0.000258f,-0.000000f,-0.000263f,-0.000429f,-0.000434f,-0.000271f,0.000000f, 0.000276f,0.000451f,0.000455f,0.000284f,0.000000f,-0.000290f,-0.000473f, -0.000478f,-0.000298f,0.000000f,0.000304f,0.000496f,0.000501f,0.000313f, -0.000000f,-0.000319f,-0.000521f,-0.000526f,-0.000328f,-0.000000f,0.000334f, 0.000546f,0.000551f,0.000344f,-0.000000f,-0.000350f,-0.000572f,-0.000577f, -0.000360f,0.000000f,0.000367f,0.000599f,0.000604f,0.000377f,0.000000f, -0.000384f,-0.000627f,-0.000633f,-0.000395f,0.000000f,0.000402f,0.000656f, 0.000662f,0.000413f,0.000000f,-0.000421f,-0.000687f,-0.000693f,-0.000432f, 0.000000f,0.000440f,0.000718f,0.000725f,0.000452f,-0.000000f,-0.000460f, -0.000751f,-0.000758f,-0.000473f,-0.000000f,0.000481f,0.000786f,0.000793f, 0.000494f,-0.000000f,-0.000503f,-0.000821f,-0.000829f,-0.000517f,0.000000f, 0.000526f,0.000859f,0.000866f,0.000540f,-0.000000f,-0.000550f,-0.000897f, -0.000905f,-0.000565f,0.000000f,0.000575f,0.000938f,0.000946f,0.000590f, 0.000000f,-0.000601f,-0.000980f,-0.000989f,-0.000617f,0.000000f,0.000628f, 0.001024f,0.001034f,0.000644f,-0.000000f,-0.000656f,-0.001071f,-0.001080f, -0.000674f,0.000000f,0.000686f,0.001119f,0.001129f,0.000704f,-0.000000f, -0.000717f,-0.001170f,-0.001180f,-0.000736f,0.000000f,0.000749f,0.001223f, 0.001234f,0.000769f,-0.000000f,-0.000783f,-0.001279f,-0.001290f,-0.000805f, 0.000000f,0.000819f,0.001337f,0.001349f,0.000842f,0.000000f,-0.000857f, -0.001399f,-0.001412f,-0.000881f,0.000000f,0.000897f,0.001464f,0.001478f, 0.000922f,-0.000000f,-0.000939f,-0.001533f,-0.001548f,-0.000965f,0.000000f, 0.000983f,0.001606f,0.001621f,0.001011f,-0.000000f,-0.001031f,-0.001683f, -0.001699f,-0.001060f,-0.000000f,0.001081f,0.001766f,0.001783f,0.001112f, -0.000000f,-0.001134f,-0.001853f,-0.001871f,-0.001168f,0.000000f,0.001191f, 0.001946f,0.001966f,0.001227f,0.000000f,-0.001252f,-0.002046f,-0.002067f, -0.001291f,-0.000000f,0.001317f,0.002154f,0.002176f,0.001359f,-0.000000f, -0.001388f,-0.002269f,-0.002294f,-0.001433f,0.000000f,0.001464f,0.002394f, 0.002421f,0.001513f,-0.000000f,-0.001546f,-0.002530f,-0.002559f,-0.001599f, -0.000000f,0.001636f,0.002678f,0.002709f,0.001694f,-0.000000f,-0.001734f, -0.002840f,-0.002874f,-0.001798f,0.000000f,0.001842f,0.003018f,0.003056f, 0.001912f,-0.000000f,-0.001962f,-0.003215f,-0.003257f,-0.002039f,-0.000000f, 0.002094f,0.003434f,0.003481f,0.002181f,-0.000000f,-0.002243f,-0.003681f, -0.003733f,-0.002341f,0.000000f,0.002411f,0.003959f,0.004019f,0.002522f, -0.000000f,-0.002601f,-0.004276f,-0.004345f,-0.002729f,-0.000000f,0.002821f, 0.004642f,0.004722f,0.002969f,-0.000000f,-0.003077f,-0.005069f,-0.005163f, -0.003251f,0.000000f,0.003378f,0.005574f,0.005687f,0.003587f,-0.000000f, -0.003740f,-0.006182f,-0.006319f,-0.003993f,0.000000f,0.004181f,0.006928f, 0.007098f,0.004497f,-0.000000f,-0.004734f,-0.007867f,-0.008085f,-0.005139f, 0.000000f,0.005448f,0.009087f,0.009377f,0.005985f,-0.000000f,-0.006405f, -0.010739f,-0.011142f,-0.007154f,0.000000f,0.007757f,0.013102f,0.013703f, 0.008875f,-0.000000f,-0.009817f,-0.016771f,-0.017763f,-0.011668f,0.000000f, 0.013341f,0.023253f,0.025196f,0.016991f,-0.000000f,-0.020774f,-0.037820f, -0.043229f,-0.031173f,0.000000f,0.046768f,0.100902f,0.151360f,0.187096f, 0.200000f,0.187096f,0.151360f,0.100902f,0.046768f,0.000000f,-0.031173f, -0.043229f,-0.037820f,-0.020774f,-0.000000f,0.016991f,0.025196f,0.023253f, 0.013341f,0.000000f,-0.011668f,-0.017763f,-0.016771f,-0.009817f,-0.000000f, 0.008875f,0.013703f,0.013102f,0.007757f,0.000000f,-0.007154f,-0.011142f, -0.010739f,-0.006405f,-0.000000f,0.005985f,0.009377f,0.009087f,0.005448f, 0.000000f,-0.005139f,-0.008085f,-0.007867f,-0.004734f,-0.000000f,0.004497f, 0.007098f,0.006928f,0.004181f,0.000000f,-0.003993f,-0.006319f,-0.006182f, -0.003740f,-0.000000f,0.003587f,0.005687f,0.005574f,0.003378f,0.000000f, -0.003251f,-0.005163f,-0.005069f,-0.003077f,-0.000000f,0.002969f,0.004722f, 0.004642f,0.002821f,-0.000000f,-0.002729f,-0.004345f,-0.004276f,-0.002601f, -0.000000f,0.002522f,0.004019f,0.003959f,0.002411f,0.000000f,-0.002341f, -0.003733f,-0.003681f,-0.002243f,-0.000000f,0.002181f,0.003481f,0.003434f, 0.002094f,-0.000000f,-0.002039f,-0.003257f,-0.003215f,-0.001962f,-0.000000f, 0.001912f,0.003056f,0.003018f,0.001842f,0.000000f,-0.001798f,-0.002874f, -0.002840f,-0.001734f,-0.000000f,0.001694f,0.002709f,0.002678f,0.001636f, -0.000000f,-0.001599f,-0.002559f,-0.002530f,-0.001546f,-0.000000f,0.001513f, 0.002421f,0.002394f,0.001464f,0.000000f,-0.001433f,-0.002294f,-0.002269f, -0.001388f,-0.000000f,0.001359f,0.002176f,0.002154f,0.001317f,-0.000000f, -0.001291f,-0.002067f,-0.002046f,-0.001252f,0.000000f,0.001227f,0.001966f, 0.001946f,0.001191f,0.000000f,-0.001168f,-0.001871f,-0.001853f,-0.001134f, -0.000000f,0.001112f,0.001783f,0.001766f,0.001081f,-0.000000f,-0.001060f, -0.001699f,-0.001683f,-0.001031f,-0.000000f,0.001011f,0.001621f,0.001606f, 0.000983f,0.000000f,-0.000965f,-0.001548f,-0.001533f,-0.000939f,-0.000000f, 0.000922f,0.001478f,0.001464f,0.000897f,0.000000f,-0.000881f,-0.001412f, -0.001399f,-0.000857f,0.000000f,0.000842f,0.001349f,0.001337f,0.000819f, 0.000000f,-0.000805f,-0.001290f,-0.001279f,-0.000783f,-0.000000f,0.000769f, 0.001234f,0.001223f,0.000749f,0.000000f,-0.000736f,-0.001180f,-0.001170f, -0.000717f,-0.000000f,0.000704f,0.001129f,0.001119f,0.000686f,0.000000f, -0.000674f,-0.001080f,-0.001071f,-0.000656f,-0.000000f,0.000644f,0.001034f, 0.001024f,0.000628f,0.000000f,-0.000617f,-0.000989f,-0.000980f,-0.000601f, 0.000000f,0.000590f,0.000946f,0.000938f,0.000575f,0.000000f,-0.000565f, -0.000905f,-0.000897f,-0.000550f,-0.000000f,0.000540f,0.000866f,0.000859f, 0.000526f,0.000000f,-0.000517f,-0.000829f,-0.000821f,-0.000503f,-0.000000f, 0.000494f,0.000793f,0.000786f,0.000481f,-0.000000f,-0.000473f,-0.000758f, -0.000751f,-0.000460f,-0.000000f,0.000452f,0.000725f,0.000718f,0.000440f, 0.000000f,-0.000432f,-0.000693f,-0.000687f,-0.000421f,0.000000f,0.000413f, 0.000662f,0.000656f,0.000402f,0.000000f,-0.000395f,-0.000633f,-0.000627f, -0.000384f,0.000000f,0.000377f,0.000604f,0.000599f,0.000367f,0.000000f, -0.000360f,-0.000577f,-0.000572f,-0.000350f,-0.000000f,0.000344f,0.000551f, 0.000546f,0.000334f,-0.000000f,-0.000328f,-0.000526f,-0.000521f,-0.000319f, -0.000000f,0.000313f,0.000501f,0.000496f,0.000304f,0.000000f,-0.000298f, -0.000478f,-0.000473f,-0.000290f,0.000000f,0.000284f,0.000455f,0.000451f, 0.000276f,0.000000f,-0.000271f,-0.000434f,-0.000429f,-0.000263f,-0.000000f, 0.000258f,0.000413f,0.000409f,0.000250f,0.000000f,-0.000245f,-0.000393f, -0.000389f,-0.000238f,-0.000000f,0.000233f,0.000374f,0.000370f,0.000226f, -0.000000f,-0.000222f,-0.000355f,-0.000351f,-0.000215f,-0.000000f,0.000211f, 0.000337f,0.000334f,0.000204f,0.000000f,-0.000200f,-0.000320f,-0.000317f, -0.000194f,-0.000000f,0.000190f,0.000304f,0.000301f,0.000184f,0.000000f, -0.000180f,-0.000288f,-0.000285f,-0.000174f,0.000000f,0.000171f,0.000273f, 0.000270f,0.000165f,0.000000f,-0.000162f,-0.000258f,-0.000256f,-0.000156f, -0.000000f,0.000153f,0.000245f,0.000242f,0.000148f,-0.000000f,-0.000145f, -0.000231f,-0.000229f,-0.000140f,-0.000000f,0.000137f,0.000219f,0.000216f, 0.000132f,0.000000f,-0.000129f,-0.000207f,-0.000204f,-0.000125f,-0.000000f, 0.000122f,0.000195f,0.000193f,0.000118f,0.000000f,-0.000115f,-0.000184f, -0.000182f,-0.000111f,-0.000000f,0.000108f,0.000173f,0.000171f,0.000105f, 0.000000f,-0.000102f,-0.000163f,-0.000161f,-0.000099f,-0.000000f,0.000096f, 0.000154f,0.000152f,0.000093f,-0.000000f,-0.000091f,-0.000145f,-0.000143f, -0.000087f,-0.000000f,0.000085f,0.000136f,0.000135f,0.000082f,0.000000f, -0.000080f,-0.000128f,-0.000127f,-0.000077f,-0.000000f,0.000075f,0.000120f, 0.000119f,0.000073f,-0.000000f,-0.000071f,-0.000113f,-0.000112f,-0.000068f, 0.000000f,0.000067f,0.000106f,0.000105f,0.000064f,0.000000f,-0.000063f, -0.000100f,-0.000099f,-0.000060f,-0.000000f,0.000059f,0.000094f,0.000093f, 0.000057f,0.000000f,-0.000055f,-0.000089f,-0.000088f,-0.000053f,-0.000000f, 0.000052f,0.000083f,0.000082f,0.000050f,-0.000000f,-0.000049f,-0.000079f, -0.000078f,-0.000047f,-0.000000f,0.000046f,0.000074f,0.000073f,0.000045f, 0.000000f,-0.000044f,-0.000070f,-0.000069f,-0.000042f,-0.000000f,0.000042f, 0.000066f,0.000066f,0.000040f,0.000000f,-0.000039f,-0.000063f,-0.000063f, -0.000038f,0.000000f,0.000038f,0.000060f,0.000060f,0.000036f,0.000000f, -0.000036f,-0.000057f,-0.000057f,-0.000035f,-0.000000f,0.000034f,0.000055f, 0.000055f,0.000034f,0.000000f,-0.000033f,-0.000053f,-0.000053f,-0.000032f, -0.000000f,0.000032f,0.000051f,0.000051f,0.000031f,-0.000000f,-0.000031f, -0.000050f,-0.000050f,-0.000031f,0.000000f,0.000030f,0.000049f,0.000049f, 0.000030f,0.000000f,-0.000030f,-0.000048f,-0.000048f,-0.000029f,-0.000000f, 0.000029f,0.000047f,
Simply FIR question
Started by ●November 22, 2004
Reply by ●November 22, 20042004-11-22
In Matlab, use the freqz function. Type help freqz for more info. With FIR filters, the attenuation may be 35dB worst case in the stop band, but still may have "nulls" or "ripples" that are significantly deeper than this. The freqz plot should show this. Or you could try a few other frequencies nearby to see if the results differ. "?ine Canby" <aine_canby@yahoo.com> wrote in message news:57ed59a.0411221150.14b9be53@posting.google.com...> Hi there, > > I have a 1024 coef FIR filter bank, which I use to filter a cosine > signal. I have calculated the stop-band supression to be -35dBs but > this sounds really high to me. The filters turning point is at 0.1f, > where f is the sampling frequency. For example, if I feed the FIR with > a frequency of 0.25f, I get a signal out with amplitude 1*10^-6. Does > this sound correct? > > Is there a function in matlab I could use to plot the spectrum > resulting from my FIR?
Reply by ●November 22, 20042004-11-22
in matlab it is also possible to design FIR filters, especially with fdatool if you have the toolbox, or using the fir1() or remez() commands, depending on the filter you want to deign. This is helpful in the case you don't want to copy your 1024 coeffs into a matlab function to plot them ... :-) sam
Reply by ●November 23, 20042004-11-23
Thanks for your answers. I tried filtering a cos signal as follows - a=fir1(1024,0.2); %a = a' %freqz(a,1,1024); k = 0:1:20000; fk = cos(0.3*pi*k); y = filter(a,1,fk); plot(y(1024:20000)); and the output filtered signal has a magnitude of 1.5*10-4, which is -38.23 for an input magnitude of 1. At the same time if I plot the freqz() of "a" I get a graph which suggests that the attenuation at 0.3f (f=sampling freq) is in the order of -70dBs? Why is this and how should I establish my stopband attenuation in dBs, because looking at the freqz graph it seems to be -70dBs for frequencies above 0.25f. Cheers, Aine.
Reply by ●November 23, 20042004-11-23
(...)> and the output filtered signal has a magnitude of 1.5*10-4, which is > -38.23 for an input magnitude of 1.I think you mean -38.23 dB ?? Well, this isn't really correct... The definition of the dB is : L [dB] = 10*log10(P2/P1) if P1 and P2 are powers (watts for example) and L [dB] = 20 * log10(V2/V1) if, for example, V1 and V2 are values such as voltages or currents. The value that you read when doing your plot is not a power, so you have to use the second equation : 20*log10((1.5*10^-4)/1) = -76.48 dB Does this answer your question ? Sam
Reply by ●November 23, 20042004-11-23
aine_canby@yahoo.com (?ine Canby) wrote> and the output filtered signal has a magnitude of 1.5*10-4, which is > -38.23 for an input magnitude of 1.>> 20*log10(1.5*10^-4)ans = -76.4782 Perhaps you need to do the power rather than the magnitude? Ciao, Peter K.
Reply by ●November 24, 20042004-11-24
On 23 Nov 2004 07:27:57 -0800, aine_canby@yahoo.com (?ine Canby) wrote:>Thanks for your answers. I tried filtering a cos signal as follows - > >a=fir1(1024,0.2); >%a = a' >%freqz(a,1,1024); > >k = 0:1:20000; >fk = cos(0.3*pi*k); >y = filter(a,1,fk); >plot(y(1024:20000)); > >and the output filtered signal has a magnitude of 1.5*10-4, which is >-38.23 for an input magnitude of 1. At the same time if I plot the >freqz() of "a" I get a graph which suggests that the attenuation at >0.3f (f=sampling freq) is in the order of -70dBs? Why is this and how >should I establish my stopband attenuation in dBs, because looking at >the freqz graph it seems to be -70dBs for frequencies above 0.25f. > >Cheers, > >Aine.Hi, Wow, ... you used some strange values in your code. Anyway, the steady state response of your filter output is a sinusoid whose peak amplitude is 1.37*10^-4. Your input sinusoid has a peak amplitude 1. So .... 1.37*10^-4 dB = 20*log10 --------------- = -77.23 1 Your filter input frequency is roughly 0.15Fs Hz (Fs is sample rate). So if you use freqz(a,1,4096,1), zoom on and look closely (zoom in several times) at the magnitude response exactly at the freq of 0.15Fs Hz, you'll see that the mag response is quite close to -77.5 dB which agrees well with the above "dB" computation. [-Rick-]
Reply by ●November 24, 20042004-11-24
Thanks, I now understand what I was doing wrong. p.kootsookos@iolfree.ie (Peter Kootsookos) wrote in message news:<3fca8095.0411231251.6426d1c4@posting.google.com>...> aine_canby@yahoo.com (?ine Canby) wrote > > > and the output filtered signal has a magnitude of 1.5*10-4, which is > > -38.23 for an input magnitude of 1. > > >> 20*log10(1.5*10^-4) > > ans = > > -76.4782 > > Perhaps you need to do the power rather than the magnitude? > > Ciao, > > Peter K.