<< Chapter < Page
  Digital signal processing - dsp     Page 6 / 21
Chapter >> Page >

The shiftOrigin method code

The shiftOrigin method is shown in its entirety in Listing 4 . Although this method is rather long, it is also completely straightforward. Therefore, itshouldn't require a further explanation. You may be able to develop a much shorter algorithm for accomplishing the same task.

Listing 4. The shiftOrigin method code.
//Method to shift the wavenumber origin and // place it at the center for a more visually// pleasing display. Must be applied // separately to the real part, the imaginary// part, and the amplitude spectrum for a // wavenumber spectrum.static double[][]shiftOrigin(double[][]data){ int numberOfRows = data.length;int numberOfCols = data[0].length;int newRows; int newCols;double[][] output =new double[numberOfRows][numberOfCols];//Must treat the data differently when the // dimension is odd than when it is even.if(numberOfRows%2 != 0){//oddnewRows = numberOfRows + (numberOfRows + 1)/2;}else{//even newRows = numberOfRows + numberOfRows/2;}//end elseif(numberOfCols%2 != 0){//odd newCols = numberOfCols +(numberOfCols + 1)/2; }else{//evennewCols = numberOfCols + numberOfCols/2; }//end else//Create a temporary working array.double[][]temp = new double[newRows][newCols];//Copy input data into the working array.for(int row = 0;row<numberOfRows;row++){ for(int col = 0;col<numberOfCols;col++){ temp[row][col] = data[row][col];}//col loop }//row loop//Do the horizontal shift firstif(numberOfCols%2 != 0){//shift for odd //Slide leftmost (numberOfCols+1)/2 columns// to the right by numberOfCols columns for(int row = 0;row<numberOfRows;row++){ for(int col = 0;col<(numberOfCols+1)/2;col++){ temp[row][col + numberOfCols] =temp[row][col]; }//col loop}//row loop //Now slide everything back to the left by// (numberOfCols+1)/2 columns for(int row = 0;row<numberOfRows;row++){ for(int col = 0;col<numberOfCols;col++){ temp[row][col] =temp[row][col+(numberOfCols + 1)/2]; }//col loop}//row loop}else{//shift for even //Slide leftmost (numberOfCols/2) columns// to the right by numberOfCols columns. for(int row = 0;row<numberOfRows;row++){ for(int col = 0;col<numberOfCols/2;col++){ temp[row][col + numberOfCols] =temp[row][col]; }//col loop}//row loop//Now slide everything back to the left by // numberOfCols/2 columnsfor(int row = 0;row<numberOfRows;row++){ for(int col = 0;col<numberOfCols;col++){ temp[row][col] =temp[row][col + numberOfCols/2]; }//col loop}//row loop }//end else//Now do the vertical shift if(numberOfRows%2 != 0){//shift for odd//Slide topmost (numberOfRows+1)/2 rows // down by numberOfRows rows.for(int col = 0;col<numberOfCols;col++){ for(int row = 0;row<(numberOfRows+1)/2;row++){ temp[row + numberOfRows][col] =temp[row][col]; }//row loop}//col loop //Now slide everything back up by// (numberOfRows+1)/2 rows. for(int col = 0;col<numberOfCols;col++){ for(int row = 0;row<numberOfRows;row++){ temp[row][col] =temp[row+(numberOfRows + 1)/2][col]; }//row loop}//col loop}else{//shift for even //Slide topmost (numberOfRows/2) rows down// by numberOfRows rows for(int col = 0;col<numberOfCols;col++){ for(int row = 0;row<numberOfRows/2;row++){ temp[row + numberOfRows][col] =temp[row][col]; }//row loop}//col loop//Now slide everything back up by // numberOfRows/2 rows.for(int col = 0;col<numberOfCols;col++){ for(int row = 0;row<numberOfRows;row++){ temp[row][col] =temp[row + numberOfRows/2][col]; }//row loop}//col loop }//end else//Shifting of the origin is complete. Copy// the rearranged data from temp to output // array.for(int row = 0;row<numberOfRows;row++){ for(int col = 0;col<numberOfCols;col++){ output[row][col] = temp[row][col];}//col loop }//row loopreturn output; }//end shiftOrigin method}//end class ImgMod30

Questions & Answers

how to study physic and understand
Ewa Reply
what is conservative force with examples
Moses
what is work
Fredrick Reply
the transfer of energy by a force that causes an object to be displaced; the product of the component of the force in the direction of the displacement and the magnitude of the displacement
AI-Robot
why is it from light to gravity
Esther Reply
difference between model and theory
Esther
Is the ship moving at a constant velocity?
Kamogelo Reply
The full note of modern physics
aluet Reply
introduction to applications of nuclear physics
aluet Reply
the explanation is not in full details
Moses Reply
I need more explanation or all about kinematics
Moses
yes
zephaniah
I need more explanation or all about nuclear physics
aluet
Show that the equal masses particles emarge from collision at right angle by making explicit used of fact that momentum is a vector quantity
Muhammad Reply
yh
Isaac
A wave is described by the function D(x,t)=(1.6cm) sin[(1.2cm^-1(x+6.8cm/st] what are:a.Amplitude b. wavelength c. wave number d. frequency e. period f. velocity of speed.
Majok Reply
what is frontier of physics
Somto Reply
A body is projected upward at an angle 45° 18minutes with the horizontal with an initial speed of 40km per second. In hoe many seconds will the body reach the ground then how far from the point of projection will it strike. At what angle will the horizontal will strike
Gufraan Reply
Suppose hydrogen and oxygen are diffusing through air. A small amount of each is released simultaneously. How much time passes before the hydrogen is 1.00 s ahead of the oxygen? Such differences in arrival times are used as an analytical tool in gas chromatography.
Ezekiel Reply
please explain
Samuel
what's the definition of physics
Mobolaji Reply
what is physics
Nangun Reply
the science concerned with describing the interactions of energy, matter, space, and time; it is especially interested in what fundamental mechanisms underlie every phenomenon
AI-Robot
what is isotopes
Nangun Reply
nuclei having the same Z and different N s
AI-Robot
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Digital signal processing - dsp. OpenStax CNX. Jan 06, 2016 Download for free at https://legacy.cnx.org/content/col11642/1.38
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Digital signal processing - dsp' conversation and receive update notifications?

Ask