MONO TO STEREO SYNTHESIZER IMPLEMENTATION ON FPGA Santosh Kumar Thouta BTech, CMR College of Engineering and Technology, India, 2006 PROJECT Submitted in partial satisfaction of the requirements for the degree of MASTER OF SCIENCE in ELECTRICAL AND ELECTRONIC ENGINEERING at CALIFORNIA STATE UNIVERSITY, SACRAMENTO SPRING 2010 MONO TO STEREO SYNTHESIZER IMPLEMENTATION ON FPGA A Project by Santosh Kumar Thouta Approved by: __________________________________, Committee Chair Jing Pang, Ph.D. __________________________________, Second Reader Preetham Kumar, Ph.D. ____________________________ Date ii Student: Santosh Kumar Thouta I certify that this student has met the requirements for format contained in the University format manual, and that this project is suitable for shelving in the Library and credit is to be awarded for the Project. ______________________, Graduate Coordinator Preetham Kumar, Ph.D. Department of Electrical & Electronics Engineering iii ________________ Date Abstract of MONO TO STEREO SYNTHESIZER IMPLEMENTATION ON FPGA by Santosh Kumar Thouta The main objective of this project is to design a synthesizer that can convert mono audio signal into stereo audio signal. This synthesizer proves to be a handy hardware that allows enjoying stereo quality even though the source of the audio is mono. A graphical user interface is developed using MATLAB, which allows tuning the frequencies, gain and order of the digital filters in the synthesizer to adjust the enhancement in the audio quality. The functionality of the design is verified using the GUI initially and later on with the hardware implemented on the Cyclone II 2C35 FPGA of the Altera DE2 board. The heart of the synthesizer hardware design involves designing digital filters and interfacing several hardware components such as an Audio CODEC, SDRAM and Cyclone II FPGA. The algorithm to do the mono to stereo conversion is coded in Verilog and the Altera Quartus II design suite is used for simulations and synthesis. The project achieved satisfactory stereo audio quality from designed hardware. _______________________, Committee Chair Jing Pang, Ph.D. _______________________ Date iv ACKNOWLEDGMENTS I would like to thank my project advisor, Dr. Jing Pang for guiding me with my project. I am also thankful to her for being very helpful and providing me with valuable ideas and critical technical information that was required during the course of the project. Special thanks to Dr. Preetham kumar for being my second reader and taking time to review my report despite of a very busy schedule. Finally, I am thankful to my family and friends for their great support, encouragement during tough times and guidance during all the time for completion of my Masters project. I am thankful to everyone else who has provided me help for the Masters project. v TABLE OF CONTENTS Page Abstract ........................................................................................................................ iv Acknowledgments......................................................................................................... v List of Tables ............................................................................................................. vii List of Figures ........................................................................................................... viii Chapter 1. BACKGROUND STUDY AND INTRODUCTION …………………………… 1 1.1 Background ................................................................................................. 1 1.2 Introduction ................................................................................................ 1 2. STEREO ENHANCEMENT TECHNIQUES ........................................................ 3 2.1 Mono to Stereo conversion and stereo enhancement .................................. 3 2.2 Mono to Stereo conversion without crosstalk ............................................. 4 2.3 Mono to Stereo conversion with crosstalk .................................................. 5 2.3.1 Architecture.................................................................................. 6 2.3.2 MATLAB simulation of the crosstalk architecture ..................... 8 2.4 Mono to stereo conversion with crosstalk and reverberation ..................... 9 2.4.1 Reverberator model using comb filters ...................................... 11 2.4.2 All-pass filter ............................................................................. 11 2.4.3 Matlab simulation results of the reverberator model using comb filters ................................................................................................... 12 2.5 Reverberator using IIR and FIR filters ..................................................... 14 2.5.1 Matlab simulations of the reverberator model using IIR and FIR filter ..................................................................................................... 14 3. SOFTWARE DESIGN OF SYNTHESIZER AND FILTER DESIGN TECHNIQUES ..................................................................................................... 16 3.1 Mono to stereo synthesizer software design ............................................. 16 3.1.1 Experiments to get the best stereo effect ................................... 17 vi 3.1.2 Simulations based on filter order ............................................... 18 3.1.3 MATLAB simulation of an 8th order band pass filter ................ 19 3.2 Filter design techniques ............................................................................ 19 3.2.1 Analog filters ............................................................................. 20 3.2.2 Digital filters .............................................................................. 20 3.2.3 Advantages of Digital filters ...................................................... 20 3.2.4 Basic representation of a filter ................................................... 21 3.2.5 Types of Digital filters ............................................................... 22 3.2.6 Infinite impulse response (IIR) filter ......................................... 23 3.2.7 Finite impulse response (FIR) filter ........................................... 23 4. HARDWARE DESIGN AND VERIFICATION OF THE SYNTHESIZER ...... 26 4.1 Verilog simulation .................................................................................... 26 4.2 Implementation of the Synthesizer Design ............................................... 27 4.3 Signals used in the design ......................................................................... 29 4.4 ADC module ............................................................................................. 30 4.4.1 ADC module verilog simulation ................................................ 31 4.5 MONO TO STEREO ALGORITHM module .......................................... 32 4.6 DAC module ............................................................................................. 32 4.6.1 DAC module verilog simulation ................................................ 34 5. CONCLUSION AND FUTURE WORK ............................................................. 35 5.1 Conclusion ................................................................................................ 35 5.2 Future work ............................................................................................... 35 Appendix MONO TO STEREO SYNTHESIZER GUI IMPLEMENTATION 36 Bibliography ............................................................................................................... 63 vii LIST OF TABLES Page 1. Table 1 Scaled up input samples in 2’s complement format ………………….. 26 2. Table 2 List of signals used in the design ………………….………………….. 29 3. Table 3 SDRAM address ranges for different audio data ….………………….. 32 viii LIST OF FIGURES Page 1. Figure 1 Mono to stereo conversion without crosstalk …………………………. 4 2. Figure 2 Mono to stereo system with crosstalk architecture ……………………. 6 3. Figure 3 Comb filter block diagram ………………….…………………………. 7 4. Figure 4 Comb filter direct and reflected sound magnitude response …..………. 9 5. Figure 5 Mono to stereo conversion with Crosstalk and reverberation effect …. 10 6. Figure 6 Reverberator design using comb filters…….…………………………. 12 7. Figure 7 Phase delay response curves for different feedback coefficients .……. 13 8. Figure 8 Amplitude responses of the All-pass filter ...…………………………. 13 9. Figure 9 Block diagram of the reverberator using IIR and FIR filter .…………. 14 10. Figure 10 Reverberator amplitude response using IIR and FIR filter …………. 14 11. Figure 11 Mono to stereo synthesizer block diagram.…………………………. 17 12. Figure 12 Stereo output responses using all 8th, 16th and 32nd order filters……. 18 13. Figure 13 Matlab simulation results of an 8th order band pass filter .…………. 19 14. Figure 14 Digital filter ..…………………………….…………………………. 21 15. Figure 15 FIR filter architecture…………………….…………………………. 23 16. Figure 16 Adder/Subtractor symbol .……………….…………………………. 24 17. Figure 17 Unit Delay……………………………….…………………………. 24 18. Figure 18 Multiplier symbol……………………….…………………………. 24 19. Figure 19 Band pass filter audio output data ..…….…………………………. 27 20. Figure 20 Spectrum results of 8th order band pass filtered audio data ………. 27 ix 21. Figure 21 Mono to stereo synthesizer hardware block diagram……………. 27 22. Figure 22 ADC module state machine .………….…………………………. 30 23. Figure 23 Verilog simulation results of the ADC module …………………. 31 24. Figure 24 DAC module state diagram .………….…………………………. 33 25. Figure 25 Verilog simulation results of DAC module ..……………………. 34 x 1 Chapter 1 BACK GROUND STUDY AND INTRODUCTION 1.1 Background A monaural/monophonic signal consists of single audio channel, which can be fed into a single channel or multiple channels. On the contrary, a stereophonic signal consists of two or more channels, where each channel is independent of the other. In a stereo transmission, the sound coming from various directions is different making it sound very natural [8]. Currently most of the audio appliances in the market are using stereo quality transmission, but there exists a few applications such as radio broadcasting and several audio/video transmitter devices where mono transmission is used because of high cost involved in providing stereo quality. A mono to stereo synthesizer/converter would be a handy hardware that would allow the user to enjoy stereo quality audio even from the existing mono audio devices. 1.2 Introduction This project provides a basic methodology to convert a mono audio signal into stereo audio signal. Majority of the human vocal sounds are present in the lower frequency range (20 Hz – 3 kHz), whereas the sounds produced by some music instruments shares a wide frequency range (20 Hz - 20000 kHz). Using this information the synthesizer design concentrates on feeding both the channels of the stereo output with the lower frequencies i.e. 20 Hz – 3 kHz so that the vocal information is not lost in either of the channels. The 2 higher frequencies i.e. between 3 kHz and 20 kHz are treated in such a way that some of the frequency bands are fed to one channel and the rest of them are fed to the other channel covering the complete audio spectrum. The above-mentioned frequency separation can be achieved by using a series of band pass filters in the design with different pass bands. A graphical interface is designed using MATLAB, which allows setting the pass band frequencies and filter orders of the several band-pass filters involved in the design to understand the best configuration of the filters. It is an easy task to simulate a design in software but when it comes to implementing the same design in hardware involves several constraints such as complexity of the algorithm, available resources(memory, I/O, capacity of the FPGA) available, timeline and cost. After performing a few experiments and considering all the above-mentioned constraints, the synthesizer design is implemented using Finite Impulse Response filters of thirty-second order and unity gain. The final design is successful. 3 Chapter 2 STEREO ENHANCEMENT TECHNIQUES The most important aspect of mono to stereo conversion is to get a good quality stereo effect. A mono audio can be converted into stereo using different design approaches but if the design is bad, the stereo quality will degrade a lot. In this chapter, many techniques to convert the mono signal to stereo signal and to enhance the stereo quality are discussed. Simulation results of different enhancement architectures are provided. 2.1 Mono to Stereo conversion and stereo enhancement A mono signal is used as a common source for all the speakers or headphones used in the system. This kind of a mono system gives a good performance in speech transmission because everyone can hear the same sound. A stereo system consists of two or more channels, the sound comes to different channels may have different travelling paths and reflections of sound sources. A poorly designed stereo system results in bad sound quality compared to a well designed mono system. In order to get a better stereo quality from a mono audio source or a stereo audio source, a few techniques are discussed in this chapter. 4 2.2 Mono to Stereo conversion without crosstalk Figure 1. Mono to stereo conversion without crosstalk A simple architecture to convert a mono to stereo signal is shown in Figure 1, where it shows that different frequency band pass FIR filters filter a mono signal and eventually a few frequency bands are passed to the left channel and the rest of the frequency bands to the right channel. Apart from the FIR common filter, which is fed to both the left and right, all other frequency bands are mutually exclusive. The common FIR filter used, covers the low frequency band where most of the vocal audio is available which is important to be transmitted onto both of the speakers. This system lacks the ability to consider the crosstalk that is involved with the left and right channels and the reflections of sound from various objects to create a natural effect. Overall, this system yields decent stereo effect and this architecture is used in the project for hardware implementation after taking into consideration of the resource and time constraints, but the approach is 5 explained in detail, which would enable in implementing systems that are even more complex. 2.3 Mono to Stereo conversion with Crosstalk This technique is an improvised model of the stereo enhancement technique discussed in [1]. In this particular method, both mono and stereo audio signals can act as sources resulting in an enhanced stereo effect output. Whenever one listens to a sound from speakers, there are several sounds that need to be considered to create a stereo effect. For example when a sound is played in two speakers left and right placed apart, the sound heard at the left side is basically the straight sound from the left speaker, the crosstalk sound coming from the right speaker and also reflected sound from various objects. Similarly, the sound at right side also consists of the straight sound, reflected sound and crosstalk. Once all these sounds are produced in the stereo system, the sound is localized around the listener making it sound very natural. In order to achieve such a model, an architecture is proposed as follows which is an improvisation of the one i.e. proposed in [1]. 6 2.3.1 Architecture Figure 2. Mono to stereo system with crosstalk architecture[1] As seen in Figure 2, the input can be a mono source or a stereo source. In case of a mono source a single channel is fed into both the left and right channels and the system would convert it into a stereo signal with enhancement. Whereas in case of a stereo signal provided at the input, the signal goes through the whole stereo enhancement process and provides a richer stereo output. The above architecture can be built using a couple of comb filters, eight FIR filters and Gain control blocks. A comb filter is used to transmit the straight sound as well as the reflected sound. The reflected sound can come from several objects such as a person’s shoulder or a nearby wall. The block diagram of a comb filter is shown in Figure 3. 7 Figure 3. Comb filter block diagram [1] From Figure 3 it is clear that a comb filter can transmit the direct as well as the reflected sound. A reflected signal is implemented by adding a certain delay element to the direct signal and attenuating the signal so that it is not as loud as the direct sound. Mixing the reflected signal with the direct signal provides an audio where one can hear both the straight sounds and the reflected sounds. ‘ar’ and ‘ad’ are the coefficients of the comb filters used to attenuate or boost the reflected and direct signals respectively [1]. The crosstalk portion of the sound at the left speaker is coming from the right channel which is divided into four different frequency bands using FIR band pass filters. The gains of all these band pass filters are controlled in the ‘Gain control’ section which would allow the user to control the gain of the system. If one wants to enhance the quality of speech, the ‘Gain Control’ section should be used to increase the gain on the lower frequency bands where most of the vocal information is available, similarly in order to enhance the melody increasing the gain on intermediate frequency bands should result in good stereo sound [1]. Four FIR filters are used to produce the cross talk from each channel and only one of them has a common frequency band, whereas all others have frequency bands, which are mutually exclusive. Finally, after generating the direct, 8 reflected and crosstalk sounds from the respective speakers, they are mixed together as shown in Figure 2 to get a richer stereo effect. 2.3.2 MATLAB simulation of the crosstalk architecture A model of the mono to stereo enhancement with crosstalk architecture is implemented using MATLAB. The parameters used for a comb filter in the design are as follows 1) Delay for the reflected sound = 10ms 2) Gain of the reflected sound(ad) = 0.1 3) Gain of the direct sound(ar) = 1 The parameters used for the different FIR band pass filters used to produce the crosstalk are 1) FIR filter order = 32 2) Frequency bands for the Left Channel crosstalk FIR filters are 20 – 3000Hz, 3000-5000Hz, 5000-7000Hz, 7000 -9000Hz, and gains of these filters is 0.6 3) Frequency bands for the Right Channel crosstalk FIR filters are 20 -3000 Hz, 9000-12000Hz, 12000-150000Hz, 15000-21000Hz, and gains of these filters is 0.5 Using all the above parameters for the FIR filter, comb filters and adjustment sections the simulation results look as follows. 9 0.5 0.4 0.3 0.2 0.1 0 -0.1 -0.2 -0.3 -0.4 -0.5 0 1 2 3 4 5 6 7 5 x 10 Figure 4. Comb filter direct and reflected sound magnitude response In the above Figure 4 the response shown in blue is the direct sound whereas the response shown in green the reflected sound that is attenuated 10 times of the delayed direct signal. The sound quality after the simulation produced a very good stereo effect when compared to the previous non-crosstalk model. 2.4 Mono to stereo conversion with crosstalk and reverberation In the previous architecture, how a mono signal can be converted into stereo by using different frequency bands of the crosstalk is discussed. In the current architecture, a new concept called reverberation is added. Reverberation is a phenomenon where the sound tends to persist even after the original signal is removed because of the several reflections from walls and other objects, which slowly diminish before the sound is absorbed. In addition to the crosstalk model a couple of reverberator models are used from [2] to get a 10 more realistic stereo effect. The mono to stereo architecture with the reverberation block is shown in the following Figure 5. Figure 5. Mono to stereo conversion with Crosstalk and reverberation effect As shown in Figure 5 the mono audio signal is converted into the stereo signal taking into consideration the crosstalk effect coming from the speakers, which is discussed earlier in the chapter. Once the stereo signal is generated, an additional reverberation sound is mixed to portray the effect of sound reflections from several objects. The stereo enhancement observed by listening to the audio output from this model is richer than the previous models. A couple of reverberator models proposed in [2] are used for simulations, which are discussed as follows. 11 2.4.1 Reverberator model using comb filters A comb filter adds up an attenuated or boosted version of a delayed original signal to the original signal [1]. This procedure accounts for minimal reflections that could occur. So a set of four comb filters are used with different delay elements to represent sound reflections from various distant sources. The response of all the comb filters in the reverberator design is then passed through an “All-pass” filter so that all the frequency components are passed through without any attenuation. The Figure6 shows the reverberator model with comb filters [2]. 2.4.2 All-pass filter An all-pass filter is used to pass all the frequency components of a signal without any attenuation in amplitude but with a slight change in the phase delay of the signal causing a distortion effect where new frequency components are added to the original signal. The transfer function of an all-pass filter is shown in equation (1) . ……………………….(1) [2] In the above equation beta is the feedback coefficient and D is the delay element of the All-pass filter. The phase delay of an all-pass filter depends upon the feedback coefficient used and most of the change is observed at lower frequencies of the signal when compared to the higher frequency signals. This filter provides a flat frequency response, which also accounts for multiple sound reflections [2]. 12 Figure 6. Reverberator design using comb filters [2] 2.4.3 Matlab simulation results of the reverberator model using comb filters As shown in the Figure 6 four comb filters with 10ms, 20ms, 30ms and 40ms delay are designed to account for the reflections coming from several distant objects. The feedback coefficients used for the all-pass filter are 0.8, 0.5 and 0.3 to see the effect on the phase delay. Multiple phase delay plots for these feedback coefficients are plotted to check the effect on phase delay of the output signal. As expected the phase delay is dependent on the feedback coefficient of the all-pass filter and most of the phase delay differences are observed only in the lower frequencies. The phase delay plot using different feedback coefficients is shown in Figure 7. The input amplitude response and the output amplitude response of the all-pass filter is shown in Figure8 which shows that the amplitude of the signal is not changed by the all-pass filter. 13 Figure 7. Phase delay response curves for different feedback coefficients All pass input audio 2 1 0 -1 -2 0 1 2 3 4 5 6 7 5 x 10 Allpass output audio 0.4 0.2 0 -0.2 -0.4 0 1 2 3 4 5 6 7 5 x 10 Figure 8. Amplitude responses of the All-pass filter 14 2.5 Reverberator using IIR and FIR filters In this reverberator, the important components are FIR and IIR filters. FIR filter is used to capture the early reflection components and the IIR filter is used to capture the late reverberation components. The block diagram of this reverberator is shown in Figure 9. Figure 9. Block diagram of the reverberator using IIR and FIR filter [2] As seen in Figure 9, the parameters x(n) and y(n) are input and output signal vectors respectively. In order to control the gain of these reflections and reverberation, sound g1, g2 and g3 gain components can be used [2]. 2.5.1 Matlab simulations of the reverberator model using IIR and FIR filter Original signal 0.5 0 -0.5 0 1 2 3 4 5 6 7 5 x 10 Reverberator output signal 0.8 0.6 0.4 0.2 0 0 1 2 3 4 5 6 7 5 x 10 Figure 10. Reverberator amplitude response using IIR and FIR filter 15 The 32nd order FIR filter and a 2nd order IIR filter are used for simulations. Gain values used are g1=0.4, g2=0.6, g3=0.4. The simulation results are shown in figure X. It is observed that the reverberator output has higher amplitude components and it is because of the early reflection and late reverberation components added to the original signal. 16 Chapter 3 SOFTWARE DESIGN OF SYNTHESIZER AND FILTER DESIGN TECHNIQUES Initially the design of the mono to stereo synthesizer is done in software using MATLAB. Designing the synthesizer in software allows doing several experiments by changing the parameters of the filters and other components used in the design. This software design and verification enables a quicker hardware implementation of the design. The current chapter discusses the software design aspect of the synthesizer, which includes the architecture, simulation results and parameter conclusions for hardware implementation. In addition, filter design aspects are also provided which can be useful in understanding the software and hardware implementation of the filter. 3.1 Mono to stereo synthesizer software design Figure 11 shows the top level design of a basic mono to stereo synthesizer. As shown in the diagram the mono audio signal is fed parallelly into several band pass filters and then the outputs of 3 band pass filters (left) and common band pass filter are summed together and sent to the left stereo channel. Similarly, the bottom 3 band pass filter outputs and the common band pass filter outputs are summed together and sent to the right stereo channel. A graphical user interface has been implemented in MATLAB to achieve the synthesizer functionality. The GUI has several self-explanatory functions such as ‘play mono’, ‘play left channel’ and ‘play stereo’ buttons. The GUI also allows user to change 17 the pass band frequencies, gain and order of the filters used in the design to see the effects on stereo conversion. In addition to playing the audio signal the GUI also plots a magnitude and frequency response spectrum’s for the corresponding signals. Figure 11. Mono to stereo synthesizer block diagram [9] 3.1.1 Experiments to get the best stereo effect In order to get a good stereo effect the filter parameters such as order and gain should be tuned properly. Pass band frequencies used for both the left and right channels are 1) Common pass band for both left and right channel is 20 Hz - 3 kHz. 2) Left channel exclusive pass band frequency range 3 kHz - 9 kHz. 3) Right channel exclusive pass band frequency range 9 kHz - 21 kHz. 18 3.1.2 Simulations based on filter order Three simulations are performed to check the filter performance by using all 8th order, 16th order and 32nd order filters only in each simulation separately. Figure 12. Stereo output responses using all 8th, 16th and 32nd order filters From the above simulation results, we can see that the higher the order of the filters used the better we get the frequency response. As seen from the 32nd order filter simulation results the pass band for left and right channel are as expected by the specification, so in the current design all 32nd order filters will be used for hardware and software implementation and analysis. In addition, the frequency response, the audio quality observed with 32nd order filters is very superior when compared to 16th order and 8th order filters. 19 3.1.3 MATLAB simulation of an 8th order band pass filter The most basic and major part of the synthesizer design is to design a FIR bandpass filter, which is chosen for the verification purpose. An 8th order band pass filter with unity gain and a pass band of 20Hz – 9000Hz is designed both in MATLAB verify the functionality achieved is same in both hardware and software. The input fed to the filter is a mono audio signal. After running the simulation, the output magnitude and the frequency response are shown in Figure 13. Matlab band pass filter magnitude response 0.5 0 -0.5 0 1 2 3 4 5 6 7 5 x 10 4 Matlab band pass filter frequency response x 10 Frequency 2 1.5 1 0.5 0 2 4 6 Time 8 10 12 Figure13. Matlab simulation results of an 8th order band pass filter From the above magnitude and frequency, response of the band pass filter it is clear that a satisfactory pass band frequency is achieved from 20Hz to 9000Hz. 3.2 Filter design techniques Filter design is an important aspect in any digital signal processing design as it is evident from the current design. The basic function of a filter is to remove unwanted parts or 20 frequencies of the signal or to extract useful parts of the signal such as certain required frequency components. There are two types of filters, analog and digital. 3.2.1 Analog filters These kinds of filters are made up of passive and active components such as resistor, capacitor and op-amp to produce the required filtering. The input signals will be filtered out continuously with these kinds of filters in terms of voltage or current. They are defined over a continuous range of frequencies and are classified into several types such as low-pass, high-pass, band-pass, band-stop and all-pass filters. Analog filters can also be used for performing differentiation, integration, estimation and convolution functions [4]. 3.2.2 Digital filters 3.2.3 Advantages of Digital filters 1) Digital filters are programmable and the filter characteristics can be easily changed by changing the filter program, whereas in an analog circuit’s characteristics can be changed very easily by changing the filter circuitry. 2) Analog filter response is dependent on temperature because most of them include active and passive components such as resistors, capacitors and op-amps whose properties are subject to change with temperature. Digital filter do not depend on temperature and can produce a stable filter characteristics irrespective of the temperature. 3) Designing and testing a digital filter can be done easily when compared to an analog filter. 21 4) Digital filters are very stable and can reproduce the same response several times. 5) Low frequency signals can be handled very well with good accuracy using digital filters. 6) Hardware implementation of digital filters is also easy with the usage of fast DSP processors [7]. 3.2.4 Basic representation of a filter This project uses only digitals filters for its design so a detailed description of these kinds of filters will be provided. These filters are discrete in nature which means that the input analog signal is sampled at a certain frequency and it considers only those sampled inputs for applying the filtering mechanism. A digital filter is series of complex computations performed on a sequence of numbers x[n] representing the input, into a new desired sequence y[n] that represents the output. The following diagram shows the basic representation of a digital filter. X[n] Y[n] Figure 14. Digital filter [4] 22 The equation2 that governs the output sequence based on the input sequence is as follows. …………………………………(2) [4] In the above equation x[n] is the input sequence, y[n] is the output sequence, ai & bi are coefficients of the filters. In simple words a filtered output digital sequence y[n] is formed by performing a series of multiplications on the previous input samples and the previous output samples with the filter coefficients and summing them up properly. The transfer function equation in z domain is …………………………………(3) [4] It is clearly from the two equations that digital filters are also capable of functions such as differentiation, integration and convolution. 3.2.5 Types of Digital filters Digital filters are classified into two 1) Infinite Impulse Response(IIR) filter 2) Finite Impulse Response(FIR) filter 23 3.2.6 Infinite impulse response (IIR) filter IIR filters are designed using recursive algorithms where the output is dependent on the inputs samples and the previous values of the output. These filters can handle infinite number of input samples [4]. 3.2.7 Finite impulse response (FIR) filter FIR filters are designed using a non-recursive algorithm, which implies that the output depends only on the present and past values of the input. This can be achieved by substituting the value of bi as zeroes in equation (4) resulting in the following equation that dictates the response of a FIR filter. …………………………………(4) [4] FIR filters can handle only finite number of input samples and are currently used in the design implementation. In order to realize the FIR filter in hardware the following nonrecursive approach gives a clear picture. Figure 15. FIR filter architecture [4] 24 Notations used in the above approach are Figure 16. Adder/ Subtractor symbol [4] This signifies that the input sequences x[n] and v[n] are added or subtracted to produce the output. Figure 17. Unit Delay [4] This notation is used to show that a delayed input sample or (n-1)th sample is assigned to the output. Figure 18. Multiplier symbol [4] The above representation is generally used to represent the coefficients or the gain values that are used to multiply with the filter input samples to generate the output samples. Using all the notations described above the recursive approach of filter design can be explained as a given instance the output sequence is generated by multiplying the filter coefficients with the inputs and delayed inputs and then summed together. In order to implement the recursive FIR filter function of order N in hardware we need (N+1) 25 multipliers, N adders and (N+M) flip-flops where m is the number of bits used to represent the input signal. Multipliers and adders are the most hardware consuming components required for the filter design in hardware so a trivial approach is followed to decrease these components in the current design. The filter coefficients for an FIR filter are symmetrical in nature, and using this concept, we can implement the filter with less number of multipliers. The above equations make it easier in understanding the implementation of a digital filter in real hardware and it portrays that all we need to achieve a filter functionality is a few flip –flops (number of flip-flops required depends on the filter order and also the number of bits used in for the input) to hold the current and previous samples of the input, (N+1) multipliers and N adders where N is the order of the filter. Multipliers and adders are the most hardware consuming components required for the filter design in hardware so a trivial approach is followed to decrease these components in the current design. The filter coefficients for a linear phase FIR filter are symmetrical in nature and using this behavior the number of multipliers used can be decreased. 26 Chapter 4 HARDWARE DESIGN AND VERIFICATION OF THE SYNTHESIZER Hardware implementation of the synthesizer design is performed as part of the project. There are several verification steps and hardware design aspects that will be discussed in this chapter. Modelsim verilog simulations are performed and the results are also included. 4.1 Verilog simulation The band pass filter design implementation and test-bench simulations are done using verilog. The verilog design accepts 16-bit input data and 8-bit coefficient data that are actually scaled up by 2048 and 32 times respectively. All data are represented in 2’s complement format. The following Table 1 gives an example about audio input data representation in verilog. Floating point format audio input signal Scaled up by 2048 Quantization result 2's complement representation 0.0108 -0.016 -0.0445 -0.0707 22.1184 -32.768 -91.136 -144.794 22 -33 -92 -145 16'b0000000000010110 16'b1111111111011111 16'b1111111110100101 16'b1111111101101111 Table 1. Scaled up input samples in 2’s complement format After simulating the verilog design in Modelsim the filter output is written out into a file. Figure 19 shows the filter output which is scaled down by 65536. The spectrum simulation data is shown in Figure 20. 27 Figure 19. Band pass filter audio output data Figure 20. Spectrum results of 8th order band pass filtered audio data 4.2 Implementation of the Synthesizer Design Figure 21. Mono to stereo synthesizer hardware block diagram The block diagram as shown in Figure 21 gives top-level view of the whole mono to stereo synthesizer design flow. Audio input provided at the line input is serially available in the I2S format at the ADCDAT pin of the codec chip. The serial data is collected using 28 the ADC module and written into the SDRAM. Once the input is written into the SDRAM the data is processed, the filtering algorithm is applied, and then the resulting data is stored onto the SDRAM using the “MONO TO STEREO ALGORITHM” module. The final step in processing the data is to read the data from SDRAM and supply the data serially bit by bit to the digital to analog converter which drives the stereo output to the audio lineout pin. For the current project the audio CODEC registers are configured with the following settings 1) Line audio is selected and the DAC select mode is activated 2) The power down mode on linein, adc, dac, out, osc, clock and power signals is disabled 3) Master mode configuration is used 4) I2S data format is selected 5) ADC and DAC sampling frequency are designed at 48Khz which is 32 times slower than the bit clock(~3MHz) 6) Input data bus width is set to 16 bits Detailed information on configuring the internal registers of the Wolfson audio codec is found in the WM8731 datasheet. The SDRAM module is used to perform read/write operations. 29 4.3 Signals used in the design Signal Name iAUD_BCLK Description Input audio bit clock. It is generated by the Audio codec chip in the master mode configuration. Bit clock is 32 times faster than the sampling clock i.e. 48 kHz Reset This is an active low signal which serves as reset for the whole design except for the SDRAM module which has a separate reset. This signal is used between different modes of operation so that the address pointers get initialized correctly. iAUD_ADCLRCK This is the sampling clock generated by the codec chip to control the left and right channel data processing for the ADC iAUD_DACLRCK This is the sampling clock generated by the codec chip to control the left and right channel data processing for the DAC iAUD_DATA This signal is connected to the ADCDAT pin of the audio codec chip where the ADC output data is available serially bit by bit in the I2S format oAUD_DATA This signal is connected to the DACDAT pin of the audio codec chip where the DAC input data should be provided serially bit by bit in the I2S format write_done oSDRAM_ADDR iSDRAM_DATA iSDRAM_DATA This signal indicates the completion of writing input data into SDRAM This address is generated by the ADC module to write the data into that particular address of the SDRAM This address is generated by the DAC module to read the data from this particular address of the SDRAM This data corresponds to the SDRAM location iSDRAM_ADDR Table 2. List of signals used in the design 30 4.4 ADC module iAUD_ADCLRCK== 1'b0 iAUD _ s0 ADC L RCK == 1 'b 1 iAUD_ADCLRCK== 1'b1 reset oSDRAM_ADDR = 0 s1 iAU C AD D_ LR CK 1 == 'b0 If (cnt < 16) Collect the ADC output bits into a 16 bit temp register s2 write_done <= 1'b1; if( D oS DD _A M RA R == ff) fff 'h0 21 if(oSDRAM_ADDR < 21'h0fffff) write the 16 bit register into SDRAM address Increment the SDRAM address wait for another 48 bit clk cycles to capture the next 16 bits of ADC data s3 Figure 22. ADC module state machine This module is required to collect the data provided serially bit by bit at the ADCDAT interface pin. The data is available on the ADCDAT pin in the I2S format, which is decoded, and the 16-bit data is accumulated before storing in the SDRAM. The state machine shown in figure X describes how the ADC data collection logic can be implemented. State s0: The ADC module will be in this stage initially when the system is in reset. The SDRAM address pointer is initialized to 21’h00_0000 for writing. 31 State s1: Once a high to low transition is observed on the ADC sampling clock i.e. iAUD_ADCLRCK the state transit to the next state s2 State s2: According to the I2S data format one clock cycle is ignored before capturing 16 bits of the left channel data. Once the left channel data is captured, it is written into the SDRAM and waits for 16 clock cycles iAUD_BCK before capturing the 16 bit right channel data and writes it into to the next SDRAM address. This cycle of capturing and writing the left and right channel data continues until the 21’h0F_FFFF SDRAM address. State s3: Once the writing completes the state machine enters s3 asserting the write_done led indicator. 4.4.1 ADC module verilog simulation Figure 23. Verilog simulation results of the ADC module The above simulation shows that once a high to low transition is observed on iAUD_ADCLRCK one clock cycle is ignored and the next 16 bits are sampled and stored into a register before writing into the SDRAM as shown in the Figure 23. 32 4.5 MONO TO STEREO ALGORITHM module The main function of this module is to synchronize the outputs of all the seven band pass filters in the design to get the left and right channel outputs. This module is responsible for supplying the MATLAB coefficients and (N to (N-32)) input samples at every clock cycles to all the filters. Once the left and right channel output are calculated all the left channel data is written in even addresses between, whereas the right channel data is written into odd addresses. Address Range 00_0000h to 0F_FFFFh Audio data Input audio data Even addresses between 10_0000h to 2F_FFFFh Left Channel data Odd addresses between 10_0000h to 2F_FFFFh Right Channel data Table 3. SDRAM address ranges for different audio data 4.6 DAC module After applying the mono to stereo algorithm, the left and right channel data is stored separately in alternative addresses. In order to play the processed output this DAC module is designed which allows transferring the 16-bit data serially onto the DACDAT pin, after which the digital to analog conversion is done before playing it through the lineout. The state machine shown in Figure 24 gives an idea of the DAC module flow. 33 Read left channel and right channel data from SDRAM and store into two 16 bit registers iAUD_DACLRCK== 1'b0 iAUD _DAC s0 LRC K== 1'b1 iAUD_DACLRCK== 1'b1 reset iSDRAM_ADDR = 22'h10_0000 s1 iAU CL DA D_ RC 'b0 =1 K= s2 Readin the left and right channel data completed if DR (iS DD _A AM R == ff) fff 'h2 21 If (cnt < 16) Every clock cycle transmit one bit of the left channel data onto the DAC input pin increment cnt; elsif (cnt == 16) Increment the SDRAM address pointer and store the right channel data into the 16 bit temp register increment cnt; elsif ((cnt >16) && ( cnt <32)) Wait for 16 bit clk cycles before transmitting right channel data increment cnt; elsif((cnt >=32) && (cnt <47)) Every clock cycle transmit one bit of the left channel data onto the DAC input pin increment cnt; elsif(cnt == 48) increment the SDRAM address pointer and store the left channel data into the 16 bit temp register wait for 16 clock cycles and transmit left data increment cnt If(iSDRAM_ADDR <22'h2f_ffff) cs <= s2; else cs <= s3; s3 Figure 24. DAC module state diagram State s0: When the active low reset signal is asserted, the state machine enters into this state where the SDRAM address pointer is initialized to 10_0000h. State s1: Similar to the ADC module state diagram the logic remains in this state until a high to low transition is observed. State s2: In this state the left channel data is read from the initial even address of the SDRAM and each bit is transmitted on every clock cycle of iAUD_BCK. Once the left channel data is transmitted onto the DACDAT pin the next address data which corresponds to the right channel is captured and transmitted after 16 clock cycles following the I2S format. This loop continues until all the addresses between 10_0000h and 2F_FFFFh are read from the SDRAM. 34 4.6.1 DAC module verilog simulation Figure 25. Verilog simulation results of DAC module Figure 25 shows the simulation results of a DAC module which shows that the data read from the even address of the SDRAM is transmitted when the iAUD_DACLRCK is low which represents the transmission of left channel data according to the I2S format. Similarly, the second set of data corresponds to an odd address and it is transmitted when iAUD_DACLRCK is high representing the right channel data transmission. 35 Chapter 5 CONCLUSION AND FUTURE WORK 5.1 Conclusion Implementation of the “Mono to Stereo Synthesizer Design” was very challenging which gave me quite a lot of exposure to hardware design such as interfacing memory components, DSP components and FPGA. This project involved studying and simulating different stereo enhancement techniques, which gives me a better understanding of the stereo concepts. The main goal of the project is to convert a mono audio signal into stereo audio signal, which is achieved with satisfactory audio results. 5.2 Future work The algorithm to convert the mono to stereo synthesizer can be fine-tuned to get a better stereo effect. The filter design used in the project can be optimized further in the hardware implementation. Different stereo enhancement techniques are discussed in the project so that better stereo hardware design is possible in the future. 36 APPENDIX MONO TO STEREO SYNTHESIZER GUI IMPLEMENTATION MATLAB code function varargout = monotostereo(varargin) % MONOTOSTEREO M-file for monotostereo.fig % MONOTOSTEREO, by itself, creates a new MONOTOSTEREO or raises the existing % singleton*. % % H = MONOTOSTEREO returns the handle to a new MONOTOSTEREO or the handle to % the existing singleton*. % % MONOTOSTEREO('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in MONOTOSTEREO.M with the given input arguments. % % MONOTOSTEREO('Property','Value',...) creates a new MONOTOSTEREO or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before monotostereo_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to monotostereo_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help monotostereo % Last Modified by GUIDE v2.5 01-Nov-2009 01:42:17 % Begin initialization code - DO NOT gui_Singleton = 1; gui_State = struct('gui_Name', 'gui_Singleton', 'gui_OpeningFcn', 'gui_OutputFcn', 'gui_LayoutFcn', EDIT mfilename, ... gui_Singleton, ... @monotostereo_OpeningFcn, ... @monotostereo_OutputFcn, ... [] , ... 37 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before monotostereo is made visible. function monotostereo_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to monotostereo (see VARARGIN) % Choose default command line output for monotostereo handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes monotostereo wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = monotostereo_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; function BPF_COMMON_LC_Callback(hObject, eventdata, handles) % hObject handle to BPF_COMMON_LC (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of BPF_COMMON_LC as text 38 % str2double(get(hObject,'String')) returns contents of BPF_COMMON_LC as a double %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','20') end guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function BPF_COMMON_LC_CreateFcn(hObject, eventdata, handles) % hObject handle to BPF_COMMON_LC (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function BPF_LEFT1_LC_Callback(hObject, eventdata, handles) % hObject handle to BPF_LEFT1_LC (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of BPF_LEFT1_LC as text % str2double(get(hObject,'String')) returns contents of BPF_LEFT1_LC as a double %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','2000') end guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function BPF_LEFT1_LC_CreateFcn(hObject, eventdata, handles) % hObject handle to BPF_LEFT1_LC (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB 39 % handles called empty - handles not created until after all CreateFcns % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function BPF_LEFT2_LC_Callback(hObject, eventdata, handles) % hObject handle to BPF_LEFT2_LC (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of BPF_LEFT2_LC as text % str2double(get(hObject,'String')) returns contents of BPF_LEFT2_LC as a double %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','5000') end guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function BPF_LEFT2_LC_CreateFcn(hObject, eventdata, handles) % hObject handle to BPF_LEFT2_LC (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function BPF_LEFT3_LC_Callback(hObject, eventdata, handles) % hObject handle to BPF_LEFT3_LC (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) 40 % Hints: get(hObject,'String') returns contents of BPF_LEFT3_LC as text % str2double(get(hObject,'String')) returns contents of BPF_LEFT3_LC as a double %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','8000') end guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function BPF_LEFT3_LC_CreateFcn(hObject, eventdata, handles) % hObject handle to BPF_LEFT3_LC (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function BPF_RIGHT1_LC_Callback(hObject, eventdata, handles) % hObject handle to BPF_RIGHT1_LC (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of BPF_RIGHT1_LC as text % str2double(get(hObject,'String')) returns contents of BPF_RIGHT1_LC as a double %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','2000') end guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function BPF_RIGHT1_LC_CreateFcn(hObject, eventdata, handles) 41 % hObject % eventdata % handles called handle to BPF_RIGHT1_LC (see GCBO) reserved - to be defined in a future version of MATLAB empty - handles not created until after all CreateFcns % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function BPF_RIGHT2_LC_Callback(hObject, eventdata, handles) % hObject handle to BPF_RIGHT2_LC (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of BPF_RIGHT2_LC as text % str2double(get(hObject,'String')) returns contents of BPF_RIGHT2_LC as a double %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','7000') end guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function BPF_RIGHT2_LC_CreateFcn(hObject, eventdata, handles) % hObject handle to BPF_RIGHT2_LC (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function BPF_RIGHT3_LC_Callback(hObject, eventdata, handles) % hObject handle to BPF_RIGHT3_LC (see GCBO) 42 % eventdata % handles reserved - to be defined in a future version of MATLAB structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of BPF_RIGHT3_LC as text % str2double(get(hObject,'String')) returns contents of BPF_RIGHT3_LC as a double %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','14000') end guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function BPF_RIGHT3_LC_CreateFcn(hObject, eventdata, handles) % hObject handle to BPF_RIGHT3_LC (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function BPF_COMMON_UC_Callback(hObject, eventdata, handles) % hObject handle to BPF_COMMON_UC (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of BPF_COMMON_UC as text % str2double(get(hObject,'String')) returns contents of BPF_COMMON_UC as a double %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','3000') end 43 guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function BPF_COMMON_UC_CreateFcn(hObject, eventdata, handles) % hObject handle to BPF_COMMON_UC (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function BPF_LEFT1_UC_Callback(hObject, eventdata, handles) % hObject handle to BPF_LEFT1_UC (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of BPF_LEFT1_UC as text % str2double(get(hObject,'String')) returns contents of BPF_LEFT1_UC as a double %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','6000') end guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function BPF_LEFT1_UC_CreateFcn(hObject, eventdata, handles) % hObject handle to BPF_LEFT1_UC (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end 44 function BPF_LEFT2_UC_Callback(hObject, eventdata, handles) % hObject handle to BPF_LEFT2_UC (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of BPF_LEFT2_UC as text % str2double(get(hObject,'String')) returns contents of BPF_LEFT2_UC as a double %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','9000') end guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function BPF_LEFT2_UC_CreateFcn(hObject, eventdata, handles) % hObject handle to BPF_LEFT2_UC (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function BPF_LEFT3_UC_Callback(hObject, eventdata, handles) % hObject handle to BPF_LEFT3_UC (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of BPF_LEFT3_UC as text % str2double(get(hObject,'String')) returns contents of BPF_LEFT3_UC as a double %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','21000') 45 end guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function BPF_LEFT3_UC_CreateFcn(hObject, eventdata, handles) % hObject handle to BPF_LEFT3_UC (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function BPF_RIGHT1_UC_Callback(hObject, eventdata, handles) % hObject handle to BPF_RIGHT1_UC (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of BPF_RIGHT1_UC as text % str2double(get(hObject,'String')) returns contents of BPF_RIGHT1_UC as a double %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','8000') end guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function BPF_RIGHT1_UC_CreateFcn(hObject, eventdata, handles) % hObject handle to BPF_RIGHT1_UC (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end 46 function BPF_RIGHT2_UC_Callback(hObject, eventdata, handles) % hObject handle to BPF_RIGHT2_UC (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of BPF_RIGHT2_UC as text % str2double(get(hObject,'String')) returns contents of BPF_RIGHT2_UC as a double %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','15000') end guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function BPF_RIGHT2_UC_CreateFcn(hObject, eventdata, handles) % hObject handle to BPF_RIGHT2_UC (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function BPF_RIGHT3_UC_Callback(hObject, eventdata, handles) % hObject handle to BPF_RIGHT3_UC (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of BPF_RIGHT3_UC as text % str2double(get(hObject,'String')) returns contents of BPF_RIGHT3_UC as a double %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); 47 %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','21000') end guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function BPF_RIGHT3_UC_CreateFcn(hObject, eventdata, handles) % hObject handle to BPF_RIGHT3_UC (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function BPF_LEFT1_GAIN_Callback(hObject, eventdata, handles) % hObject handle to BPF_LEFT1_GAIN (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of BPF_LEFT1_GAIN as text % str2double(get(hObject,'String')) returns contents of BPF_LEFT1_GAIN as a double %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','1') end guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function BPF_LEFT1_GAIN_CreateFcn(hObject, eventdata, handles) % hObject handle to BPF_LEFT1_GAIN (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. 48 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function BPF_common_gain_Callback(hObject, eventdata, handles) % hObject handle to BPF_common_gain (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of BPF_common_gain as text % str2double(get(hObject,'String')) returns contents of BPF_common_gain as a double %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','1') end guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function BPF_common_gain_CreateFcn(hObject, eventdata, handles) % hObject handle to BPF_common_gain (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function BPF_RIGHT3_GAIN_Callback(hObject, eventdata, handles) % hObject handle to BPF_RIGHT3_GAIN (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of BPF_RIGHT3_GAIN as text % str2double(get(hObject,'String')) returns contents of BPF_RIGHT3_GAIN as a double 49 %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','1') end guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function BPF_RIGHT3_GAIN_CreateFcn(hObject, eventdata, handles) % hObject handle to BPF_RIGHT3_GAIN (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function BPF_RIGHT2_GAIN_Callback(hObject, eventdata, handles) % hObject handle to BPF_RIGHT2_GAIN (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of BPF_RIGHT2_GAIN as text % str2double(get(hObject,'String')) returns contents of BPF_RIGHT2_GAIN as a double %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','1') end guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function BPF_RIGHT2_GAIN_CreateFcn(hObject, eventdata, handles) % hObject handle to BPF_RIGHT2_GAIN (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB 50 % handles called empty - handles not created until after all CreateFcns % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function BPF_RIGHT1_GAIN_Callback(hObject, eventdata, handles) % hObject handle to BPF_RIGHT1_GAIN (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of BPF_RIGHT1_GAIN as text % str2double(get(hObject,'String')) returns contents of BPF_RIGHT1_GAIN as a double %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','1') end guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function BPF_RIGHT1_GAIN_CreateFcn(hObject, eventdata, handles) % hObject handle to BPF_RIGHT1_GAIN (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function BPF_LEFT3_GAIN_Callback(hObject, eventdata, handles) % hObject handle to BPF_LEFT3_GAIN (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) 51 % Hints: get(hObject,'String') returns contents of BPF_LEFT3_GAIN as text % str2double(get(hObject,'String')) returns contents of BPF_LEFT3_GAIN as a double %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','1') end guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function BPF_LEFT3_GAIN_CreateFcn(hObject, eventdata, handles) % hObject handle to BPF_LEFT3_GAIN (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function BPF_LEFT2_GAIN_Callback(hObject, eventdata, handles) % hObject handle to BPF_LEFT2_GAIN (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of BPF_LEFT2_GAIN as text % str2double(get(hObject,'String')) returns contents of BPF_LEFT2_GAIN as a double %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','1') end guidata(hObject, handles); 52 % --- Executes during object creation, after setting all properties. function BPF_LEFT2_GAIN_CreateFcn(hObject, eventdata, handles) % hObject handle to BPF_LEFT2_GAIN (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) [mono,fs] = wavread('mono.wav'); wavplay(mono,fs); figure; subplot(2,1,1),plot(mono),title('Mono audio'); subplot(2,1,2),specgram(mono,128,fs),title('Mono specgram'); % --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) guidata(hObject, handles); [mono,fs] = wavread('mono.wav'); %BAND PASS COMMON FILTER bpf_common_order = get(handles.BPF_COMMON_ORDER,'String'); bpf_common_lc = get(handles.BPF_COMMON_LC,'String'); bpf_common_uc = get(handles.BPF_COMMON_UC,'String'); bpf_common_gain = get(handles.BPF_COMMON_GAIN,'String'); fn = [(str2num(bpf_common_lc))/(fs/2) , (str2num(bpf_common_uc))/(fs/2)]; [b,a] = fir1((str2num(bpf_common_order)), fn, 'bandpass'); bpf_common = filter(b,a,mono); %BAND PASS LEFT1 FILTER bpf_left1_order = get(handles.BPF_LEFT1_ORDER,'String'); bpf_left1_lc = get(handles.BPF_LEFT1_LC,'String'); bpf_left1_uc = get(handles.BPF_LEFT1_UC,'String'); bpf_left1_gain = get(handles.BPF_LEFT1_GAIN,'String'); fn = [str2num(bpf_left1_lc)/(fs/2),str2num(bpf_left1_uc)/(fs/2)]; [b,a] = fir1(str2num(bpf_left1_order), fn, 'bandpass'); 53 bpf_left1 = filter(b,a,mono); %BAND PASS LEFT2 FILTER bpf_left2_order = get(handles.BPF_LEFT2_ORDER,'String'); bpf_left2_lc = get(handles.BPF_LEFT2_LC,'String'); bpf_left2_uc = get(handles.BPF_LEFT2_UC,'String'); bpf_left2_gain = get(handles.BPF_LEFT2_GAIN,'String'); fn = [str2num(bpf_left2_lc)/(fs/2),str2num(bpf_left2_uc)/(fs/2)]; [b,a] = fir1(str2num(bpf_left2_order), fn, 'bandpass'); bpf_left2 = filter(b,a,mono); %BAND PASS LEFT3 FILTE bpf_left3_order = get(handles.BPF_LEFT3_ORDER,'String'); bpf_left3_lc = get(handles.BPF_LEFT3_LC,'String'); bpf_left3_uc = get(handles.BPF_LEFT3_UC,'String'); bpf_left3_gain = get(handles.BPF_LEFT3_GAIN,'String'); fn = [str2num(bpf_left3_lc)/(fs/2),str2num(bpf_left3_uc)/(fs/2)]; [b,a] = fir1(str2num(bpf_left3_order), fn, 'bandpass'); bpf_left3 = filter(b,a,mono); left_channel = (str2num(bpf_common_gain) * bpf_common) + (str2num(bpf_left1_gain) * bpf_left1) + (str2num(bpf_left2_gain) * bpf_left2) + (str2num(bpf_left3_gain) * bpf_left3); wavplay(left_channel,fs); %wavwrite(lef_channel,'left_channel.wav') figure; subplot(2,1,1),plot(left_channel),title('Left Channel'); subplot(2,1,2),specgram(left_channel,128,fs),title('Left Channel specgram'); % --- Executes on button press in pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) guidata(hObject, handles); [mono,fs] = wavread('mono.wav'); %BAND PASS COMMON FILTER bpf_common_order = get(handles.BPF_COMMON_ORDER,'String'); bpf_common_lc = get(handles.BPF_COMMON_LC,'String'); bpf_common_uc = get(handles.BPF_COMMON_UC,'String'); bpf_common_gain = get(handles.BPF_COMMON_GAIN,'String'); fn = [(str2num(bpf_common_lc))/(fs/2) , (str2num(bpf_common_uc))/(fs/2)]; [b,a] = fir1((str2num(bpf_common_order)), fn, 'bandpass'); bpf_common = filter(b,a,mono); 54 %BAND PASS RIGHT1 FILTER bpf_right1_order = get(handles.BPF_RIGHT1_ORDER,'String'); bpf_right1_lc = get(handles.BPF_RIGHT1_LC,'String'); bpf_right1_uc = get(handles.BPF_RIGHT1_UC,'String'); bpf_right1_gain = get(handles.BPF_RIGHT1_GAIN,'String'); fn = [str2num(bpf_right1_lc)/(fs/2),str2num(bpf_right1_uc)/(fs/2)]; [b,a] = fir1(str2num(bpf_right1_order), fn, 'bandpass'); bpf_right1 = filter(b,a,mono); %BAND PASS RIGHT2 FILTER bpf_right2_order = get(handles.BPF_RIGHT2_ORDER,'String'); bpf_right2_lc = get(handles.BPF_RIGHT2_LC,'String'); bpf_right2_uc = get(handles.BPF_RIGHT2_UC,'String'); bpf_right2_gain = get(handles.BPF_RIGHT2_GAIN,'String'); fn = [str2num(bpf_right2_lc)/(fs/2),str2num(bpf_right2_uc)/(fs/2)]; [b,a] = fir1(str2num(bpf_right2_order), fn, 'bandpass'); bpf_right2 = filter(b,a,mono); %BAND PASS RIGHT3 FILTE bpf_right3_order = get(handles.BPF_RIGHT3_ORDER,'String'); bpf_right3_lc = get(handles.BPF_RIGHT3_LC,'String'); bpf_right3_uc = get(handles.BPF_RIGHT3_UC,'String'); bpf_right3_gain = get(handles.BPF_RIGHT3_GAIN,'String'); fn = [str2num(bpf_right3_lc)/(fs/2),str2num(bpf_right3_uc)/(fs/2)]; [b,a] = fir1(str2num(bpf_right3_order), fn, 'bandpass'); bpf_right3 = filter(b,a,mono); right_channel = (str2num(bpf_common_gain) * bpf_common) + (str2num(bpf_right1_gain) * bpf_right1) + (str2num(bpf_right2_gain) * bpf_right2) + (str2num(bpf_right3_gain) * bpf_right3); wavplay(right_channel,fs); wavwrite(right_channel,'right_channel.wav'); figure; subplot(2,1,1),plot(right_channel),title('Right Channel'); subplot(2,1,2),specgram(right_channel,128,fs),title('Right Channel specgram'); % --- Executes on button press in pushbutton4. function pushbutton4_Callback(hObject, eventdata, handles) % hObject handle to pushbutton4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) guidata(hObject, handles); [mono,fs] = wavread('mono.wav'); %BAND PASS COMMON FILTER bpf_common_order = get(handles.BPF_COMMON_ORDER,'String'); 55 bpf_common_lc = get(handles.BPF_COMMON_LC,'String'); bpf_common_uc = get(handles.BPF_COMMON_UC,'String'); bpf_common_gain = get(handles.BPF_COMMON_GAIN,'String'); fn = [(str2num(bpf_common_lc))/(fs/2) , (str2num(bpf_common_uc))/(fs/2)]; [b,a] = fir1((str2num(bpf_common_order)), fn, 'bandpass'); bpf_common = filter(b,a,mono); %BAND PASS LEFT1 FILTER bpf_left1_order = get(handles.BPF_LEFT1_ORDER,'String'); bpf_left1_lc = get(handles.BPF_LEFT1_LC,'String'); bpf_left1_uc = get(handles.BPF_LEFT1_UC,'String'); bpf_left1_gain = get(handles.BPF_LEFT1_GAIN,'String'); fn = [str2num(bpf_left1_lc)/(fs/2),str2num(bpf_left1_uc)/(fs/2)]; [b,a] = fir1(str2num(bpf_left1_order), fn, 'bandpass'); bpf_left1 = filter(b,a,mono); %BAND PASS LEFT2 FILTER bpf_left2_order = get(handles.BPF_LEFT2_ORDER,'String'); bpf_left2_lc = get(handles.BPF_LEFT2_LC,'String'); bpf_left2_uc = get(handles.BPF_LEFT2_UC,'String'); bpf_left2_gain = get(handles.BPF_LEFT2_GAIN,'String'); fn = [str2num(bpf_left2_lc)/(fs/2),str2num(bpf_left2_uc)/(fs/2)]; [b,a] = fir1(str2num(bpf_left2_order), fn, 'bandpass'); bpf_left2 = filter(b,a,mono); %BAND PASS LEFT3 FILTE bpf_left3_order = get(handles.BPF_LEFT3_ORDER,'String'); bpf_left3_lc = get(handles.BPF_LEFT3_LC,'String'); bpf_left3_uc = get(handles.BPF_LEFT3_UC,'String'); bpf_left3_gain = get(handles.BPF_LEFT3_GAIN,'String'); fn = [str2num(bpf_left3_lc)/(fs/2),str2num(bpf_left3_uc)/(fs/2)]; [b,a] = fir1(str2num(bpf_left3_order), fn, 'bandpass'); bpf_left3 = filter(b,a,mono); left_channel = (str2num(bpf_common_gain) * bpf_common) + (str2num(bpf_left1_gain) * bpf_left1) + (str2num(bpf_left2_gain) * bpf_left2) + (str2num(bpf_left3_gain) * bpf_left3); %BAND PASS COMMON FILTER bpf_common_order = get(handles.BPF_COMMON_ORDER,'String'); bpf_common_lc = get(handles.BPF_COMMON_LC,'String'); bpf_common_uc = get(handles.BPF_COMMON_UC,'String'); bpf_common_gain = get(handles.BPF_COMMON_GAIN,'String'); fn = [(str2num(bpf_common_lc))/(fs/2) , (str2num(bpf_common_uc))/(fs/2)]; [b,a] = fir1((str2num(bpf_common_order)), fn, 'bandpass'); 56 bpf_common = filter(b,a,mono); %BAND PASS RIGHT1 FILTER bpf_right1_order = get(handles.BPF_RIGHT1_ORDER,'String'); bpf_right1_lc = get(handles.BPF_RIGHT1_LC,'String'); bpf_right1_uc = get(handles.BPF_RIGHT1_UC,'String'); bpf_right1_gain = get(handles.BPF_RIGHT1_GAIN,'String'); fn = [str2num(bpf_right1_lc)/(fs/2),str2num(bpf_right1_uc)/(fs/2)]; [b,a] = fir1(str2num(bpf_right1_order), fn, 'bandpass'); bpf_right1 = filter(b,a,mono); %BAND PASS RIGHT2 FILTER bpf_right2_order = get(handles.BPF_RIGHT2_ORDER,'String'); bpf_right2_lc = get(handles.BPF_RIGHT2_LC,'String'); bpf_right2_uc = get(handles.BPF_RIGHT2_UC,'String'); bpf_right2_gain = get(handles.BPF_RIGHT2_GAIN,'String'); fn = [str2num(bpf_right2_lc)/(fs/2),str2num(bpf_right2_uc)/(fs/2)]; [b,a] = fir1(str2num(bpf_right2_order), fn, 'bandpass'); bpf_right2 = filter(b,a,mono); %BAND PASS RIGHT3 FILTE bpf_right3_order = get(handles.BPF_RIGHT3_ORDER,'String'); bpf_right3_lc = get(handles.BPF_RIGHT3_LC,'String'); bpf_right3_uc = get(handles.BPF_RIGHT3_UC,'String'); bpf_right3_gain = get(handles.BPF_RIGHT3_GAIN,'String'); fn = [str2num(bpf_right3_lc)/(fs/2),str2num(bpf_right3_uc)/(fs/2)]; [b,a] = fir1(str2num(bpf_right3_order), fn, 'bandpass'); bpf_right3 = filter(b,a,mono); right_channel = (str2num(bpf_common_gain) * bpf_common) + (str2num(bpf_right1_gain) * bpf_right1) + (str2num(bpf_right2_gain) * bpf_right2) + (str2num(bpf_right3_gain) * bpf_right3); stereo(:,1) = left_channel; stereo(:,2) = right_channel; wavplay(stereo,fs); %wavwrite(stereo,fs,'Stereo_output_with_4order_filters'); figure; subplot(3,1,1),plot(stereo),title('Stereo Audio'); subplot(3,1,2),specgram(left_channel,128,fs),title('Left Channel Stereo specgram'); subplot(3,1,3),specgram(right_channel,128,fs),title('Right Channel Stereo specgram'); function BPF_COMMON_ORDER_Callback(hObject, eventdata, handles) % hObject handle to BPF_COMMON_ORDER (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) 57 % Hints: get(hObject,'String') returns contents of BPF_COMMON_ORDER as text % str2double(get(hObject,'String')) returns contents of BPF_COMMON_ORDER as a double %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','1') end guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function BPF_COMMON_ORDER_CreateFcn(hObject, eventdata, handles) % hObject handle to BPF_COMMON_ORDER (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function BPF_LEFT1_ORDER_Callback(hObject, eventdata, handles) % hObject handle to BPF_LEFT1_ORDER (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of BPF_LEFT1_ORDER as text % str2double(get(hObject,'String')) returns contents of BPF_LEFT1_ORDER as a double %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','1') end guidata(hObject, handles); 58 % --- Executes during object creation, after setting all properties. function BPF_LEFT1_ORDER_CreateFcn(hObject, eventdata, handles) % hObject handle to BPF_LEFT1_ORDER (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function BPF_LEFT2_ORDER_Callback(hObject, eventdata, handles) % hObject handle to BPF_LEFT2_ORDER (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of BPF_LEFT2_ORDER as text % str2double(get(hObject,'String')) returns contents of BPF_LEFT2_ORDER as a double %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','1') end guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function BPF_LEFT2_ORDER_CreateFcn(hObject, eventdata, handles) % hObject handle to BPF_LEFT2_ORDER (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end 59 function BPF_LEFT3_ORDER_Callback(hObject, eventdata, handles) % hObject handle to BPF_LEFT3_ORDER (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of BPF_LEFT3_ORDER as text % str2double(get(hObject,'String')) returns contents of BPF_LEFT3_ORDER as a double %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','1') end guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function BPF_LEFT3_ORDER_CreateFcn(hObject, eventdata, handles) % hObject handle to BPF_LEFT3_ORDER (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function BPF_RIGHT1_ORDER_Callback(hObject, eventdata, handles) % hObject handle to BPF_RIGHT1_ORDER (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of BPF_RIGHT1_ORDER as text % str2double(get(hObject,'String')) returns contents of BPF_RIGHT1_ORDER as a double %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) 60 set(hObject,'String','1') end guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function BPF_RIGHT1_ORDER_CreateFcn(hObject, eventdata, handles) % hObject handle to BPF_RIGHT1_ORDER (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function BPF_RIGHT2_ORDER_Callback(hObject, eventdata, handles) % hObject handle to BPF_RIGHT2_ORDER (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of BPF_RIGHT2_ORDER as text % str2double(get(hObject,'String')) returns contents of BPF_RIGHT2_ORDER as a double %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','1') end guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function BPF_RIGHT2_ORDER_CreateFcn(hObject, eventdata, handles) % hObject handle to BPF_RIGHT2_ORDER (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); 61 end function BPF_RIGHT3_ORDER_Callback(hObject, eventdata, handles) % hObject handle to BPF_RIGHT3_ORDER (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of BPF_RIGHT3_ORDER as text % str2double(get(hObject,'String')) returns contents of BPF_RIGHT3_ORDER as a double %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','1') end guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function BPF_RIGHT3_ORDER_CreateFcn(hObject, eventdata, handles) % hObject handle to BPF_RIGHT3_ORDER (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function BPF_COMMON_GAIN_Callback(hObject, eventdata, handles) % hObject handle to BPF_COMMON_GAIN (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of BPF_COMMON_GAIN as text % str2double(get(hObject,'String')) returns contents of BPF_COMMON_GAIN as a double %is not a number then input will be empty 62 input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','1') end guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function BPF_COMMON_GAIN_CreateFcn(hObject, eventdata, handles) % hObject handle to BPF_COMMON_GAIN (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end 63 BIBLIOGRAPHY 1. Nobuyuki Iwanaga, Wataru Kobayashi, Kazuhiko Furuya, Takao Onoye and Isao Shirakawa, “Embedded Implementation of Acoustic Field Enhancement forStereo Sound Sources,” IEEE Transactions on Consumer Electronics, vol. 49, no.3, pp. 737-741, August 2003. 2. Lin Wang, Fuliang Yin, Zhe Chen, “An Out of Head sound field enhancement for the headphone system”, IEEE Int. Conference Neural Networks & Signal Processing, pp. 517-521, China, June 2008. 3. Jussi Pekonen, “Coefficient-Modulated First-Order Allpass Filter as Distortion Effect,” Proc. of the 11th Int. Conference on Digital Audio Effects (DAFx-08), Espoo, Finland, September 2008. 4. Steve Winder, “Analog and Digital Filter Design,” Newnes Inc., October 2002. 5. Patrick Marchand, O.Thomas Holland, “Graphics and GUI’s with MATLAB, Third Edition,” Taylor & Francis, Inc., November 2002. 6. "WM8731/WM8731L Portable Internet Audio CODEC with Headphone Driver and Programmable Sample Rates", Wolfson Microelectronics Production Datasheet, Rev 4.3, August 2006. 7. “Inroduction to digital filters” retrieved from world wide web http://www.dsptutor.freeuk.com/digfilt.pdf 8. “Monoaural sound” retrieved from world wide web http://en.wikipedia.org/wiki/Monoaural 64 9. “Mono to stereo synthesizer” retrieved from world wide web http://www.ece.rice.edu/~duarte/elec542/project.pdf