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!

- Arduino Uno
- CJMCU-9812 MAX9812L Electret Microphone Amplifier Development Board for Arduino

- Arduino IDE
- MATLAB

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.

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’)*

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:

*figure*

*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)’)*

*xlabel(‘Frequency (Hz)’) *

*ylabel(‘|s(k)|’)*

*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)’)*

*xlabel(‘Frequency (Hz)’) *

*ylabel(‘|X(k)|’)*

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.

- 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.

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); *

*figure*

*plot(w1,abs(h1)), grid *

*xlabel(‘Frequency (Hz)’) *

*ylabel(‘Frequency response’) *

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:

- This can be obtained by connecting together a Low Pass Filter circuit with a High Pass Filter circuit
- When you apply this filter, the signal in the pass-band filter remains the same, while on the outside of the frequency band the frequency components will be attenuated
- Components on the high pass band and low pass band are going to be attenuated
- In our case, this justifies the attenuation of components at frequencies up to 2000 Hz

- An ideal bandpass filter has
**flat passband**, but in our case, as you can see in Figure 4, we have a gain (it also can have attenuation). We can obtain an ideal filter only in mathematics.

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.

1 2

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.

- Digital Signal Processing using MATLAB Part 2
- Intro to Digital Signal Processing using MATLAB Part 1
- Digital Signal Processing Part 3 – Fourier Transform
- Make Your Own Arduino RFID Door Lock – Part 2: Unlock Using Your Smartphone
- DIY RepRap 3D Printer for Beginners – Part 2: Wire
- How To Shrink Your Projects For Arduino

Receive update on new postsPrivacy Policy