As per my understanding of the question, I could see that you are facing bit errors while demodulating FSK(Frequency Shift Keying) modulated signal using fskdemod.
There are several reasons why bit errors may occur during the demodulation process, following these conditions might help achieve more accurate demodulation and reduces bit errors.
- Signal to Noise Ratio (SNR): Increasing the SNR, either by increasing the signal power or decreasing the noise power, reduces bit errors. This is because a higher SNR means the signal is less affected by noise.
- Nyquist Criterion: Ensuring that the inputs to the fskdemod function satisfy the Nyquist criterion i.e., where is the Sampling Frequency and , denote the frequency deviation and Bit rate per second respectively of the FSK transmitted signal.
Here's my sample implementation following the above conditions which might help you:
% Defining Parameters
Fs = 1e6; % Sampling frequency (Hz)
Rb = 10e3; % Bit rate (bits per second)
M = 2; % M-ary number (for binary FSK, M=2)
numBits = 1e2; % Number of bits to transmit
deviation = 8e3; % Frequency deviation (Hz)
samplesPerSymbol = Fs / Rb; % Samples per symbol
snrdB = 5; % Signal to Noise Ratio in dB
% Generate random binary data
data = randi([0 M-1], numBits, 1);
% FSK modulation
txSignal = fskmod(data, M, deviation, samplesPerSymbol, Fs);
% Add AWGN to the signal
noisySignal = awgn(txSignal, snrdB, 'measured');
% Normalize the signal
noisySignal = noisySignal / max(abs(noisySignal));
% Separate into I and Q components
I = real(noisySignal);
Q = imag(noisySignal);
IQ_samples = [I Q];
% Save IQ samples to a text file
fileID = fopen('IQ_samples.txt', 'w');
fprintf(fileID, '%f %f\n', IQ_samples');
fclose(fileID);
% Read IQ samples from the text file
IQ_samples = load('IQ_samples.txt');
% Separate the IQ samples into I and Q components
I = IQ_samples(:, 1);
Q = IQ_samples(:, 2);
% Combine I and Q components into a complex signal
rxSignal = I + 1i * Q;
% FSK demodulation
rxData = fskdemod(rxSignal, M, deviation, samplesPerSymbol, Fs);
% Calculate BER
[numErrors, ~] = biterr(data, rxData);
disp(['Number of bit errors: ', num2str(numErrors)]);
In the code provided above, I generated a random data, and Frequency Shift Keying (FSK) modulation is performed using the fskmod function. Noise is then added to the modulated signal with a predefined Signal-to-Noise Ratio (SNR). The IQ samples are saved to a text file, read back, and the I and Q components are extracted. FSK demodulation is carried out using the fskdemod function.
For further help, I suggest you go through the following resources
- https://in.mathworks.com/help/comm/ref/fskdemod.html?s_tid=doc_ta#d126e47038
- Sklar, Bernard. Digital Communications: Fundamentals and Applications. 2nd ed. Upper Saddle River, N.J: Prentice-Hall PTR, 2001.
I hope it helps!