HELLO !! Welcome to Walt's Study Guide On Digital Signal Processing !! For the Steven W. Smith book, 1997 I'm trying to both enhance what the author did, as well as learn. The authors inclusion of the code is to match the text theory with code. Reading the code is a must for the student to understand whats going on. However, the code isn't complete as is. There's no real input data. This means the code is non-functional. As the author intended. I'm hoping to bridge the gap so that others can start with working templates to learn easier using these tools. In particular, the modules should be easier to re-organize by project-- inputting raw data - or generating it - and getting output should be a time saver. THE BOOK: The Scientist and Engineer's Guide to Digital Signal Processing Steven W. Smith California Technical Publishing Copyright 1997 available on Amazon in hard copy, or for FREE in PDF from this website: see: http://www.dspguide.com/ The code by Smith is written for ease of understanding in BASIC and also some is written in Fortran. I want to do 2 primary things: show the code to newer students in a newer much used language like C# mostly for motivation, and because C# is similar to VB, and to turn this code into usable projects for learning. There are other large already complete packages available for use in DSP should one prefer those, such as "R", or "Octave". The code is taking 3 forms: 1. C# versions of the book text. This means the code is non-working since the input data is not provided. So some variables aren't set. This allows students a line-for-line comparison to the text. 2. C# versions of working examples. These take the very basic C# code of the book text and add only whats necessary to make it functional. 3. C# version of extended examples: these may have extra print, debug, or user input statements to make the code more flexible. They may also include examples not of the book code text, but code to generate signals shown in figures, or discussed in text. Or perhaps a complement to existing book text. For example, the book may have a hi-pass filter, and I supply a C# example of a low pass filter. 4. I plan to morph the code examples into working projects. Detail level is still to be determined...but some are started. This includes simple programs connected by tee's and pipes. I'm using C# in mono on linux. The mono compiler is available for Windows. I'm using C# in order to be more "modern" and in a general sense should enable java users to port easily. I'm accepting java donations, should any arrive. Either should look a lot like plain C since no networks or gui are used. I am seriously considering doing this in C... but I personally don't want to do the work. An idea is that if someone ( perhaps you) wants to duplicate the code for learning in stock C, I would *really* like to include it ! All code is copyright Walter L. Smith, except where noted. It's all under copyright license GPLv3. ============================= PLEASE READ the latest additions and changes !! ========= Nov 19 2009 Added: table_24-1.cs table_24-1_example.draft.cs table_25-1.cs table_25-2.cs ========= Nov 13 2009 Added: table_2-3_example.cs table_2-4_example.cs re-wrote: table_2-3.cs table_2-4.cs ========= Nov 12 2009 removed: table_19-1.cs table_19-X-1.cs added: table_19-1.cs # book code recursion filter table_19-1_example_1.cs # low pass filter table_19-1_example_2.cs # hi pass filter table_19-1_Reverse_example_1.cs # low pass filter reverse direction table_19-1_Reverse_example_2.cs # hi pass filter reverse direction Create_Fig_15-1a_Noisy_Pulse.cs Create_Pulse_Noisy_array.cs ========== Nov 11 2009 Added: table_20-4_example_1.cs # working example of book text, calls table_20-5 table_20-5_example_1.cs # working example, called from 20-4 table_20-4_example_2.cs # working example with debugging and write statements table_20-5_example_2.cs # working example called from table_20-4_example_2 =========== Nov 3 2009 Added: table_20-4.cs table_20-5.cs table_31-1.cs table_31-1_example.cs =========== Oct 24 2009 The following BASH script works: dsp_port=`ps | mono Parse_unix_ps.exe`;dsp_data1=` mono Create_Pulse_Array.exe |tee $dsp_port | grep , `| echo -e "$dsp_data1\n$dsp_data2\n" |tee >/dev/pts/3 >(mono ch_6_Convolution_Project_1.exe) | tee >(mono ch_12_Project_Console.exe) I decided to use shell vars to keep the data. The bash man says they can be unlimited in size. The user only needs to do IO in the program that algorithmically creates data. Then output from the covolution filter program must be guaranteed to be power of 2 data since the ch_12_Project_Console is an FFT. =========== Oct 23 2009 Have completed a start to end script that needs more work: dsp_port=`ps | mono Parse_unix_ps.exe`; mono Create_Pulse_Array.exe | tee $dsp_port | grep , | tee >(cat sine_4_amplitude_offset_128.xls) | mono ch_6_Convolution_Project_1.exe ; sleep 2s|tee >(mono ch_12_Project_Console.exe) -- all one line above -- The "sleep 2s" shold make a few folks groan... Created 2 new directories: http://waltech.freeshell.org/DSP/Projects_Using_Pipes http://waltech.freeshell.org/DSP/Projects_Using_Options_and_Files The first will be used for project files testign that use pipes and tee. Only the first "Create Data" program may have user IO. One temp value - the port for the user - is saved as environment bash value.. The second will house files where the mono executes can have command line options: "mono myprog 12 10 c" and intermediate results will be stored in temporary files.. =========== Oct 20 2009 added: Create_Fig_6-3-LP_kernel-1.cs # simple creates the data Create_Fig_6-3-LP_kernel-2.cs # user spec'd data Create_Fig_6-3-HP_kernel-1.cs # simple creates the data Create_Fig_6-3-HP_kernel-2.cs # user spec'd data figure_6-3_low_pass_kernel.xls figure_6-3_high_pass_kernel.xls the two .xls files simply contain the data for the figure 6-3 filter. The *LP*1 file merely creates the arch data from an equation. the -2 file in both cases allows for user input. The *HP* file uses the "arch" code in the LP file, and performs a conversion to a high pass filter. file name conventions are rev'd: figures which are data charts and are made from data: the data will be in files begining with "figure_chapter-number" and will have extension .xls - for the present. changing the file extension to .cvs is under consideration. computer programs which create the data in book "figures" will be called "Create_Fig.chapter-number".. =========== Oct 17 2009 Howard added an xample to perform user input without the user interface. This might make it easier to perform reptitious tasks: Create_Pulse_Array-argstostdout.cs -- Thought Process: Here is an example as a flow diagram of a "moderately complex" system without being complete with tee's and such: Create_Data_Array ( same as Create_Pulse_Array) Create_Impulse_Response Convert_Impulse_low_to_high Filter_Signal ( use Create_Data array AND data from Convert_Impulse ) Perform_FFT ( same as ch_12_Project_Console) ( use data from Filter_Signal) graph_Data I use the filenames above from what we've done recently for reference. However, those filenames will change in that they might do some different "work". For example, I need to experiment with using data Other than the pulse... I need to also try a Hamming window for example. If you like, one interesting piece of raw starting data might be a pulse with added noise. The noise can be added to the present pulse we use. The noise should add, lets say: 1. type 1 would be evenly distributed noise +0.5 to -0.5. 2. type 2 would be Gaussian distributed noise +0.5 to -0.5 NOTE: as an aside, I found that when printing an array of 512 floats to the terminal screen, if I try to do a gui cut/paste into OO calc spreadsheet, there is no "paste". I assume the string of data is too large. However, the shell method, where the text is marked, and then the center mouse button clicked, will paste the data into the cell. Of course, after that, Data => text-to-columns then works. ============ Oct 15 2009 added Project file: ch_12_Project_Console.cs which accepts user input, produces user output and performs a complex fft. Completed proof of concept on piping together files Create_Data => Process_Data the example completed uses the files tee_Script.sh, Parse_unix_ps.cs, Create_Pulse_Array.cs, ch_12_Project_console.cs Parse_unix_ps finds the terminal the user is on to assist in the piping of data. ============ Oct 8 2009 Added: table_12-4.cs table_12-4.example.1.cs table_8-3.cs table_8-3.example.1.cs (Rect to polar) table_8-3.example.2.cs (polar to rect) Convert_Rect_To_Polar.cs Removed: table_12-4.draft.cs table_12-4.draft2.cs tabel_12-4.debug.cs table_12-4.draft.debug.cs note: table 12-4.example.1.cs has a simple true/false boolean added to print additional statements if "debug" is true. This is an example for programming technique. Convert_Rect_To_Polar is almost the same as table_8-3.example.1.cs It has a 2nd section added to how how to call it as a module. The example programs can use better raw data. ============ Oct 7 2009 Added: table_19-1.cs table_19-X-1.cs note: I'm using a new designator for boilerplate code which is not in the text, but perhaps the algorithm is mentioned. Revised: table_12-1.cs was table_12-1.draft.cs table_12-2.cs was table_12-2.draft.cs table_12-5.cs was table_12-5.draft.cs ============= Oct 5 2009 Revised to new format std : table_2-1.cs ; direct representation of book. table_2-1.example.1.cs ; a working program table_2-2.cs table_2-2.example.1.cs ; a working program Convert_Spectral_Inversion.cs Convert_Spectral_Reversal.cs removed named program : table_2-1.working.example.cs table_2-2.draft.cd table_2-2.example.cs ============== Oct 4 2009 added: Create_Gaussian_Array.cs This makes a Gaussian Array. It uses the full equation p. 27 The user can change variables.. the array size for resolution, the mean and the standard deviation ( sigma). IT outputs the Gaussian data. The X scale is fairly fixed for simplicity. Create_Gaussian_With_XScale.cs This makes a Gaussian Array using the full equation. The user can input into a variable the mean and deviation. This program also produces an array output that can be the x-axis for graphs. This scaling is automatic !! ============== Oct 1 2009 changed my homepage to link to DSP page, so see http://waltech.freeshell.org Things to do: 1. demonstrate fig. 10-11 Eq. p 198 2. Ch 12 p. 235 table 12-4 Bit reversal here looks like data is swapped rather than the index numbers. However, there is some index porcessing going on (I, J), and I haven't figured out the algorithm. 3. demonstate ch 14 p. 273 spectral reversal 4. "complex" dft is p 233: compare to table 8-2 ( real?). 5. ch 12 p. 230 interlaced composition also see for ref ch 5 p. 103 demonstrate interlaced ? 6. note: ch 12 p.230, FFT interlacing, Each sample is literally N=1 point set of samples. This means that each is a transform to a DC. It is only when diluted or shifted that something else occurs. Each sample is complex. Not a bad thing to diagram a comlex example of a butterfly. =============== Sept 26 2009 Added: table_16-1.draft.cs table_16-2.draft.cs Create_Wiener_Filter.cs also: added style rules for text table code written in C#: Basically, it's like this: ( example included below) 1. include namespace, class and main for code that is a reflection of the tables in the book. 2. Keep gosubs as in the text. 3. Use spaces, not tabs, set at 3 for most. gedit can do this. This varies for me depending on the "level" of the braces. 4. Braces: Use a brace on a separate line for for both beginning and end of the top 3 code levels: namespace, class, Main Use a start brace on the same line for actual code. Use a stop brace on a separate line. The stop Brace should be inline with the braced code start. 5. Data: start and stop brace can be on the same line if it's readable. Data can be stylized for readablty: see example. 6. Data: in parenthesis, a comma will follow with no space. A space will follow a comma. A space will be before the clsoing paren. A space will follow an opening paren. 7. This style applies to code that appears as a "main" and has no obvious "procedure" prototypes which make it appear as a module. This is still TBD, and may not be applicable. Parenthesis will be adjacent to the code. 8. Comments pertaining directly to code blocks will have no line space between the command and the code. The comment indent will line up vertically with the code block. 9. Variable names will be capitalized and be the same as the "tables". 10. Declarations will be made for all variables. 11. Comments can be extended to additional lines if the line width becomes too large. 12. Top comments will start at the left margin. 13. namespace will start at the left margin. The opening brace will start at the left margin. Opening braces for class and Main will also start in the same column as the keyword. There are exceptions to every rule. And I have no doubt this will continue revision. Style has not yet been determined for "working example" programs with Main, or callable "modules". =============== Sept 23 2009 ch 14 P 274, clarification, first paragraph: "Changing the sign....." If you recall, the frequency of 0.5 is the max freq that can be shown: exactly every other sample is + and every other sample is -. See fig 8-5g p. 151. So a multiply changes the sign of every other sample. This is a Cos. Note that fig 8-5h is the same freq, but a sin. 8-5h is not applicable to this paragraph. Ch 14 p. 274, clarification, Fig 14-8a, b A Cascade is by definition a convolution. See p. 133 Fig 7-9 ch 6 p. 113 Fig 6-6 ch 6 p. 116 This pertains to the Output Side Algorithm. 2nd paragraph, 2nd sentence: "This point is equal to..." This is the best explanation yet that I've seen of the output side algorithm, which is the most traditional method of showing a convolution. Unfortunately, the usual way where the h() is flipped by itself has not much intuitive information. Fig 6-6 should be redrawn to include the point summations. ============== Sept 21 2009 added: Normalize_Array.Draft.cs Normalize_Array_2.Draft.cs * Create_Arch_Array.cs * This is only a template. It needs the algorithm changed. The first normalizes by adding all the values, essentially integrating, and dividing by the total. The second does the more normal Normalization: it finds the biggest number and divides all elements by that value, which makes the range of values from 0 to 1. ============== Sept 20 2009 added: table_15-2.working.draft_2.cs updated: Create_Pulse_Array.cs table_15-2.working.draft.cs ============== Sept 19 2009 added: table_15-1.draft.cs table_15-2.draft.cs table_15-1.working.draft.cs table_15-2.working.draft.cs although the "Working" examples don't have real data to process from an array in the source. One thing I'm thinking about, since it's ch_15, is to read the data from a file. Or perhaps just include a very small array of input data. added: Convert_amplitude_DB_array_to_normal.cs Convert_normal_array_to_power_DB.cs Convert_normal_array_to_amplitude_DB.cs Convert_power_DB_array_to_normal.cs these are very simple programs that convert a data array to/from a vaue to either and amplitude 20*log(A) or a power 10*log(P), or vice versa: from a DB to a linear value. The loop can be extracted and used as a simple function in a "project". ============== Sept 11 2009 major rework on: table_12-4.working.draft.cs reads in 64, and outputs 64.. ============== Sept 8 2009 added: Create_Fourier_Square_Array_1.cs Create_Fourier_Sawtooth_Array_1.cs Create_Hamming_Array.cs Create_Blackman_Array.cs Create_Window-sinc_Filter_Black_Array.cs Moved a number of files named "Neural_Network...blah" to "table_26-x" filenames. =============== Sept 4 2009 added: ch_12_Project_1.draft.cs ch_12_Project_2.draft.cs table_12-4.working.draft.cs most of these are pretty crummy. I did them a while back and they require a lot of work to make "Right" for students. =============== Sept 3 2009 Tip O Day: When you run the programs from "terminal mode", or terminal screen, or whats called CLI ( command line interfae), you type comands and data, and the screen prints the responses in text. There is no "graphical interface". So, when you get a screen full of data you want to put into, say open office "calc" spreadsheet, you first "cut" the text from the screen. Then paste it into the first cell in calc. This puts ALL the data (even a 64 number floating array )into ONE cell. Then, using calc's menu, do "Data --> Text to Columns". Usually, select the comma (",") as the delimiter. Then each number of the data is placed into a separate cell left to right across the sheet. ================ Sept 1 2009 added contributed code: howies_Create_Impulse_Data.cs added : table_8-2.working_2.draft.cs Create_Sine_Offset_Array_variant3.cs Create_Sinc_Array.cs Create_Decay_Array.cs Normalize_Array.draft.cs ch6-Convert-lo-and-hi-pass-filter.draft.cs ch6-Convolution_hi_pass_filter.example1.draft.cs ch6-Convolution_low_pass_filter.example1.draft.cs ch6-Convolution_working_example_3.cs =============== August 21, 2009 Added book cs template code for ch. 8 ============== August 19, 2009 I'm Looking for ideas to demonstrate simple concepts in Ch 7. which has no code. ============== Auguest 19 2009 ch 6. Convolution In school, and in several texts I've looked at, I really haven't seen a good description of convolution for engineers. Based on my reading of the Smith book, I would redescribe convolution as a generalized filter. Using DSP, he filter ( convolution) function is determined by the digital pattern of the impulse response. The filter can be a low pass filter ( which is the most represented filter), high pass filter, bandpass, bandstop, or a custom filter which can do really special things. It also serves as a filter represented by weighted coefficients. Please read the last paragraph of the last page of ch. 6, p. 122. The Smith book is quite good at showing how one impulse on the input reacts with the impulse response to produce the output. The follow-thru show nine sets of data in fig. 6-6. on p. 113. The Output side 2 pages later shows how addign these 9 chartsts at each point results in teh total output ( total of each point, and all the points). My engineering classes went very carefully thru the convolution math and derivation. However ** I have yet to see/read of a good description of the flipped convolution porcess, meaning something related to the physical world: " The leading edge of time slides along the reponse and is added because ..." I am defintely INTERESTED in some GOOD relation of the flipped convolution to some physical/ or more descriptive verbage. ============== August 18 : discussion topics: format for C# mirror of book code: 1. cap letters ? 2. include class declaratio n? 3. how big should arrays be ? under what circumstances ? 4. how to implement working code ? 5. use Console.WriteLine for "print" stateents 6. whats should we name "namespace", and "class"? 7. Filename standards ? table_x-x.draft.y.cs for draft mirror files of book code. table_x-x.cs for final mirror file. rev's not to be noted. table_x-x.working.example.1.cs for working examples of mirror code, with the last number being a working code variant. PROJECT.cs -- no filename format has been suggestee for projects within chapters. These projects would be comprehensive in use of the text code models. 8. chapters 3, 4, 5, have no code in text. Suggestions accepted for code "projects" that demonstrate text concepts. 9. ch 5 -- suggest simple code be written to demonstrate: a: odd/even signal decomposition b: interlaced decomposition with small pre-filled array. ================== August 17: clarification: ch 2, p. 21, Table_2-3 line 230 It seems that the raw data used is not floating point, but is 8 bit byte data. the raw data itself is used as an index to the histogram array. If the data were anything but 8 bit integers, it would have to be "binned" to fit in the histogram. An implication is that the data is it's own index. see p. 25, first par. " A problem occurs in ..." and table 2-4. ============= August 16: additional editing. ============== clarification: ch2, p.16 first par. starting "This method of..." First, if the mean is much larger than the standard deviation, Eq. 2-2 involves subtracting two numbers that re very close in value." The math isn't apparent here. However, if one consideres mu (u) as the mean, and x sub-i as the data point, then if the data point is 10.01 and the mean is 10.00, the SD is 0.01. So the difference is only 0.01. Another way to say this is that the data point and mean are very close in value. ===================== Ch2, p.17 par. starting " Before ending this ... " additional: It's quite usual in electrical engineering to say SNR is (S+N)/N, signal plus noise to noise. This is the same as mean and SD. ==================== May 26, 2009 I've just started this page. There's no "index.html" file -- yet-- so you can see the files available from any web page. I still need a script to automatically check for new files in this dir, and have the index.html file with a linked list of files updated regularly. The intent is to create additional study guide information and to thie that information directly to the chapter and paragraph in Steve Smith's 199 pub "Digital Signal Processing for Scientists and Engineers. First thing I did was to take Ch 26 files and convert to C# language retaining as much of the original content as possible; i.e. no modifications were done to make them legitimate C# objects, subroutines with proper parameter passing etc. This will occur as specific full project examples are created. IF you wish to contribute thoughts, comments, technical clarifications and explanations,and code, please email: ********** waltechmail@yahoo.com ********** As first word in subject, place: " DSP: " THANKS Walt..........