Forum
Please or Register to create posts and topics.

How to generate .iq file from matlab

I'm trying to generate a .iq file from matlab and import into the file source block in the aaronia rtsa suite. I do it like the following.

% Parameters
% f = 1000000; % Frequency of the sine wave (Hz)
f = 1; % Frequency of the sine wave (Hz)
% fs = 100000000; % Sampling frequency (Hz)
fs = 100; % Sampling frequency (Hz)
T = 1; % Duration of the signal (seconds)
t = 0:1/fs:T-1/fs; % Time vector

% Generate I and Q streams
I = sin(2 * pi * f * t); % In-phase component (sine wave)
Q = cos(2 * pi * f * t); % Quadrature component (cosine wave)

% Plot the sine wave (I) and cosine wave (Q)
figure;
subplot(2, 1, 1);
plot(t, I);
title('In-phase (I) Component');
xlabel('Time (s)');
ylabel('Amplitude');

subplot(2, 1, 2);
plot(t, Q);
title('Quadrature (Q) Component');
xlabel('Time (s)');
ylabel('Amplitude');

% Generate complex IQ signal
IQ_signal = I + 1i * Q;

% Plot the complex IQ signal on a polar plot
figure;
plot(real(IQ_signal), imag(IQ_signal));
title('IQ Signal (Complex Plane)');
xlabel('In-phase (I)');
ylabel('Quadrature (Q)');

Isig=real(IQ_signal);
Qsig=imag(IQ_signal);

Isig_single =single(Isig);
Qsig_single =single(Qsig);

Iqdata = reshape([Isig;Qsig],[],1);

% Open a file for binary writing
fileID = fopen('\sine_test_float32.iq', 'wb');
% Check if the file opened successfully
if fileID == -1
error('Failed to open the file.');
end

% Write the IQ data to the file
% Here, we assume single precision (32-bit) for both I and Q components

% quack = "quack";
% fwrite(fileID, [quack], 'float32');

% fwrite(fileID, Iqdata, 'int8');
% fwrite(fileID, Iqdata, 'int16');
% fwrite(fileID, Iqdata, 'int32');
% fwrite(fileID, Iqdata, 'float64');
fwrite(fileID, IQ_signal, 'float32');
% fwrite(fileID, Iqdata, 'float32');
% fwrite(fileID, [Isig; Qsig], 'float32');
% fwrite(fileID, [Isig_single; Qsig_single], 'float32');

% Close the file
fclose(fileID);
disp('IQ data has been written to output.iq');

I am able to create a .iq file. When i import the .iq file into the file source block i'm getting "Block 'file source' in critical state. File read error. Am i creating the .iq file incorrectly? Is the format incorrect? Any help would be appreciated.

 

 

 

You may have to enable the "Format Override" option under "Import Config" and select the specific format you're using.