How to plot a bode graph for a filtered output?

So I have a IIR butterworth filter with coeffficient converted into its transfer function, [b a]=sos2tf(SOS,G). I have a input audio file that I am using this filter on, and I did y = fitler(b,a,x), but now I am confused as to how I can plot the magnitude and frequency of this output?. I am also lacking theoritical knowledge on this subject which has made it hard for me to understand this.

 Accepted Answer

... coeffficient converted into its transfer function, [b a]=sos2tf(SOS,G).
Do not do that! Keep it as a second-order-section realisation for best results and greatest stability.
y = fitler(b,a,x)
Do not do that, either. Use the filtfilt function instead, since its results are phase-neutral (no phase distortion).
Use the fft function to calculate the frequency-domain (spectrum) representation of the output. Plot the magnitude using the absolute (abs) value, and the phase using the angle function.
The documentation for those functions go into extensive detail as to how to use them, so I will not describe them further here.
.

6 Comments

ok thank you very much, the reason I used filter was because we were also asked to hear the noise of the filter and when I did sound(y) when I had done filt filt, that did not work at all.
My pleasure!
If the instructions were to use filter, then using the second-order-section representation would not work because filter only accepts transfer function representation.
My comments about the magnitude and frequency calculations and plots remain valid. As far as the theoretical knowledge of the Fourier transform is concerned, there are many books and websites with that information. It is not absolutely straightforward because it deals with complex variables and complex integration, however it is not difficult to understand with an undergraduate background in calculus.
.
actually quick question, is there a way to convert the frequency to rad/sec, since plotting the abs of fft will give it to me in frequency, I can use mag2dB for the magnitude, but am confused as to how I'd convert it to rad/sec for the frequency
Yes, there is. The frequency scale of a one-sided Fourier transform (or each side of a two-sided Foureir transform) goes from 0 to the Nyquist frequency, and the Nyquist frequency is equivalent to π rad/sec (or whatever the denominator unit is, since it can also be spatial, but I digress).
So if the frequency were to go from 0 to 10 Hz (10 Hz being the Nyquist frequency):
fHz = linspace(0, 10, 11)
fHz = 1×11
0 1 2 3 4 5 6 7 8 9 10
the radian frequency would go from 0 to π:
fradsec = (fHz * pi)/max(fHz);
fradsec(1:6)
ans = 1×6
0 0.3142 0.6283 0.9425 1.2566 1.5708
fradsec(7:11)
ans = 1×5
1.8850 2.1991 2.5133 2.8274 3.1416
.
so if the frequency of my output were 44100, my case would be 44100/2, so fhz would go from 0: 44100/2, and then same process follows?
Yes, exactly.
To illustrate —
fHz = linspace(0, 44100/2, 11);
fHz(1:6)
ans = 1×6
0 2205 4410 6615 8820 11025
fHz(7:11)
ans = 1×5
13230 15435 17640 19845 22050
fradsec = (fHz * pi)/max(fHz);
fradsec(1:6)
ans = 1×6
0 0.3142 0.6283 0.9425 1.2566 1.5708
fradsec(7:11)
ans = 1×5
1.8850 2.1991 2.5133 2.8274 3.1416
.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!