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!
CJMCU-9812 MAX9812L Electret Microphone Amplifier Development Board for Arduino
Step 3: Applying the distortion filter
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’); sound(s,fe2); pause(9) 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); figure plot(t1,s2,t1,x),grid title(‘The initial signal vs the distorted signal’); sound(x,fe2); pause(9) audiowrite(‘x.wav’,x,fe2);
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.
Figure 1: Overlapping signals
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)
t1=(0:length(s)-1)/(fe2); figure subplot(2,1,1), plot(t1,s),grid title(‘s signal in time domain(low-pass filter)’); xlabel(‘Time’) ylabel(‘Amplitude’)
t2=(0:length(x)-1)/(fe2); subplot(2,1,2), plot(t2,x),grid title(‘x signal in time domain(distorted)’); xlabel(‘Time’) ylabel(‘Amplitude’)
Figure 2: Before and after distortion of the signal in time domain
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.
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.
Figure 3: Before and after distortion of the signal in frequency domain
Those two signals have different spectrum.
In the top
Y-axis has values around 800.
After value of 2000 Hz, there is no signal shown.
In the bottom:
Y-axis has values around 40.
After value of 2000 Hz, we can observe there is signal.
It’s pretty difficult to examine the plot at this frequency. So let’s make it around 2000 Hz and reevaluate the values.
Figure 4: A small interval around 2500 Hz
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.
Tiberia is currently in her final year of electrical engineering at Politehnica University of Bucharest. She is very passionate about designing and developing Smart Home devices that make our everyday lives easier.