This is a continuation of our DSP Arduino series. Last time, we covered the basics of Fourier transform and using MATLAB we learned how to transform a sinusoidal signal from the time domain to the frequency domain. This time, after adding a distortion filter, we will create a simple GUI in MATLAB to record our voice signal!
From the previous article, we’ve obtained a signal that had a low-passed filter with a 40th order. For this step, we need to add another filter which distorts the signal. This can be done with the filter function in MATLAB. As you may already know, we’ll also need to add the coefficients shown below.
[s,fe2,bits] = wavread(‘s’);
b = [0.1662, -0.0943, 0.2892, -0.1227, 0.2348, 0.0180, 0.0415, 0.1388, -0.0616, 0.1290, -0.0434, 0.0420, -0.0010, -0.0009, 0.0032, -0.0015, 0.0056] ;
a = [1.0000, -0.7548, 3.4400, -1.6385, 4.8436, -0.8156, 3.2813, 1.2582, 0.6571, 2.1922, -0.4792, 1.4546, -0.2905, 0.4693, -0.0208, 0.0614, 0.0120] ;
x = filter(b,a,s);
title(‘The initial signal vs the distorted signal’);
Please note that s is the signal obtained in the previous step when we applied the low-pass filter. In Figure 1, the blue signal represents the original signal, while the green signal represents the distorted signal. The green signal has a lower amplitude compared to the blue one.
To examine further, we are going to use the FFT algorithm.
For a better comparison, the signals were plotted separately. The next two figures will illustrate the difference between the time and frequency domain.
% s si x signals (time-frequency domain)
title(‘s signal in time domain(low-pass filter)’);
title(‘x signal in time domain(distorted)’);
In the time domain, there is significant modification; s signal has a lower value, even if the visualization of those two pictures would give you the impression that x signal has a higher value. If you are looking at the y-axis scaling, you can observe the difference in amplitude. At this point, maybe you are wondering what kind of filter applied was applied and what kind of modification resulted in those coefficients.
The answer is found in the frequency domain:
s1 = abs(fft(s,NS));
subplot(2,1,1), plot((0:(NS-1))/NS*fe2, s1), grid
title(‘Single-Sided Amplitude Spectrum of s(t)’)
x1 = abs(fft(x,NS));
subplot(2,1,2), plot((0:(NS-1))/NS*fe2, x1), grid
title(‘Single-Sided Amplitude Spectrum of x(t)’)
We applied the Fourier transform in order to find the equivalent frequency. As you can see in Figure 3, the point where the y-axis becomes symmetrical is around sampling frequency divided by two.
Those two signals have different spectrum.
It’s pretty difficult to examine the plot at this frequency. So let’s make it around 2000 Hz and reevaluate the values.
If we look closer to the y-axis, we can observe that the signals have the same shape, even though they didn’t look similar in Figure 3. The problem with that figure was the axis scaling, which resulted in the impression of a dissimilar-looking signal.
On both figures, we observed that the amplitude has been lowered. We still don’t know what the frequency response of the filter is and what other modification this brings to our signal. In this case, we can plot it using Matlab.
[h1,w1] = freqz(b,a,NS,fe2);
This new type of filter is called band pass filter. Since this is new, let’s go over some of its properties before we proceed further:
You can see that the filter in Figure 6 has similar shape to the filter in Figure 5. Thus, we have obtained the new filter.