Locating peaks and valleys on a map using java.
This is the assignment for my excerice,if someone knows the code,please give it to me.
I'm still beginner in java,and i have to submit that project by monday.
Topographical maps are easily represented with two-dimensional
arrays of integer or real valued
heights. However, the bird's eye view they provide is sometimes
difficult to appreciate after a day of
lugging a 70-pound backpack.
Consider a two-dimensional array variable storing real numbers and
representing heights of a
topographical map.
Write a program that locates peaks. We define a peak as any point that
is higher than its eight
neighbors.
Write a program that locates valleys. A valley is any series of three
points along a row or column that
are lower than their twelve neighbors. (Can you deal with longer
valleys as well?)
1. Define a two-dimensional array type for holding real numbers and
having a size of maxrow times
maxcol;
2. Declare a Boolean method that tests if a point of this map
represents a peak;
3. From the main program locate all peaks and output their positions
and heights;
The header should be like this:
peak number Row position Column position weight
and for valleys it will the same heading
valley number Row position Column position
This is the assignment for my excerice,if someone
knows the code,please give it to me.
I'm still beginner in java,and i have to submit that
project by monday.Tthis really isn't a beginners problem. Or if it's a beginners problem it's a beginners problem at a school with high standards. Above all it's clever. The problem is formulated in a way that you're unlikely to find code on the internet that exactly fits the bill and can be directly copied.
So if you stay off the booze tonight and skip church tomorrow you have a whole day on your hands. Use it well. The problem is clearly formulated and should pose no problem for a rasonably smart student -:)
Similar Messages
-
How can I get the peak and valley of a MZI signal
I am using MZI signal which is similar to sine wave with frequency of 10MHz to calibrate an interference signal. I want to get the peak and valley of the MZI signal and get the corresponding value of interference signal at the same location. The problem is that the MZI signal aquired by DAQ is not smooth, Please see attached filter.PNG, the top left is the MZI, top right is the MZI Zoomed in, you can see that there may be two values that are approximately same to each other. I used a peak detector to detect both the peak and valley and a build array to concatenate them. I am worried that the peak detector may find two peaks or two valleys in a fringe. So I used the filter function in express to bandpass the MZI signal (cutoff frequency is 8MHZ~12MHZ) to smooth the signal, the result zoomed in is the bottom graph in filter.PNG. But I found that it did not solve the problem but cause phase shift. Is there somebody can give some help?
Attachments:
filter.PNG 143 KB
peak detector.PNG 69 KBI don't know anything about MZI signals, but I do know sine waves. If this is a sine wave, it is relatively easy to measure its amplitude as long as you know the frequency. Since you say it is 10 MHz, you appear to know the frequency. You can use Fourier analysis to determine the magnitude and phase of your signal, as long is it is a steady signal that doesn't change frequency or amplitude.
Generate a sine and cosine wave using the same frequency. Divide each wave by the sum of its points. Multiply each one by your incoming signal and sum all the values, one sum for sine and one sum for cosine. The sums should be the coefficients of the sine and cosine components of your unknown signal. The ratio tells you the phase of the signal. If you multiply the sine and cosine waves by their coefficients and add them together, you should be very close to your incoming signal. The amplitude of your signal is equal to square root of A*A+B*B, where A and B are your coefficients.
I may be off by a constant factor here somewhere (probably pi), since I didn't write down the equations and verify them. These equations are the basis of the Fourier series, though, so they would be fairly easy to find.
Another option would be resampling. If you upsampled the data and increased the data resolution by a factor of 10 or so and filtered the results using an FIR filter, you would have a much cleaner signal with a lot more detail. You wouldn't have any problem locating and measuring peaks and valleys. This would probably work better with your data, since it looks like it doesn't have a constant magnitude. To upsample the data, just add 9 zeroes between each data point. Create a lowpass FIR filter that is based on 10 times the original sampling frequency and has an amplitude of 10. The cutoff frequency should be half the original sampling rate. Filter your new data and you should get the same waveform with 10 times the resolution.
Bruce
Message Edited by Bruce Ammons on 10-02-2008 09:10 PM
Bruce Ammons
Ammons Engineering -
Peaks and valleys detection of a zig-zag shape waveform
Hi,
I have 2 waveforms coming in and I would like to detect the peaks and valleys(with the location, or ) and write them to a spreadsheet file.
In a pattern like this
peak #1(waveform 1) peak #1(waveform 2) Location of peak#1(waveform 1) Location of peak #1(waveform 2)
valley #1(waveform 1) valley #1(waveform 2) Location of valley#1(waveform 1) Locationo of valley#1(waveform 2)
peak #2(waveform 1) peak #2(waveform 2) Location of peak#2(waveform 1) Location of peak #2(waveform 2)
valley #2(waveform 1) valley#2(waveform 2) Location of valley#2(waveform 1) Location of valley #2(waveform 2)
The waveforms come in with varing heights, kind of like a wiggling zig zag shape. Sometimes the peaks/valleys are very smooth and kind of hard to differentiate from the others.
Thanks.If you search the forums for peak detect, you will find a number of hits. Also, here is a recent thread discussin peak detection without setting a pulse width.
Basically, you want to use the peak detection.vi located in Signal Processing > Signal Operation. That will find your peaks and valleys.
In order to put all of this into Excel/Spreadsheet (do you have / want to use the Excel Toolkit or just the Write to Spreadsheet.vi?), you will need to feed all of your points into a build array and a shift register and then when you are done aquiring data, feed that into the Write to spreadsheet.vi or to a vi for excel.
The formating will depend on how you feed the data into your array, ie wave 1, location 1 or wave 1 , wave 2, etc
Kenny
Kenny -
How to create and edit a .ini file using java
Hi All...
Pls help me in creating and editing an .ini file using java...
thanks in advance
Regards,
sathyaLet's assume the ini file is a mapping type storage (key=value) so lets use Properties object. (works with java 1.4 & up)
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
public class Test {
private static Properties props;
public static void main(String[] args) throws IOException {
File file = new File("test.ini");//This is out ini file
props = new Properties();//Create the properties object
read(file);//Read the ini file
//Once we've populated the Properties object. set/add a property using the setProperty() method.
props.setProperty("testing", "value");
write(file);//Write to ini file
public static void read(File file) throws IOException {
FileInputStream fis = new FileInputStream(file);//Create a FileInputStream
props.load(fis);//load the ini to the Properties file
fis.close();//close
public static void write(File file) throws IOException {
FileOutputStream fos = new FileOutputStream(file);//Create a FileOutputStream
props.store(fos, "");//write the Properties object values to our ini file
fos.close();//close
} -
I've got a big trouble. First, I'm trying to do mapping using Java Coding based on the TopLink Developer's Guide.
I'm using a Employee's Table as usual, but here is the problem, I can not do inserting on the database after I do mapping. As a note, there is no error compile and also I can do the session login already.
Employee.java
public class Employee extends oracle.toplink.sessions.Project{
private Long id;
private String fnama;
private String lnama;
public Employee() {
setName("ObjectTab");
applyLogin();
addDescriptor(empDesc());
conformAllDescriptors();
public String getFnama() {
return this.fnama;
public String getLnama() {
return this.lnama;
public void setFnama(String fnama) {
this.fnama = fnama;
public void setLnama(String lnama) {
this.lnama = lnama;
public void applyLogin() {
DatabaseLogin login = new DatabaseLogin();
// use platform appropriate for underlying database
login.usePlatform(
new oracle.toplink.platform.database.oracle.Oracle9Platform());
login.setDriverClassName("oracle.jdbc.OracleDriver");
login.setConnectionString("jdbc:oracle:thin:localhost:1521:pusat");
login.setUserName("tryo");
login.setEncryptedPassword("a, ENCRYPTED");
// Configuration Properties
setDatasourceLogin(login);
public ClassDescriptor empDesc() {
ObjectRelationalDescriptor descriptor = new ObjectRelationalDescriptor();
descriptor.setJavaClass(Employee.class);
descriptor.setTableName("EMPLOYEES");
descriptor.setStructureName("EMPLOYEE_T");
descriptor.setPrimaryKeyFieldName("ID");
descriptor.addFieldOrdering("ID");
descriptor.addFieldOrdering("F_NAME");
descriptor.addFieldOrdering("L_NAME");
descriptor.addDirectMapping("id", "OBJECT_ID");
descriptor.addDirectMapping("fnama", "F_NAME");
descriptor.addDirectMapping("lnama", "L_NAME");
return descriptor;
Main Class:
protected String getSessionsXmlPath() {
return "sessions.xml";
protected String getSessionName() {
return "Session";
protected void createSession() {
XMLSessionConfigLoader loader = new XMLSessionConfigLoader(getSessionsXmlPath());
SessionManager mgr = SessionManager.getManager();
session = (DatabaseSession)mgr.getSession(loader, getSessionName(), Thread.currentThread().getContextClassLoader(), true, true);
public static void closeSession(){
SessionManager.getManager().destroyAllSessions();
session = null;
private void jButton1_actionPerformed(ActionEvent e) {
Employee myEmp = new Employee();
createSession();
private void jButton2_actionPerformed(ActionEvent e) {
Employee theEmp = new Employee();
UnitOfWork uow = session.acquireUnitOfWork();
try{
theEmp.setFnama("A");
theEmp.setLnama("B");
uow.commit();
}finally{
uow.release();
For everybody who already knows the solution, please reply as soon as possible. Because I really need this solution to finish my last final project.
ThanksWhen you create a new instance you must register it with the UnitOfWork in order to have the new entity persisted.
Employee theEmp = new Employee();
UnitOfWork uow = session.acquireUnitOfWork();
theEmp.setFnama("A");
theEmp.setLnama("B");
uow.registerObject(theEmp);
uow.commit();
Doug -
How to read the data from Excel file and Store in XML file using java
Hi All,
I got a problem with Excel file.
My problem is how to read the data from Excel file and Store in XML file using java excel api.
For getting the data from Excel file what are all the steps i need to follow to get the correct result.
Any body can send me the code (with java code ,Excel sheet) to this mail id : [email protected]
Thanks & Regards,
Sreenu,
[email protected],
india,If you want someone to do your work, please have the courtesy to provide payment.
http://www.rentacoder.com -
Without BPM:Call RFC using JCO in interface mapping using java mapping
Hi all
I have a very small scenario where REQUEST from the customer comes via Web Service all i have to do is to read the request using SOAP adapter and call an interface mapping(lets say the name is IM_TEST) inside which there is a JAVA MAPPING program written which will call an RFC in CRM using JCO.
Now this was really simple and i cud test the Interface mapping successfully, but the problem is when loading the scenario in integration directory i have certain things to do
1. to set the SENDER AGREEMENT which i did correctly
2. set the RECEIVER DETERMINATION, INTERFACE DETERMINATION AND RECEIVER AGREEMENT now here i am stuck because there is no receiver in my case as the RFC is called inside the mapping only.
can i call one more message mapping in IM_TEST which will write file onto the XI directory and then in RECEIVER DETERMINATION, INTERFACE DETERMINATION AND RECEIVER AGREEMENT i can mention the reciever as FTP.
I tried it but i gives the following error
Runtime exception occurred during execution of application mapping program com/sap/xi/tf/_MM_TEST_WRITE_FILE: com.sap.aii.utilxi.misc.api.BaseRuntimeException; Parsing an empty source. Root element expected!
Please help me how to complete the scenario so that customer can run it end to end.
<REMOVED BY MODERATOR>
Edited by: Prateek Raj Srivastava on May 12, 2010 1:44 PMStefen
What do i do then...actually this is the project requirement. They want a very fast response from PI and thats why they wnt us to omit BPM and the Graphical mapping from the scenario.
I am able to test the interface mapping which calls the the Java mapping inside which there is an RFC call, but i cannot implement it end - to - end as there is no receiver business system in this case. The only business system i have is the SOAP sender.
I am really troubled now, please help me with a solution.
Is there any other possible way through which the process can become very fast whic hcan meet their requirement.
Regards
Naina -
How to ZIP the files and folders/sub folder files using java
HI All,
I'm New to this Forum, Could anybody tell me how to zip the files and folders/sub folders using java. For example I have a folder with the name testfolder and side that folder I have some files and some sub folders inside subfolders I have some other files. I need to ZIP the files and folders as they are in same hierarchy.
Any pointers or help wolud be appritiated.
Thanks,
Rajeshbabu V[http://www.devx.com/tips/Tip/14049]
-
How to create database connection and how to call it using Java
Hi,
Good day! I'd like to know how I can create a db connection in JDev, then use this connection to retrieve data using a Java Class? I've seen using New Gallery > Database Connection. But I'm not sure how I can access this connection using Java and display some output from the retrieved records.
Any steps/tutorial link is appreciated.
Thanks in advance,
RianHi,
If you need to access the connection in the entity object then refer http://download.oracle.com/docs/cd/E15523_01/web.1111/b31974/bcadvgen.htm#BABEIFAI i.e in MODEL.
But if you want to access connection in ViewController part of application then you need to do it manually.For this i am giving you my code for reference.------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.faces.context.FacesContext;
import oracle.jdbc.pool.OracleDataSource;
public class DataHandler {
String jdbcUrl = null;
String userid = null;
String password = null;
Connection conn;
public static final String CONNECTION_STRING =
FacesContext.getCurrentInstance().getExternalContext().getInitParameter("connectionString");
public static final String USER_NAME =
FacesContext.getCurrentInstance().getExternalContext().getInitParameter("userName");
public static final String PASSWORD =
FacesContext.getCurrentInstance().getExternalContext().getInitParameter("password");
public DataHandler(String jdbcUrl, String userid, String password,
boolean shouldConnect) throws SQLException {
this.jdbcUrl = jdbcUrl;
this.userid = userid;
this.password = password;
if (shouldConnect) {
connect();
public void connect() throws SQLException {
OracleDataSource ds;
ds = new OracleDataSource();
ds.setURL(jdbcUrl);
conn = ds.getConnection(userid, password);
public Connection getConnection() {
return conn;
public ResultSet executeQuery(String sql) throws SQLException {
Statement s = conn.createStatement();
return s.executeQuery(sql);
public void closeConnection() throws SQLException {
if (!conn.isClosed()) {
conn.close();
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -
Counting Peaks and Valleys of a sine cycle with noise
I am having a problem with the peak detection VI. I have attached a typical signal that I am getting: an offset of 4 V and an amplitude of 1 V. I have put these values into the simulated sine with noise VI, as you can see. What I want this peak detector to do is give me an array of all the valleys in order, i.e. 2,97 2,90 3,00 2,90 2,88. What numbers should I give to the threshold and width in order to get an array with these values in that order. Also what numbers should I enter to show all the peaks in order i.e 5,25 4,90 5,10 5,09 4,94. Thanks.
Attachments:
Front_Panel_Screenshot.gif 19 KB
Block_Diagram_Screenshot.gif 10 KBYou could run your data array into a for loop. Take 'x' datapoints from the beginning of the array. Then use the array max/min function for the section of the array. On the next run in the for loop, take the next section of the data array and use the array max/min function.
-
How to compare and edit Resource bundle file using java programe
Hi All
I have two resource bundle with key, value and some comments. I need to write a java code to compare both of the values of the keys and if the values are different then i want to replace the second value with the first value.
Its a programe which will udpate the second file with the first file values.
I tried using Properties class but it didnt worked because when i am saving the file using store method it removes all the comments and the order of text also got disturbed.
How I need to do this any help appriciated.
Please elt me know if someone needs more info.
Thanks in advance.Let's assume the ini file is a mapping type storage (key=value) so lets use Properties object. (works with java 1.4 & up)
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
public class Test {
private static Properties props;
public static void main(String[] args) throws IOException {
File file = new File("test.ini");//This is out ini file
props = new Properties();//Create the properties object
read(file);//Read the ini file
//Once we've populated the Properties object. set/add a property using the setProperty() method.
props.setProperty("testing", "value");
write(file);//Write to ini file
public static void read(File file) throws IOException {
FileInputStream fis = new FileInputStream(file);//Create a FileInputStream
props.load(fis);//load the ini to the Properties file
fis.close();//close
public static void write(File file) throws IOException {
FileOutputStream fos = new FileOutputStream(file);//Create a FileOutputStream
props.store(fos, "");//write the Properties object values to our ini file
fos.close();//close
} -
Multi Mapping using JAVA Mapping 1:n Transformation--Urgent??
Hi,
I have to make a 1:n Mapping with the JAVA Mapping. The situation is as follows:
I have 1 ORDER with n positions and I have to convert this order to n ORDERS with 1 position in each order. My problem is, that I have to use the header-data of the input-order for each of the output orders and I have to use the first position of the input-order for the frist output-order the second postition for the second order and so on. Which mapping-steps do I have to use. I think this is an ordnary problem, but I could not find anything in the XI-help about this. Maybe anyon has got an idea.
Regards,
Rajhi
The output from java mapping must look like
<Messages>
<Message1>
<Your Traget Order>....
</Message1>
<Your Traget Order>....
</Message1>
</Messages>
Create a Graphical mapping sample (1:N) to get an idea about this structure.
refer this also
/people/jin.shin/blog/2006/02/07/multi-mapping-without-bpm--yes-it146s-possible
rgds,
Arun -
Deletion and creation of Configuration Objects using JAVA Transports
Hi Guys
I hope you guys can help me make some sense out this situation.
We have 2 systems in the QA Landscape which shares the Integration Server, Lets call it SYS.A1 and SYS.A2. In the SLD both SYS.A1 and SYS.A2 have the transport track pointing to SYS.PROD as the Production Environment. In QA env. we have 2 receiver determination for these 2 systems. This means in the PROD Environment we will have One object(Receiver Determination) which represents connections from these 2 systems in the QA Environment. (In prod we have one system which represents both the system in QA).
Recently there was a transport that came in from the QA env to PROD which contained a deletion of the receiver determination for SYS.A1 and modification of receiver determination for SYS.A2. So by the end of the transport we expected to see a modified receiver determination for the PROD environment, but what we found was the object that was there in PROD was deleted and nothing was modified.
So Can you please tell me what the transport sequence is? is there a priority given to deletion over creation? Or is there some kind of versioning applied for Directory Object transport?
I read from the forum that there is some sort of versioning applied on repository transport.. is it the same case here??? Any help in explaining this would be much appreciated.
Thanks & Regards
PravI have to remove the monthly spread sheet every time
and create a new spread sheet while executing the
code. The problem is when I run the code the records
inserted into same spread sheet along with the
previous records. So I need to delete the excel file
and create new one. I am using POI to create the
spread sheet. ICan anyone help me on this? I am
posting the code below.I don't think I want to read all that code. If you want to replace the data, you can remove the sheet and create a new one with the same name. HSSFWorkBook has methods removeSheetAt() and createSheet(). -
Java and XML :: Unlocking, editing and locking an XML file using JAVA
I need to develop a form with Address field , When i enter address information and submit the form it needs to generate an
XML file for furthur processing.
Now my problem is :
When i want to edit the address....after submitting the form by entering the address information, it should unlock
the XML and edit the XML and then lock it.
How can i achive programatically, unlocking an XML file, editing the file, and locking it?.
Thanks,
Maruthi.There's a FileLock class, you know, in the java.nio.channels package. However before you start using it you should read its API documentation carefully including statements like " Whether or not a lock actually prevents another program from accessing the content of the locked region is system-dependent and therefore unspecified".
Personally I would say that if you need to synchronize access to this XML file, you should consider changing your design to use something that supports locking a bit better, like a database. Or by writing a server that encapsulates the XML file and accepts requests to read it and update it, serializing those requests appropriately. -
Currently running process name list and local port list display using java
HI
I have for truble to display Process name list and that process running local port number...
like this output from java
process localport
======= ========
ccApp 1096
orbd 1050
postmaster 5432
skype 443
MSTask 1051
can help any one with sample code Explain sample code wtih , this thread or . if you found sample code please send me [email protected]
Best Regards
P.SASIKUMARIf it's possible for C++ ,. can you give me the best sample and how to interact to java todisplay this result....
Maybe you are looking for
-
HELP! Please. Spry Menu will not allow page to display once on server
Spry menu works fine "live" and in browser (firefox) but once uploaded, causes the entire page (index.html) not to appear. Can't find any help on the topic and extremely fustrated with this now. Here is my code. I hope this helps!? <!DOCTYPE html PUB
-
Ram not showing up as full ammount.
Hi, I have the late 2004 ibook (30gb, 1.2ghz) with 1.25 GB ram. However now when I look at the info, only 768MB show up? I have taken out & re-inserted the Ram as well. Also I have been having power issues. I have reset the PMU, however it seems to n
-
I have an HP 2640 Officejet printer. The printer is not worked proprerly well since I purchased it.I am having a problem.i am not able to print any single page in normal quality in colour and black &white also.when i am trying to print in norma qu
-
Whenever I add a one to one Apple class from my one to one site and click the ical icon, I get the following error message. I also get it when I click on the ical icon from the Apple email confirming my appointment to add to my calendar on my Mac Boo
-
How do I transfer notes from my iphone 3 to my iphone 4?
How do I transfer notes, pictures and music from my iphone 3 to my iphone 4?