package polyofdm.cc.powercontrol;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import javax.imageio.ImageIO;
import org.jfree.chart.JFreeChart;
import polyofdm.chart.ChartGenerator;
import polyofdm.chart.PdfGenerator;
import Jama.Matrix;
public class GeneratePNG {
public static void main(String[] args) throws IOException {
int allCarriers = 48;
Set<Integer> cancellationCarriers = new HashSet<Integer>();
cancellationCarriers.add(0);
cancellationCarriers.add(1);
cancellationCarriers.add(2);
cancellationCarriers.add(3);
cancellationCarriers.add(4);
cancellationCarriers.add(5);
cancellationCarriers.add(allCarriers-6);
cancellationCarriers.add(allCarriers-5);
cancellationCarriers.add(allCarriers-4);
cancellationCarriers.add(allCarriers-3);
cancellationCarriers.add(allCarriers-2);
cancellationCarriers.add(allCarriers-1);
// cancellationCarriers.add(3);
// cancellationCarriers.add(6);
// cancellationCarriers.add(9);
// cancellationCarriers.add(12);
PowerControlledCC cancellationCarrier = new PowerControlledCC(allCarriers, cancellationCarriers);
int usedSize = allCarriers-cancellationCarriers.size();
StringBuilder sb = new StringBuilder();
for (int maxDegrees = 0; maxDegrees < cancellationCarriers.size(); maxDegrees++) {
Matrix displayMatrix = new Matrix(usedSize, allCarriers);
for (int basisVector = 0; basisVector < usedSize; basisVector++) {
double[] usedData = new double[usedSize];
usedData[basisVector] = 1;
double[] allData = cancellationCarrier.getAssembledValuesMaxDegrees(usedData, maxDegrees);
for (int i = 0; i < allCarriers; i++) {
displayMatrix.set(basisVector, i, allData[i]);
}
}
System.out.println("Display Matrix");
displayMatrix.print(15, 5);
String filename = "CancellationCarrier_" + allCarriers + "used_" + cancellationCarriers.size() + "cc_" + maxDegrees + "degrees.png";
String titlePart2 = allCarriers + " carriers used, " + (cancellationCarriers.size()) + " cc, " + maxDegrees + " degrees";
writeChart(ChartGenerator.createChartFourier(displayMatrix, "Cancellation Carrier", titlePart2), new File(filename), 500, 400);
sb.append("<img src=\"img/cc/cc_in_guard_bothsides/" + filename + "\"/><br/>\n");
}
System.out.println(sb.toString());
}
private static void writeChart(JFreeChart chart, File out,
int width, int height) throws IOException {
BufferedImage img = chart.createBufferedImage(width, height);
ImageIO.write(img, "png", out);
}
}