From: Jon on 9 Jun 2010 20:35 This is related to my previous post. I have 8 bit complex I/Q values (4 for I and 4 for Q) in binary format I need to read in and convert to real values and then save to wave file format. Each channel is in a separate file with the format: real, complex, real, complex. These files are very large so this process must be done in a loop. I have appeared to have succeeded except that after the first loop there is a kind of a jump in the wave file and duplicates of the carrier signals show up when looking at the fft. I can't see anything wrong with this code. My guess is that it's something in fseek(fid1, n2+4, 'bof'); the fseeks are to go back and read the complex values after I've read the real values. out = fopen(outfile,'a+'); loop = 4; fseek(fid1,0,'eof'); filesize = ftell(fid1); frewind(fid1); samples = filesize/8; wavwriteheader(samples, channels, samplerate, 16, out); loopsamples = filesize/(8*loop); n1 = 1; n2 = filesize/(8*loop); while n2 <= filesize/8 realpart1 = sqrt(2)*fread(fid1, filesize/(8*loop), 'single', 4) .* cos(alpha*period* (n1:n2)')*multiplier; realpart2 = sqrt(2)*fread(fid2, filesize/(8*loop), 'single', 4) .* cos(alpha*period*(n1:n2)')*multiplier; if n1 == 1 fseek(fid1, 4, 'bof'); fseek(fid2, 4, 'bof'); else fseek(fid1, n2+4, 'bof'); fseek(fid2, n2+4, 'bof'); end wavesample1 = realpart1 - sqrt(2)*fread(fid1, filesize/(8*loop), 'single', 4) .* sin(alpha*period*(n1:n2)')*multiplier; wavesample2 = realpart2 - sqrt(2)*fread(fid2, filesize/(8*loop), 'single', 4) .* sin(alpha*period*(n1:n2)')*multiplier; n1 = n1 + filesize/(8*loop); n2 = n2 + filesize/(8*loop); wav = horzcat(wavesample1,wavesample2); % interleave samples and scale samples wav = reshape (wav', loopsamples*channels, 1); wav = round (wav*32767); fwrite (out, wav, 'int16', 0, 'a'); clear wavesample1 wavesample2 wav; end
|
Pages: 1 Prev: Phase delay of pulse generator not working for me. Next: Reading .mat filenames into a listbox |