<< 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 is biology
Hajah Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
what is biology
Victoria Reply
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
cell is the building block of life.
Condoleezza Reply
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