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

What are types of cell
Nansoh Reply
how can I get this book
Gatyin Reply
what is lump
Chineye Reply
what is cell
Maluak Reply
what is biology
Maluak
what's cornea?
Majak Reply
what are cell
Achol
Explain the following terms . (1) Abiotic factors in an ecosystem
Nomai Reply
Abiotic factors are non living components of ecosystem.These include physical and chemical elements like temperature,light,water,soil,air quality and oxygen etc
Qasim
what is biology
daniel Reply
what is diffusion
Emmanuel Reply
passive process of transport of low-molecular weight material according to its concentration gradient
AI-Robot
what is production?
Catherine
Pathogens and diseases
how did the oxygen help a human being
Achol Reply
how did the nutrition help the plants
Achol Reply
Biology is a branch of Natural science which deals/About living Organism.
Ahmedin Reply
what is phylogeny
Odigie Reply
evolutionary history and relationship of an organism or group of organisms
AI-Robot
ok
Deng
what is biology
Hajah Reply
cell is the smallest unit of the humanity biologically
Abraham
ok
Achol
what is biology
Victoria Reply
what is biology
Abraham
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